Computing.Net > Forums > Programming > VB - Just a quick question :)

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

VB - Just a quick question :)

Reply to Message Icon

Original Message
Name: Buzzz
Date: November 12, 2002 at 14:40:34 Pacific
Subject: VB - Just a quick question :)
OS: Xp
CPU/Ram: 1.1 Gig 256 DDR
Comment:

Hi guys,
Just a quick question (I think). Ive been going around in circles all nite trying to figure this one out, I was just about to give up then I rememered this place!
Ive only been learning VB for two weeks and I have to write a simple program to convert currency.
Here we go....
I have to write a program to convert 'X' amount of Japenese Yen into British pounds. I have writen the code and the program does the conversion however, I need to alter the way that the result is presented.
When the conversion has taken place the result is:

372 Yen = 188.9988976756 Pounds

Thats fine, but I need the result to read somthing like this:

372 Yen = 1 Pound and 88 pence

Does anyone know how to do this as I havent got a clue and my head is really starting to hurt now :(

One other thing while Ive got your attention, is there anyway to clear a textbox when the command button is clicked?

If anyone can help me I would be very very gratefull and I may not get kicked off my course because I havent finished my assignment.


Report Offensive Message For Removal


Response Number 1
Name: Spencer Ruport
Date: November 12, 2002 at 16:30:21 Pacific
Reply: (edit)

YenToPounds = 1.968265 'this may be wrong... I don't know the conversion method you are using.

Pounds = FormatNumber(YenAmt / YenToPounds, 0)
Pence = 100 * (FormatNumber(YenAmt / YenToPounds, 2) - Pounds)

In the event that a command button is clicked:
text1.text = "" will clear the text box called text1

P.s. Try doing ur own home work from now on.


Report Offensive Follow Up For Removal

Response Number 2
Name: Jim
Date: November 15, 2002 at 22:04:42 Pacific
Reply: (edit)

Buzz,

To convert 188.99889... into 1 point 88 pence you can use integer division and modulo arithmetic.

First, just stick it in an integer variable. I think thatis done with the trunc() function in VB. Say X. X = trunc(188.99889)... That will give you 188. If you need to round it, there are ways to do that, but for your example you really only want the 188.

Next, to get the pounds, just divide it by 100 and ignore the remainder. Pounds = X / 100.

There are two ways to get the 88 pence. It makes a lot of sense to just subtract the pounds number from it, and whatever is left is pence. Of course by this time your pounds frum X, and whatever is left is pence. Pence = X - (Pounds * 100).

Or, you can use modulo. Pence = X mod 100.

P.S. Ignore that comment Spencer made about doing your own homework from now on. Certainly you probably won't get much help here if you just post the homework assignment and expect someone to do the work for you. However, it is obvious that you have done the work, and just need help with a couple of specific problems. There are some sharp guys that read these boards, and if you have specific questions and can communicate them well, they'll usually get answered pretty quickly.


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have a Desktop Computer anymore?

No
Yes, but only at work
Yes, but its rarely used
Yes, and its a workhorse


View Results

Poll Finishes Today.
Discuss in The Lounge
Poll History




Data Recovery Software