VBA(Excel)的问题 [英] VBA (Excel) question

查看:106
本文介绍了VBA(Excel)的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我是VBA的新手......有人可以详细说明以下一行是做什么的吗?  我知道它正在初始化一个名为rng1的变量,但它的类型是"range"。如果是,该范围可存储多少个值?  

 Dim rng1(1对1,1对1)


此外,我可以在VBScript中做类似的事情吗?  若是,怎么做?


感谢您的帮助!

解决方案

(1 to 1,1对1)表示变量是一个包含1行和1列的数组,即只有1个项目的数组:rng1(1,1)。


由于数据类型如果未指定变量,则它是Variant类型的数组。这意味着任何类型的值(文本,数字,对象)都可以存储在单个数组元素中。


在VBScript中,你不能使用......当...声明时阵列。你只能指定上限;下限始终为0.所以行


Dim rng1 1
1


在VBScript中有效;它相当于


Dim rng1 (0
1   0
1


有4个元素:Rng1(0,0),Rng1(1,0),Rng1(0,1)和Rng1(1,1)。


如果你想要在VBScript中声明一个单元素数组,使用


Dim rng1(0,0)


这只有单个元素rng1(0 ,0)。



Hello,

I am new to VBA...can someone please elaborate what the following line is doing?  I know it's initializing a variable named rng1 but is it of type "range" and if yes, how many values can this range store?  

Dim rng1(1 To 1, 1 To 1)

Furthermore, can I do something similar in VBScript?  If yes, how?

Thanks for help!

解决方案

The (1 to 1, 1 to 1) means that the variable is an array with 1 row and 1 column, i.e. an array with just 1 item: rng1(1, 1).

Since the data type of the variable is not specified, it is an array of type Variant. This means that any kind of value (text, number, object) can be stored in the single array element.

In VBScript, you cannot use ... To ... when declaring an array. You can only specify the upper bounds; the lower bounds are always 0. So the line

Dim rng1(1, 1)

would be valid in VBScript; it is the equivalent of

Dim rng1(0 To 1, 0 To 1)

which has 4 elements: Rng1(0, 0), Rng1(1, 0), Rng1(0, 1) and Rng1(1, 1).

If you want to declare a single-element array in VBScript, use

Dim rng1(0, 0)

This has just the single element rng1(0, 0).


这篇关于VBA(Excel)的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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