tags:

views:

31

answers:

1

I want to do a CallByName for some Subs but I just can't get it to go.

Everything goes fine until execution reaches the CallByName, then I have problems:

  • Whenever I use Me, it complains about a compile error
  • And if I use frmMyServer, it says "object or method not supported"

Question: How do I do this?

This is what I have :

in my 'modHandleData'

Private Sub HandleRequestScriptedNPC(...)
    ' ...
    NPCMethod = "Scripted_Npc_" & NpcNum
    CallByName Me, NPCMethod, VbMethod, NpcNum, Index
End Sub

in my 'modScriptedNPC'

Public Sub Scripted_Npc_9(ByVal NpcNum As Long, PlayerNum As Long)
    SendOneOptionMsg PlayerNum, "NPC 9", "NPC 9 talks." & vbCrLf & "Then gives you a clue"

End Sub
+3  A: 

You’re calling the code in a module, so there is no Me instance (that only exists in classes, including forms). My VB6 is a bit rusty, but I believe you cannot call methods in modules using CallByName since you need an object.

Konrad Rudolph
+1 Quite true, you can't call methods in modules using `CallByName`. If you are prepared to get very hardcore there are other ways to do it, but I don't recommend them. http://stackoverflow.com/questions/609894/is-there-a-callbyname-equivalent-for-global-functions/609926#609926
MarkJ