Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to determine number of coins ?

Posted on 2000-04-02
4
Medium Priority
?
203 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 45 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Suggested Courses

610 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