February 19th, 2002, 04:37 PM
|
#1 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Knoxville, TN
Posts: 1,687
| Could someone help me with this code?
Ok I'm making a calculator to calculate currency.. this is what I got so far..
Dim pintPBalance As Integer
txtPrevious.Text = Format(txtPrevious.text, "Currency")
pintPBalance = txtPrevious.Text
What I'm tryin to do is to get it to convert regular numbers into a currency value, which it does ok, but if someone puts letters or the currency value in themselves (ie. $1.00) then I get an error. I would like the program to be able to accept numbers in either currency or general form and turn any general characters entered into $0.00 in vbRed. Can someone tip me off here? |
| |
February 19th, 2002, 05:30 PM
|
#2 (permalink)
| | Banned
Join Date: Oct 2001
Posts: 447
| Quote:
Dim pintPBalance As Integer
txtPrevious.Text = Format(txtPrevious.text, "Currency")
pintPBalance = txtPrevious.Text
| First, if 'pintPBalance' is an Integer, how it gonna hold '99.99'? Seems you are formatting text to currency and basically casting into 'pintPBalance' as a String by 'variant'...
How are the users entering data? command line, or some form of form, lol?
Regardless, if you want to accept all types of input, you will need to do some string manips and validation (what if they enter symbols, letters?)
Far easier to use currency editmask on text control so user can only enter #s and period (.). Editmask will display currency ($##.##), text control will thus return real number in format of ##.##, or however big... |
| |
February 19th, 2002, 07:13 PM
|
#3 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Knoxville, TN
Posts: 1,687
|
What should pintPBalance be then? As Single or what? |
| |
February 19th, 2002, 08:29 PM
|
#4 (permalink)
| | Ultimate Member
Join Date: Oct 2001
Posts: 21,026
|
what exactly kind of answers do you expect to get?
If you're expecting text or numbers, including periods and dollar signs etc you can not in anyway use an integer.
If you want dollar signs and crap in there just use a string or variant, you'll have to manipulate it manually though.
You do not want an integer, as an integer (and a single) only do "Integers" which means no decimal points.
WHAT?!?!
Was just reading through MSDN and vb doesn't have a freakin' float type?! not even REAL wtf?!
POS!!
Anyways...I digress...
One option you have IF you JUST want to do numbers.... Quote: |
Currency variables are stored as 64-bit (8-byte) numbers in an integer format, scaled by 10,000 to give a fixed-point number with 15 digits to the left of the decimal point and 4 digits to the right. This representation provides a range of -922,337,203,685,477.5808 to 922,337,203,685,477.5807.
| So you can do Dim curVariable As Currency
This allows you 4 digits to the right of the decimal point.
IF what you're looking for is finding bad characters in a STRING then you can do a InStr([start, ]string1, string2[, compare])
So you can do
If InStr(strString, "$") > 0 Then
do some stuff
End If
InStr returns an integer that specifies the location of the string you were looking for, so if it returns something greater than 0 it means it found one.
Hope it pushes in the right direction.
Oh btw, if you just want to remove bad characters you can do a
strString = Replace(strString, "$", "")
This will replace that character with nothing inside the string so $4.50 will be come 4.50 |
| |
February 20th, 2002, 12:11 AM
|
#5 (permalink)
| | Member
Join Date: Oct 2001 Location: _____L-town_____
Posts: 305
|
I am so silly... how bout this... it works great
Dim strPrevious = txtPrevious.text
If IsNumeric(strPrevious) Then
strPrevious = Format(strPrevious, "Currency")
Else
txtPrevious.text = "$0.00"
txtPrevious.Forecolor = vbRed
End if
Works like a charm!
Thanks much guys!
__________________
d[o_o]b
|
| |
February 20th, 2002, 01:00 AM
|
#6 (permalink)
| | Member
Join Date: Oct 2001 Location: _____L-town_____
Posts: 305
|
I wonder just how long before Rit realizes he posted under my name where I was on his comp. |
| |
February 20th, 2002, 02:39 AM
|
#7 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Knoxville, TN
Posts: 1,687
|
Yep.. I'm gonna have to do something bought that... well regardless I finished the program.. what fun.. my first proggie in VB.. |
| |
February 20th, 2002, 08:13 PM
|
#8 (permalink)
| | Ultimate Member
Join Date: Oct 2001
Posts: 21,026
|
Congrats
Hey SysRq I did respond to your PM but your box is full :P
If you come across any other projects you'd like to take on look us up maybe we can help  |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |