Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is there a way to make an array of functions? Essentially:

 

Private Sub GamePlay()
Call Question(x)()
End Sub

Private Sub Question1()
....
End Sub

Private Sub Question2()
....
End Sub

etc.

To err is human, to really foul things up requires a computer.
  • *Experts*
Posted

No need.

 

Put all your Question subs inside a class, create an instance of it, and then you can use this function:

Private Sub MethodByName(ByVal obj As Object, ByVal method As String, ByVal args As String())
       Dim t As Type
       t = obj.GetType
       t.InvokeMember(method, Reflection.BindingFlags.InvokeMethod, t.DefaultBinder, obj, args)
End Sub

To call each function by its name. So some code like this would work:

Dim q As New Questions() 'Questions being the class containing all the Question subs.

MethodByName(q, "Question" & myNumber, New String())

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...