Converting values from strings to integers 
Author Message
 Converting values from strings to integers

I am using the code im VB6:

Dim varIDNO As Variant

   varIDNO = InputBox("Enter SHS ID Number:", "Find Participant", "")
   If varIDNO = "" Or varIDNO < "160000" Or varIDNO > "160999" Then
          MsgBox "This is an incorrect SHS ID Number"
          Exit Sub
  End If

Whenever I enter "1600222" - one character longer, My messagebox does not
appear.
How do I convert the string to integer?



Wed, 16 Jul 2003 11:47:50 GMT  
 Converting values from strings to integers

Syntax

        CInt(expression)

The expression argument is any valid expression.

Remarks

In general, you can document your code using the subtype conversion
functions to show that the result of some operation should be expressed as a
particular data type rather than the default data type. For example, use
CInt or CLng to force integer arithmetic in cases where currency,
single-precision, or double-precision arithmetic normally would occur.
Use the CInt function to provide internationally aware conversions from any
other data type to an Integer subtype. For example, different decimal
separators are properly recognized depending on the locale setting of your
system, as are different thousand separators.

If expression lies outside the acceptable range for the Integer subtype, an
error occurs.

----------------------------------------------------------------------------
----

Note CInt differs from the Fix and Int functions, which truncate, rather
than round, the fractional part of a number. When the fractional part is
exactly 0.5, the CInt function always rounds it to the nearest even number.
For example, 0.5 rounds to 0, and 1.5 rounds to 2.

----------------------------------------------------------------------------
----

----------------------------------------------------------------------------
----
? 1996 by Microsoft Corporation


Quote:
> I am using the code im VB6:

> Dim varIDNO As Variant

>    varIDNO = InputBox("Enter SHS ID Number:", "Find Participant", "")
>    If varIDNO = "" Or varIDNO < "160000" Or varIDNO > "160999" Then
>           MsgBox "This is an incorrect SHS ID Number"
>           Exit Sub
>   End If

> Whenever I enter "1600222" - one character longer, My messagebox does not
> appear.
> How do I convert the string to integer?



Wed, 16 Jul 2003 12:56:04 GMT  
 Converting values from strings to integers
   varIDNO = InputBox("Enter SHS ID Number:", "Find Participant", "")
   If varIDNO = "" Or CLng(varIDNO) < "160000" Or CLng(varIDNO) > "160999"
Then
          MsgBox "This is an incorrect SHS ID Number"
          Exit Sub
  End If

Dan

Quote:

> I am using the code im VB6:

> Dim varIDNO As Variant

>    varIDNO = InputBox("Enter SHS ID Number:", "Find Participant", "")
>    If varIDNO = "" Or varIDNO < "160000" Or varIDNO > "160999" Then
>           MsgBox "This is an incorrect SHS ID Number"
>           Exit Sub
>   End If

> Whenever I enter "1600222" - one character longer, My messagebox does not
> appear.
> How do I convert the string to integer?



Thu, 17 Jul 2003 05:01:06 GMT  
 Converting values from strings to integers


Quote:
>    varIDNO = InputBox("Enter SHS ID Number:", "Find Participant", "")
>    If varIDNO = "" Or CLng(varIDNO) < "160000" Or CLng(varIDNO) > "160999"

If you are converting the input to a Long you should convert the constants
as well:
If IsNumeric(varIDNO) then
  If CLng(varIDNO) < 160000 Or CLng(varIDNO) > 160999 Then


Thu, 17 Jul 2003 08:55:29 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Converting Currency Values to their string values

2. Help: converting long integer colour values to RGB

3. [VBS] vbscript function to convert 64-bit integer to date value

4. How to convert vbError variant to integer value?

5. Convert float/integer values to binary and vice versa

6. Convert integers and strings to byte array

7. stupid question: convert string to integer?

8. how to convert string to integer for calculation?

9. Converting string to integer/number

10. convert string to integer?

11. How to convert String to Integer in VB6?

12. convert string to integer

 

 
Powered by phpBB® Forum Software