Solved

How to determine number of coins ?

Posted on 2000-04-02
4
182 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 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