Help on String and Integer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • werks
    New Member
    • Dec 2007
    • 218

    Help on String and Integer

    Hi there programmers.

    How can you tell if the input value in a textbox is an Integer or String is there any code to know this?
  • daniel aristidou
    Contributor
    • Aug 2007
    • 494

    #2
    Originally posted by werks
    Hi there programmers.

    How can you tell if the input value in a textbox is an Integer or String is there any code to know this?
    [CODE=vb] If isnumeric(textb ox.text) = True then
    Msgbox("I am a number")
    Else
    msgbox("I'M not anumber ,im mostlikely a string")
    End if
    [/CODE]
    This help?

    Comment

    • werks
      New Member
      • Dec 2007
      • 218

      #3
      Originally posted by daniel aristidou
      [CODE=vb] If isnumeric(textb ox.text) = True then
      Msgbox("I am a number")
      Else
      msgbox("I'M not anumber ,im mostlikely a string")
      End if
      [/CODE]
      This help?
      Thank you! Thank you! Thank You! very much. You saved my day.


      Better Than Yesterday ^^

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        I'd just like to point out that by definition, the value in a textbox is always a string. What you're testing is whether it's possible for VB to convert that string to a number. (Note, IsNumeric() function won't care whether it's an integer - it could be too large for instance).

        Oh, and a quick tip, daniel. If you're testing a logical value, there's no point in comparing it to True. It already is True or False. So in this example, the code
        If IsNumeric(textb ox.Text) = True Then
        works exactly the same as
        If IsNumeric(textb ox.Text) Then.
        Except that depending on how smart the compiler is, the shorter version might execute ever so slightyl faster.
        Last edited by Killer42; Feb 1 '08, 01:26 AM.

        Comment

        • shuvo2k6
          New Member
          • Jan 2008
          • 68

          #5
          Originally posted by werks
          Hi there programmers.

          How can you tell if the input value in a textbox is an Integer or String is there any code to know this?

          TextBox's Text Property must be String, if u want to check Integer, there is no fucntion for that for ur need u must take some other way.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by shuvo2k6
            TextBox's Text Property must be String, if u want to check Integer, there is no fucntion for that for ur need u must take some other way.
            daniel aristidou already provided a solution which "werks" :) though it may have problems with large numbers or decimals.

            Comment

            • lotus18
              Contributor
              • Nov 2007
              • 865

              #7
              Originally posted by Killer42
              Oh, and a quick tip, daniel. If you're testing a logical value, there's no point in comparing it to True. It already is True or False. So in this example, the code
              If IsNumeric(textb ox.Text) = True Then
              works exactly the same as
              If IsNumeric(textb ox.Text) Then.
              Except that depending on how smart the compiler is, the shorter version might execute ever so slightyl faster.
              I didn't know this huh? I learned something new for this day. haha : )

              Rey Sean

              Comment

              • daniel aristidou
                Contributor
                • Aug 2007
                • 494

                #8
                Hey...killer..y ou have a valid point... i already knew that...i just always put = True in when trying to explain or if there is more than one statement...so as not to get confused.....
                Good point though....

                Comment

                Working...