DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

functions and arrays

Hi everybody

I am faced a problem with Vscript , i hope someone can help: i have the following code

'code starts here
function dosometask()
    dim y(3)
        y(1)=1
        y(2)=2
        y(3)=3
    dosometask=y
end function

dim u(3)
u=dosometask()
msgbox(u(1)) 
'code ends here

the function  is going to manipulate an array inside of it , and must return the array , then this returning array should be assigned in other array outside the function , i got type mismatch error, in line u=dosometask(), in general how can i assign one array to other assuming both are of the same size 

dim a(3)
dim b(3)

b=a
and get a copy of a in b


thanks in advance


0 Kudos
Message 1 of 3
(3,567 Views)

Hi

Arrays can't be assigned on this Kind.

If you work with arrays, you should use a loop(always!), for example: for-loop

for i = 1 to 3

     b(i) = a(i)
next
 
here is the right code

'code starts here
function dosometask()
    dim y(3)
        y(1)=1
        y(2)=2
        y(3)=3
    dosometask=y
end function

dim u
u=dosometask()
msgbox(u(1))
 
'all
for i = 1 to uBound(u)
  msgBox (u(i))
next 
 
'code ends here

 
 

Message Edited by joh_joh on 08-08-2005 04:24 AM

0 Kudos
Message 2 of 3
(3,550 Views)

Hi arkangel,

You can do this, you just need to dimension the variable outside the Function as a normal scaler variant [dim u], not a fixed-length array [dim u(3)].

'code starts here
function dosometask()
    dim y(3)
        y(1)=1
        y(2)=2
        y(3)=3
    dosometask=y
end function

dim u
u=dosometask()
msgbox(u(1)) 
'code ends here

Ask if you have further questions,
Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 3 of 3
(3,542 Views)