Results 1 to 7 of 7

Thread: Help, Please... VB Question..

  1. #1

    Question Help, Please... VB Question..

    Hey.. I'm stuck.. I'm a little rusty with my VB.. And I have a review program.. I need to do some Mod-type function..

    I have two numbers let's say.. 6.43 and 6.57... When I divide by 1 (using "\" instead of "/").. I get 6 for the first and 7 for the second.. I need to get 6 for both of them because I am using it's remainder to divide again.. It's a change dispensing loop by the way.... First 1's, then .25's, then .10's etc.. How do I get the Mod function to round down?

  2. #2
    The Iceman Cometh
    Join Date
    Aug 2001
    I'm not too familiar with VB, but I have written similar programs before in various languages. My recommendation would to be pull the whole number off (that's how many 1's you'd get), and then work on the decimal from there. The problem has to do with rounding the floating-point to an integer (the second gets rounded up to 7 because it's greater than 6.4999...). Just my opinion.


  3. #3
    Senior Member
    Join Date
    Oct 2001
    This is the kludgiest, quickest fix I could think of:

    if (number \ 1) > number then number = (number \ 1) - 1
    else number = number \ 1
    Hope this helps .
    OpenBSD - The proactively secure operating system.

  4. #4
    AO French Antique News Whore
    Join Date
    Aug 2001
    Pretty Simple!

    int(6.43) = 6
    int(6.57) = 6

    The Fonction INT(Number) will give you everything before the points. All the decimal are trash out!

    Hope it help.
    -Simon \"SDK\"

  5. #5
    Unfortunately, no.. That did not help.. I need to write a program.. Which Counts out the change that I would give out to a customer after a purchase.. IN this format: # of Singles, # of Quarters, # of Dimes, etc.. This is what I have so far.. If you copy this into VB and run it.. You'll see my problem.. IE: YOu wouldn't give out 4 dollars if the change is only 3.74.. You would give out 3 and then 2 quarters, 2 dimes, 0 nickels and 4 pennies.. See my dilema now? Someone please help..

    Private Sub cmdExe_Click()
    Dim Cash As Single, Cost As Single, Change As Single
    Dim Error As String
    Dim S As Integer, Q As Integer, D As Integer, N As Integer, P As Integer
    Open "c:/my documents/money.txt" For Input As #1
    picOut.FontBold = True
    picOut.FontUnderline = True
    picOut.Print "CASH"; Spc(5); "COST"; Spc(5); "CHANGE"; Spc(5); "DOLLARS"; Spc(5); "QUARTERS"; Spc(5); "DIMES"; Spc(5); "NICKELS"; Spc(5); "PENNIES"
    picOut.FontBold = False
    picOut.FontUnderline = False
    Do While Not EOF(1)
    Input #1, Cash, Cost
    If (Cash < Cost) Then
    Error = "------------------------- You Do Not Have Enough Money to Make the Purchase -------------------------"
    picOut.Print Tab(3); FormatCurrency(Cash); Tab(16); FormatCurrency(Cost); Tab(33); Error
    Change = Cash - Cost
    S = (Change \ 1)
    Q = (Change / 0.25) - S * 4
    D = (Change / 0.1) - Q * 2.5
    N = (Change / 0.05) - D * 2
    P = (Change / 0.01) - N * 5

    picOut.Print Tab(3); FormatCurrency(Cash); Tab(16); FormatCurrency(Cost); Tab(33); FormatCurrency(Change, 2); Tab(54); S; Tab(74); Q; Tab(89); D; Tab(106); N; Tab(123); P

    End If
    Close #1

    End Sub

    Thanks again

  6. #6
    AO French Antique News Whore
    Join Date
    Aug 2001
    Oh! Check that..

    Dim sngMoney as Single

    sngMoney = 100 * txtMoney.text "TxtMoney.text is the variable where 3.74 should come from
    "I multiple by 100 to make it a Integer Number to Work with!
    lblA.Caption = sngMoney \ 500 "Will give the number of 5$ to give
    lblB.Caption = (sngMoney Mod 500) \ 200 "Will give the number of 2$ to give. Hey! I'm in Canada
    lblC.Caption = (sngMoney Mod 500 Mod 200) \ 100 "Will give the number of 1$ to give
    lblD.Caption = (sngMoney Mod 100) \ 25 "Will give the number of 0.25$ to give
    lblE.Caption = (sngMoney Mod 25) \ 10 "Will give the number of 0.10$ to give
    lblF.Caption = (sngMoney Mod 25 Mod 10) \ 5 "Will give the number of 0.05$ to give
    lblG.Caption = (sngMoney Mod 5) "Will give the number of 0.01$ to give

    I don't realy remember what Mod do! I program that 3 years ago and I don
    t remember math class.

    I also attach a projet. It's in french but it's give you a idea that is work.

    Hope it help.
    -Simon \"SDK\"

  7. #7


    Thank you so much! I can't believe it was that simple.. Maybe I was just thinking that I had to do more.. Once again.. That helped so much, thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts