Connecting Tech Pros Worldwide Help | Site Map

Using Array Within For Statement to Call Dynamic Procedure

  #1  
Old October 26th, 2007, 09:29 PM
Newbie
 
Join Date: Aug 2007
Posts: 28
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.
  #2  
Old October 26th, 2007, 10:32 PM
kadghar's Avatar
Expert
 
Join Date: Apr 2007
Location: Mexico City
Posts: 1,155

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

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 14th, 2005 04:15 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 11:37 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 09:56 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 03:15 AM