经典vbscript/经典ASP中没有类型的Dim语句 [英] Dim statement without type in classic vbscript / classic asp

查看:84
本文介绍了经典vbscript/经典ASP中没有类型的Dim语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在旧版代码中,我发现经典vbscript/经典asp中没有键入内容的"Dim"语句

In legacy code, I have found a "Dim" statement without type in classic vbscript / classic asp

Dim x1

x1是否具有默认类型(例如对象)?

Is there a default type (such as object) that x1 acquires?

是不是vb可能会工作后备词",如果以后会遇到x1 = 3或者x1 ='名称'

Is it true that vb might 'work backwords' and if later it encounters x1 =3 or x1 = 'Name'

它将分别分配相关的类型(整数和字符串)吗?

it will assign the relevant type (integer and string) respectively?

注意:所涉及的代码确实在现实世界中有效.因此,这不是错误,只是经典VB的不幸(IMHO)功能" ...

NOTE: The code involved really does work in the real world. Therefore, this isn't a bug, just an unfortunate (IMHO) 'feature' of classic VB ...

谢谢

推荐答案

经典asp中没有数据类型,每个变量都是变量类型.实际上,在给变量添加DIM时,您不能显式声明数据类型,这是错误的语法.

there are no data types in classic asp, every variable is of a variant type. in fact, you explicitly cannot declare a data type when DIMing a variable, it's incorrect syntax.

但是,一旦变量包含数据,您就可以通过使用诸如以下的特定功能来强制使用要使用的数据类型:

However, once a variable contains data, you can then force the data type you want to use by using specific functions such as:

CInt(x)转换为整数

CInt( x ) convert to a integer

CDbl(x)转换为小数

CDbl( x ) convert to a decimal

CStr(x)转换为字符串

CStr( x ) convert to a string

CBool​​(x)转换为布尔值

CBool( x ) convert to a boolean

您会看到它如何有用:

Response.Write ( CInt( "4" ) = 4 )       true
Response.Write ( CInt( "4" ) = "4" )     false

这篇关于经典vbscript/经典ASP中没有类型的Dim语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆