本文介绍了将字符串转换为整数.asp classic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,注释详细说明了会发生什么:

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

当我跑步时我得到了

Type mismatch: 'CInt'

我需要将其转换为整数,因为我需要使用它来进行计算

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

推荐答案

我将检查myArray2(0)的值是否是您所期望的整数.简单的方法是使用IsNumeric(),它返回一个Boolean值.

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.

像这样的东西

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

这篇关于将字符串转换为整数.asp classic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 03:54