Solved

How to determine number of coins ?

Posted on 2000-04-02
4
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 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