Convert string to integer .asp classic

I have the following code, comments in detail about what should happen:

averageNum = myArray2(0) 'assign variable response.write(TypeName(averageNum)&"<br>") 'check var type: string as expected averageNum = CInt(averageNum) 'convert to integer 

When I run this, I get

  Type mismatch: 'CInt' 

I need to turn the variable into an integer, since I need to perform calculations with it

+5
source share
1 answer

I would check that the value of myArray2(0) is an integer as you expect. An easy way to do this is to use IsNumeric() , which returns a Boolean value.

Something like that;

 averageNum = myArray2(0) 'assign variable 'Check numeric value assume 0 if not numeric. If Len(averageNum) > 0 And IsNumeric(averageNum) Then averageNum = CInt(averageNum) Else averageNum = 0 End If 
+4
source

Source: https://habr.com/ru/post/1200231/


All Articles