Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
| Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 31st, 2007, 06:24 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default [VB6] split up of an amount in monetary unit

Hello,

first of all: Hi! I'm new here :rolleyes:

For school we've got to make a very small project in Visual Basic. But I've got a 'little' problem: the deadline is allready in about 8 hours. I'm quite a VB newby, I prefer PHP much more :cool: , but that's the reason why I would like to have some help.

I'm from the Netherlands, my English is not very good. But I'll try to explain my self as clear as possible. If you don't understand my poor English, feel free to tell me and I'll try to express myself more clear.

Well... I'll first tell what I've got to make:
(I don't know if I translated the next sentence correctly) We've got to make a program which splits up an amount into monetary units (So for example: If the input is 18 euro's, the output will be: 1 ten euro bill, 1 five euro bill, 1 two euro coin, 1 one euro coin). I hope it's clear what I mean.

Like I allready told before: I'm a Visual Basics newby. I tried some things, but I've got the feeling I don't know enough to make this exercise. This is my current code (It's probalby 100% wrong, but... Yeh... I'll just show it :P):

Code:
option explicit

dim amount_of_money as double
dim left_over as double
dim number_of_bills_or_coins() as double
dim kind_of_bill_or_coin() as double

private sub command1_click()

amount_of_money = invoerbedrag.Text

redim kind_of_bill_or_coin(13)
kind_of_bill_or_coin(13) = "0,05"
kind_of_bill_or_coin(12) = "0,10"
kind_of_bill_or_coin(11) = "0,20"
kind_of_bill_or_coin(10) = "0,50"
kind_of_bill_or_coin(9) = "1,00"
kind_of_bill_or_coin(8) = "2,00"
kind_of_bill_or_coin(7) = "5,00"
kind_of_bill_or_coin(6) = "10,00"
kind_of_bill_or_coin(5) = "20,00"
kind_of_bill_or_coin(4) = "50,00"
kind_of_bill_or_coin(3) = "100,00"
kind_of_bill_or_coin(2) = "200,00"
kind_of_bill_or_coin(1) = "500,00"

redim number_of_bills_or_coins(13)

left_over = amount_of_money

for i = 1 to 13
    number_of_bills_or_coins(i) = left_over / soort(i)
    number_of_bills_or_coins(i) = Int(number_of_bills_or_coins(i))
    left_over = amount_of_money - number_of_bills_or_coins(i)
Next i
The code isn't finished yet, but I've got the feeling I'm not doing very well... So I don't like it to waste a few hours in 'programming' some useless code which aint gonna work.

I would really appreciate it if you could help me.

Many thanks,
Kip de Baas

 
Old April 2nd, 2007, 10:35 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

First of all, I would switch to the Currency variable type. It is guaranteed to not have decimal issues such as you might see with floating point numbers (Singles and Doubles). By the way, Doubles have way more precision than you need for something like this. Their number of decimal digits harms their use in a case like this.

The basic algorithm is to try to divide by the highest denomination.
Keep track of how many times it is divisible, let’s say “DivNo”.
If DivNo > 0 then subtract [DivNo × denomination] from the total, move to the next denomination down, and do that again.

Keep it up until you have used up the smallest denomination.

So you will need to keep a “tally” for [u]each</u> denomination, and you will need a temporary variable to keep the value that you will be subtracting from.

Using an array of denominations is good. You could add a second element that initializes to 0, to hold the tally for each denomination. (Be sure to have a separate array for each problem, or you will have data from one run possibly being “imposter data” for the next run.)

In VB using “\” instead of “/” for a division problem executes integer division.

You should try to use shorter variable names. For instance, name your array Denoms (for “Denominations”).

Since you know in advance how large the array will be, you should dimension it in the declaration, rather than using a ReDim statement.

Is there really no 0.01 Euro coin?

Finally, with respect to English (though your English is actually good; probably the only reason I would have know that you are not a native English speaker is your “I'll first tell what I've got to make” instead of “First I'll first tell what I have to do”.

But just as a tip (one which a lot of English speakers could stand to learn) is that words like "clear" are adjectives, they modify nouns: "This water is clear." "Your meaning is clear."
"Clearly" is an adverb, which modifies verbs:
   "I'll try to explain my self as clear as possible" should be "I'll try to explain my self as clearly as possible"
   "I'll try to express myself more clear" should be "I'll try to express myself more clearly" or "I'll try to be more clear" (Also, cannot and myself are each one word. Using "can not" and "my self" are also common mistakes.)



Is that helpful?




Similar Threads
Thread Thread Starter Forum Replies Last Post
Unit Test josericardo_jr BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 0 August 9th, 2007 08:19 AM
Where are all the unit tests? Extrakun BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 1 July 17th, 2007 05:39 PM
Unit Testing jeffmorris BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 7 May 14th, 2007 06:51 AM
Unit Testing userrob BOOK: ASP.NET Website Programming Problem-Design-Solution 2 November 9th, 2005 10:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.