Results 1 to 12 of 12

Thread: negative in text box

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    MN
    Posts
    362

    negative in text box

    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?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    VB Code:
    1. CLong(text1.Text) < 0 Then '...

    try that

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    MN
    Posts
    362
    CLong?????

    tried it, didnt work........Hmmmmmm

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091


    Oops, try CLng

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5
    Tygur
    Guest
    He means CLng, but I suggest you use Int because it's a little faster.

    How does <0 look for a decimal?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    MN
    Posts
    362
    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

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    MN
    Posts
    362
    Ok. Got it now...

    Thanks

  8. #8
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    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

  9. #9
    Tygur
    Guest
    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.

  10. #10
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    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.
    Attached Files Attached Files

  11. #11
    Tygur
    Guest
    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.

  12. #12
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width