Connecting Tech Pros Worldwide Help | Site Map

Using Array Within For Statement to Call Dynamic Procedure

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 26th, 2007, 08:29 PM
Newbie
 
Join Date: Aug 2007
Posts: 28
Default Using Array Within For Statement to Call Dynamic Procedure

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.
Reply
  #2  
Old October 26th, 2007, 09:32 PM
kadghar's Avatar
Expert
 
Join Date: Apr 2007
Location: Mexico City
Age: 25
Posts: 1,134
Default

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
Reply
  #3  
Old October 26th, 2007, 09:40 PM
kadghar's Avatar
Expert
 
Join Date: Apr 2007
Location: Mexico City
Age: 25
Posts: 1,134
Default

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
Reply
  #4  
Old October 27th, 2007, 01:53 AM
Familiar Sight
 
Join Date: Oct 2007
Posts: 138
Default

hi

first make the proceedures you are calling public.

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


regards
manpreet singh dhillon Hoshiarpur
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.