简体   繁体   English

VB6变量记录集名称

[英]VB6 variable recordset name

Is it possibile to access a recordset using a variable for the name ? 是否可以使用名称变量访问记录集?

For example, i've a table with 10 fields called Name01,Name02,Name03.....Name10. 例如,我有一个包含10个字段的表,名为Name01,Name02,Name03 ..... Name10。 I need to cycle through them so it would be nice to just use one instruction insted of repeating the same one with 10 different name. 我需要循环使用它们,这样就可以使用一条带有10个不同名称重复相同的指令。

This is the code i'm using now 这是我现在使用的代码

Sal01 = rsUtility!Order01

Sal02 = rsUtility!Order02

.... 

Sal10 = rsUtility!Order10

This is what i would like to accomplish : 这就是我想要完成的事情:

for i = 1 to 10 
    VariableName = "Order" & i 
    Sal(i) = rsUtility!VariableName 
next i

Here you go: 干得好:

for i = 1 to 10 
    VariableName = "Order" & i 
    Sal(i) = rsUtility(VariableName)
next i

Since your variables have a 2 digit ending, you gotta use a proper format and not just "Order" & i , because it will result in Order1 and not Order01 由于你的变量有一个2位数的结尾,你必须使用正确的格式而不仅仅是"Order" & i ,因为它将导致Order1而不是Order01

For i = 1 to 10 
    Sal(i) = rsUtility("Order" & Format(i,"00") )
Next i

The loop above will assign a value to a corresponding array element from DB variables in the range from Order01 to Order10 inclusive 上面的循环将从Order01Order10包括Order01范围内的DB变量为相应的数组元素Order10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM