Solved

How to determine number of coins ?

Posted on 2000-04-02
4
183 Views
Last Modified: 2010-05-02
If I input $1.50 in a textbox, I would like to analyze the input, so
it can be determined like, $1, 2 for 25cents,   or 4 for 25cents, 5 for 10cents.

How to analyze this problem in vb ?
0
Comment
Question by:tanc02
  • 2
4 Comments
 

Expert Comment

by:Slightly_Imperfect
ID: 2678202
Private Sub Command1_Click()
Dim price_enetered As String
'declared variables
Dim first_value As Integer
Dim second_value As Integer
Dim one_var As String
Dim remainder As Integer

'flagged
Dim flag_set As Integer

For wtab = 1 To Len(Text1.Text)
    Let one_var = Mid(Text1.Text, wtab, 1)
    If one_var = "." Then
      first_value = Mid(Text1.Text, 1, wtab - 1)
      second_value = Mid(Text1.Text, wtab + 1, Len(Text1.Text))
    End If
Next wtab
'divide the first value to see what it will divide into
'there are three 4 notes in my currency
'£5 £10 £20 £50
'The first value
'i have only done this as a value of £10
'you can work the rest out from this
If first_value < 2 Then
     List1.AddItem first_value & " Pound Coin"
Else
   If first_value < 5 Then
      List1.AddItem first_value & " Pound Coins"
   
   
   Else
      If first_value < 10 Then
        remainder = first_value - 5
        If remainder < 2 Then
         List1.AddItem "5 pound note " & remainder & " Pound Coin"
        Else
         List1.AddItem "5 pound note " & remainder & " Pound Coins"
        End If
      End If
   End If
End If
'i have only done the first instance
If second_value > 5 Then
   Let remainder = second_value - 5
   If remainder < 2 Then
      List1.AddItem "5 pence piece and " & remainder & " pence piece"
   Else
      List1.AddItem "5 pence and " & remainder & " penny pieces"
   End If
End If
Let price_entered = Text1.Text



End Sub

i hope this gives you what you need !!! i have only coded the first instances but at least it will give you an idea where to start from :^)

get in touch if you need any help

0
 
LVL 1

Author Comment

by:tanc02
ID: 2680511
Slightly_Imperfect  :

How to change your program, so it will fit USA coins, like $1, 50, 25, 10 and 5 cents ?
0
 

Expert Comment

by:Slightly_Imperfect
ID: 2683531
Here is the answer you were looking for !!!!

i hope i have got the currency right !!!
:^)

Private Sub Command1_Click()

Dim price_enetered As String
'declared variables
Dim first_value As Integer
Dim second_value As Integer
Dim one_var As String
Dim remainder As Integer
Dim last_value As Integer
'flagged
Dim flag_set As Integer

For wtab = 1 To Len(Text1.Text)
    Let one_var = Mid(Text1.Text, wtab, 1)
    If one_var = "." Then
      first_value = Mid(Text1.Text, 1, wtab - 1)
      second_value = Mid(Text1.Text, wtab + 1, Len(Text1.Text))
    End If
Next wtab
'divide the first value to see what it will divide into
'there are three 4 notes in my currency
'£5 £10 £20 £50
'The first value
'i have only done this as a value of £10
'you can work the rest out from this
If first_value < 2 Then
     List1.AddItem first_value & " Dollar Coin"
Else
   If first_value < 5 Then
      List1.AddItem first_value & " Dollar Coins"
   
   
   Else
      If first_value < 10 Then
        remainder = first_value - 5
        If remainder < 2 Then
         List1.AddItem "5 dollar bill " & remainder & " Dollar Bill"
        Else
         List1.AddItem "5 dollar bill " & remainder & " Dollar Bill"
        End If
      End If
   End If
End If
'i have only done the first instance
   Let remainder = Mid(second_value, 1, 1) - 5
   Let last_value = Mid(second_value, 2, 1)
   If remainder < 2 Then
      List1.AddItem "50 CENTS and " & remainder & last_value & " CENT"
   Else
      List1.AddItem "50 CENTS and " & remainder & last_value & " CENTS"
   End If
Let price_entered = Text1.Text

End Sub

add a command button a listbox and a textbox then paste the code into the command button it should work !!!!

if i got the terminalogy wrong just play about with it at least you have got the principle!!!!

0
 
LVL 14

Accepted Solution

by:
mcrider earned 15 total points
ID: 2688150
This type of question was previously asked in http://www1.experts-exchange.com/bin/Q.10245098 

However, I am posting the answer again modified to include dollars...

Here's the complete example:

Add a textbox and a command button to a new form then add the following code.


Run the program and type the currency into the textbox and press the command button....


Cheers!®©



THE CODE:

    Private Type ExactChange
        Dollars As Long
        Quarters As Long
        Dimes As Long
        Nickels As Long
        Pennies As Long
     End Type
    Private Function GetExactChange(cChange As Currency) As ExactChange
        Dim iVal As Long
        Dim lDL As Long
        Dim lQ As Long
        Dim lD As Long
        Dim lN As Long
         
        iVal = CLng(cChange * 100)
        lQ = Fix(iVal / 25): iVal = iVal - (lQ * 25)
        lD = Fix(iVal / 10): iVal = iVal - (lD * 10)
        lN = Fix(iVal / 5): iVal = iVal - (lN * 5)
        lDL = Fix(lQ / 4): lQ = lQ - (lDL * 4)
        GetExactChange.Dollars = lDL
        GetExactChange.Quarters = lQ
        GetExactChange.Dimes = lD
        GetExactChange.Nickels = lN
        GetExactChange.Pennies = iVal
    End Function
    Private Sub Command1_Click()
        With GetExactChange(CCur(Text1.Text))
            MsgBox "Dollars: " & CStr(.Dollars) & vbCrLf & _
                "Quarters: " & CStr(.Quarters) & vbCrLf & _
                "Dimes: " & CStr(.Dimes) & vbCrLf & _
                "Nickels: " & CStr(.Nickels) & vbCrLf & _
                "Pennies: " & CStr(.Pennies)
        End With
    End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now