Convert string to integer .asp classic

早过忘川 提交于 2020-03-14 07:50:07

问题


I have the following code, comments detail 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 is I get

Type mismatch: 'CInt'

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


回答1:


I would be checking that the value of myArray2(0) is an integer as you're expecting. Simple way to do this is using IsNumeric() which returns a Boolean value.

Something like this;

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


来源:https://stackoverflow.com/questions/25288900/convert-string-to-integer-asp-classic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!