Connecting Tech Pros Worldwide Help | Site Map

Using Array Within For Statement to Call Dynamic Procedure

Newbie
 
Join Date: Aug 2007
Posts: 28
#1: Oct 26 '07
Hi,

I have an IF..Then statement that I am using to determine which procedure to Call. Within the "else" section, I want to use a For..Next coding to loop through 3 different "call procedures". Here is what I have so far:


Dim arrCall As Variant
ReDim arrCall(2)

arrCall(0) = "GetData1"
arrCall(1) = "GetData2"
arrCall(2) = "GetData3"

If optVersion.Value = True Then

Call GetProcedure1

Else

For i = 0 to 2

Call arrCall(i)

Next

End If

But it keeps giving me the error: Sub or Function needed.

So basically, I want the For..Next loop to go through each "CallData". I'm not sure what I'm doing wrong.

Thanks.
kadghar's Avatar
Expert
 
Join Date: Apr 2007
Location: Mexico City
Posts: 1,155
#2: Oct 26 '07

re: Using Array Within For Statement to Call Dynamic Procedure


arrCall is a variable, not a function or sub, you cannot call it

i think you want to call GetData1, GetData2 and GetData3, call them one by one:
else
call getdata1
call getdata2
call getdata3
end if

HTH
kadghar's Avatar
Expert
 
Join Date: Apr 2007
Location: Mexico City
Posts: 1,155
#3: Oct 26 '07

re: Using Array Within For Statement to Call Dynamic Procedure


oh, i forgot, it'll be good if you say what version you're using. In VBA is possible to do it with strings.

lets say you have a sub called "Test1"

Expand|Select|Wrap|Line Numbers
  1. dim Str1 as string
  2.  
  3. str1="Test1"
  4.  
  5. application.run(str1)
this will call the sub Test1 :)

HTH
Familiar Sight
 
Join Date: Oct 2007
Posts: 158
#4: Oct 27 '07

re: Using Array Within For Statement to Call Dynamic Procedure


hi

first make the proceedures you are calling public.

then use CallByName function
e.g. CallByName array(0)


regards
manpreet singh dhillon Hoshiarpur
Reply