简体   繁体   中英

how can i fill multiple variable with array?

i use vb 2010,i have variable and i want to fill them with array. so, in array is variable. Example:

public rbt_ckd , nozzle_c, carrier_x as integer 
public state(3) as integer      
dim arrayX() as integer = {rbt_ckd,nozzle_c,carrier_x}      

for i as integer = 0 to 2     
    arrayX(i) = state(i)      
next

i tried this script format. but it is not work.

How can I do this in VB.NET?

Change Public for Dim :

Sub Test()

    Dim rbt_ckd, nozzle_c, carrier_x As Integer
    Dim state(3) As Integer
    state(0) = 10  'sample added
    state(1) = 11  'sample added
    state(2) = 12  'sample added
    Dim arrayX() As Integer = {rbt_ckd, nozzle_c, carrier_x}

    For i As Integer = 0 To 2
        arrayX(i) = state(i)
    Next

    Debug.Print(rbt_ckd)  ' this will print 0, not 10

End Sub

Note that filling is by value, not by reference. (See the output of added Debug.Print() .)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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