how can my app know if a user included a 'negative' number in a text box?
I tried using
text1 < 0
but, <0 looks for a decimal.....
Any ideas?
Printable View
how can my app know if a user included a 'negative' number in a text box?
I tried using
text1 < 0
but, <0 looks for a decimal.....
Any ideas?
VB Code:
CLong(text1.Text) < 0 Then '...
try that
:)
CLong?????
tried it, didnt work........Hmmmmmm
:rolleyes:
Oops, try CLng
:D
He means CLng, but I suggest you use Int because it's a little faster.
How does <0 look for a decimal?
darn...still aint working......
this is what I have;
a = Val(Text1.Text)
If a = 0 Then
Label1.Caption = "xxxxxxx"
End If
If CLng(a) < 0 Then
Label1.Caption = "yyyyyyy"
End If
Ok. Got it now...
Thanks
Hiya Tygur,
I think long is the native datatype for 32 bit system and so it is the fastest datatype to use, which kind of makes sense when you think about it.
Here is where I found the information:
http://msdn.microsoft.com/library/de...mizingcode.asp
Nucleus,
I wasn't saying that another data type should be used instead of Long. I was just saying that the Int function is a little quicker than the CLng function when you're trying to get a whole number. I'm talking about two functions, not data types.
Long is certainly the fastest datatype and I use it all the time.
OK, now I see what you were saying, my mistake. Just out of interest do you know of a reference to point out the relative speeds of all functions, or does it just come through testing yourself?
Also you know that thread about preventing pasting, well I have been fiddling around with a class to validate text boxes, and it seems to stop pasting even though the code has not been developed to do that yet, which is frustrating as I would like to preserve the ability to paste and optionally turn it off.
Anyway you might be interested in taking a peek and see what you think.
Nucleus,
I found out about Int being quicker because I read it someplace a long time ago. I don't remember where. Since then, I've also tested it out. I guess the easiest way of comparing function speeds is through testing.
The reason why pasting doesn't work in your class module is because you're setting KeyAscii to zero if it's 22, the ascii code for ^V, or Ctrl+V. I usually allow anything under 32 in the KeyPress event to prevent problems like this.
That's a pretty good idea, using a class module to easily apply the code to different textboxes.
LOL. Well forget subclassing, that is a much easier way to disable pasting ;).
Ok, I will post the class in another thread for others to improve and/or get info in a few minutes.