我如何使vbscript数据类型为LONG的子类型为2,147,483,647? [英] how do i make a vbscript data type subtype LONG to get it to be 2,147,483,647?

查看:120
本文介绍了我如何使vbscript数据类型为LONG的子类型为2,147,483,647?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,一次显示一个目录中的10张图像.在目录中,我现在有55,000张图像.一旦下面的zz达到32,767,它就会停止.如何使ZZ成为LONG的子类型,使其变为2,147,483,647(下面的代码不准确,只是快速完成以向您展示我要实现的循环)

I have a web page that displays 10 images at a time from a directory. In the directory I have now 55,000 images. Once zz below hits 32,767 it stops. How do I make ZZ into a subtype LONG to get it to be 2,147,483,647 (the code below is not accurate, just quickly done to show you the loop I am achieving)

pp = Request("pp")  ' pp could be at 40000

filecount = 0 

dim zz

For Each file in filecoll

    zz = zz + 1

    If ZZ > PP then 

        response.write  'show image here 

    end if

Next

推荐答案

实际的问题与long类型无关-至少不是直接相关.您的问题是 pp 是一个字符串,而应该是数字.要解决您的问题,只需将其转换为long即可:

The actual problem got nothing to do with long type - at least not directly. Your problem is that pp is a string while it should be numeric. To solve your problem just convert it to long:

pp = CLng(Request("pp"))

然后比较就可以了.

简而言之,问题在于比较两个变量-如这篇很棒的博客文章,作者:埃里克·利珀特(Eric Lippert),其中一个变量包含一个字符串值,一个变量包含数字值,并且您将它们进行比较,任何字符串都大于任何数字不管 zz 的值是多少,都意味着 pp 总是更大.

In short, the problem is when comparing two variables - as explained in this great blog post by Eric Lippert when one variable contains a string value and one variable contains numeric value and you compare them, any string is greater than any number - so no matter what is the value of zz it means that pp will always be greater.

现在进行更详细的说明.(使用 Nilpo 的帮助)

Now for a more detailed explanation. (Using some help from Nilpo)

在VBScript中,所有变量实际上都是Variant类型.它们是松散类型的,这意味着它们可以在任何时候保存任何类型的数据,并且可以更改它们包含的值的类型.

In VBScript, all variables are actually of the type Variant. They are loosely typed, meaning that they can hold any type of data at any point and the type of value they contain can be changed.

VBScript的比较运算符(<,>,<>,=)用于进行数字比较.由于字符串不是数字数据类型,因此在将字符串与数字进行比较时,这些比较运算符将永远不会返回可用的结果.这并不意味着字符串不能包含数字值.它可以包含代表数字值的数字或字母字符串,例如"4.56","4.5e3"或十五".在这种情况下,VBScript提供了一系列转换函数,这些转换函数指示VBS解释器将值视为特定类型.它还提供了 IsNumeric 函数,该函数返回true或false以指示是否可以将字符串值视为数字.

VBScript's comparison operators (<,>,<>,=) are used to make numeric comparisons. Since a string is not a numeric data type, these comparison operators will never return a usable result when comparing a string to a number. That does not mean that a string cannot contain a numeric value. It could contain a string of numbers or letters that represent a numeric value such as "4.56", "4.5e3", or "fifteen". In cases like this, VBScript provides a series of conversion functions that instruct the VBS interpreter to treat a value as a specific type. It also provides the IsNumeric function that returns true or false to indicate whether a string value can be treated as a number.

考虑所有这些,正确的方法是:

Considering all of this, the proper way of doing this would be:

pp = Request("pp")

filecount = 0

Dim zz = 0

For Each file In filecoll
    zz = zz + 1
    '...
Next

If IsNumeric("pp") Then
    If zz > CLng(pp) Then
        Response.Write  'show image here
    End If
Else
    ' pp is not a number, perhaps it is empty or contains bad characters
End If

其他注意事项:

  1. 包含单个值的变量是String或数字数据类型.这意味着诸如Currency或Date和booleans之类的数据类型本质上就是数字.
  2. 变量也可能包含对对象和数组的引用.像字符串一样,它们不能用于数字比较.
  3. Null,Empty和Nothing也是要考虑的有效值,它们指示变量的状态.当没有为变量分配实数时使用这些变量.由于是非数字形式,因此无法在数字比较中使用.
  4. VBScript提供了用于比较非数字值的特定函数和运算符.
  5. 由于VBScript不使用严格的数据类型,因此比较具有不同精度的数字时,数据宽度不是问题.为了进行比较,将在较宽的数据宽度处比较两个操作数.(对于算术运算也是如此.在这种情况下,结果值将具有更宽的数据宽度以保持精度.)

这篇关于我如何使vbscript数据类型为LONG的子类型为2,147,483,647?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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