Author Message

Look at the MOD function in the help file. It is the missing element of your
program.

Joseph Scally

<snip>

Sat, 11 Nov 2000 03:00:00 GMT

Here's the math bit,
tshirt = int((7.75*.9)+1)-.01

or more generically,

OldPrice=7.75
PriceReduce=10   '%

TShirtPrice = NewPrice(7.75,10)

Function NewPrice(OldPrice As Double, PriceReduce As Double) As Double
NewPrice=Int((OldPrice*(1-PriceReduce/100))+1)-.01
End Function

Quote:

I've
>come to so far. It's a programing project in a Visual Basic book I'm
>studying. The purpose of the project is to take the old price and reduce by
>10 percent, rounding up to the nearest dollar, and subtracting 1 cent.

>I figured, what I'd do is take the items and the prices and put them in a
>text file. That way, when the user input the item he was checking, it would
>go through the list and take the item and do the price conversion.

>Here's the program as I have it. I'm also including the form, the code, the
>pricelist, etc. So far it's doing fairly well, it's just getting the math
>part to work right.

>Private Sub cmdLookUp_Click()
>    Dim item As String, price As String, newPrice As String
>    Open "c:\pricelist.txt" For Input As #1
>    Do While (item <> txtItem.Text) And (Not EOF(1))
>        Input #1, item, price
>    Loop
>    Close #1
>    picOriginal.Cls
>    picSale.Cls
>    If item = txtItem.Text Then
>        picOriginal.Print item, price
>        picSale.Print item
>    End If
>        newPrice = price * 0.9
>    If Int(newPrice) = newPrice Then
>        newPrice = newPrice - 0.01
>    Else
>        newPrice = newPrice + 1 - 0.01
>    End If
>    picSale.Print newPrice
>End Sub

Sat, 11 Nov 2000 03:00:00 GMT

I want to thank all of you for your assistance. Here's what the book had for
being a correct answer. I thought I'd post it for everyone else to see. It
sure isnt what I expected, but I thought since y'all tried to help me out
the least I could do is post this so everyone could see what the book was
looking for. :)

Here is a sample "logic" of the code:

Do While (Not EOF(1))
Dim sale As Single, sPrice As Single, nPrice As Integer
Input #1, saleItem, price
Let sale = Val(price - (price * 0.1))
Let nPrice = Int(sale + 1)
Let nPrice = Format(nPrice, "Standard")
Let sale = Val(nPrice - 0.01)
Let sPrice = sale
If sPrice <= price Then
sPrice = sale
Else
sPrice = price
End If

' display code goes here
Loop

Sat, 11 Nov 2000 03:00:00 GMT

Joseph,

While I can't see the original question, you should be aware of a problem
with Mod - it doesn't handle big numbers (say 12345678901234567890). I'm
guessing it doesn't handle anything that cannot be stored as a long.

I use the following code instead (to handle all numbers, including Decimal
data-type):

'varData = varData Mod intDummy     won't always work
varData = varData - (Fix(varData / varDummy) *
(varDummy))     seems to

Note that varDummy must be Decimal data-type (using CDec).

Matthew

PS. If there is a bug in my code please tell me

Quote:
> Look at the MOD function in the help file. It is the missing element of
your
> program.

> Joseph Scally

> <snip>

Sun, 12 Nov 2000 03:00:00 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages