home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 1717
Discussions: 188,402, Posts: 2,243,609, Members: 232,633
Old February 19th, 2002, 04:37 PM   Digg it!   #1 (permalink)
Ultimate Member
 
Ritalin Kid's Avatar
 
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?

Ritalin Kid is offline   Reply With Quote
Old February 19th, 2002, 05:30 PM     #2 (permalink)
Banned
 
qball's Avatar
 
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...

qball is offline   Reply With Quote
Old February 19th, 2002, 07:13 PM     #3 (permalink)
Ultimate Member
 
Ritalin Kid's Avatar
 
Join Date: Oct 2001
Location: Knoxville, TN
Posts: 1,687
What should pintPBalance be then? As Single or what?

Ritalin Kid is offline   Reply With Quote
Old 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

vass0922 is offline   Reply With Quote
Old February 20th, 2002, 12:11 AM     #5 (permalink)
Member
 
SysRq's Avatar
 
Join Date: Oct 2001
Location: _____L-town_____
Posts: 305
Send a message via ICQ to SysRq
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
SysRq is offline   Reply With Quote
Old February 20th, 2002, 01:00 AM     #6 (permalink)
Member
 
SysRq's Avatar
 
Join Date: Oct 2001
Location: _____L-town_____
Posts: 305
Send a message via ICQ to SysRq
I wonder just how long before Rit realizes he posted under my name where I was on his comp.
SysRq is offline   Reply With Quote
Old February 20th, 2002, 02:39 AM     #7 (permalink)
Ultimate Member
 
Ritalin Kid's Avatar
 
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..
Ritalin Kid is offline   Reply With Quote
Old 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
vass0922 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2906)
3-days in and no threads about Gaza (161)
Misery Loves Company... (2144)
New Build ( Finally ) (7)
CPU wont boot (7)
Building a gaming computer advice (5)
I think I just killed my computer w.. (24)
RCA 52Inch HDTV wont turn on (5)
Folderchat Weekday thread (444)
Recent Discussions
Futronix has water features? (0)
Laptop proccesor to desktop mob.. (2)
Please help! multiple problems! (4)
RCA 52Inch HDTV wont turn on (5)
New Build ( Finally ) (7)
Common Spyware Solutions (97)
How do you move a hard-drive to.. (4)
What is the best external enclo.. (0)
Partition Magic 7.0 (Unallocate.. (17)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 04:50 AM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28