Valhalla Legends Forums Archive | Visual Basic Programming | VBScript, Accessing another Sub

AuthorMessageTime
CrAz3D
I have my VBScript code loaded from a text File
[code]Sub OnTalk(Username, Flags, Message, Ping)
   if username = "CrAz3D[xL]" then
      form1.addchat vbred, message & "::" & username
   end if
end sub[/code]

Upon the users talking in the channel it calls that code. What I'm not sure how to do is how to add my Ban sub, which is located in a Module, to the msscript to allow the VBScript Code to use the Ban sub.

Any helpful tips?
March 24, 2004, 1:18 AM
UserLoser.
Not sure about modules, but if it's in a Class Module then you can do it. Here's my example:

Some other global module...
[code]
Global LocalCommand as CLocalCommands
[/code]
---
The sub where you initialize & load the scripts:
[code]
Set LocalCommand = New CLocalCommands
MyScript.AddObject "CommandProcessor", LocalCommand, True
[/code]

Then you can do:
[code]
Sub User_Talk(Username, Text, Flags, Ping)
If InStr(1, Username, "xL", 1) Then
CommandProcessor.ProcessCommand "ban " & Username & " ew"
End If
Exit Sub
[/code]
March 24, 2004, 1:21 AM
CrAz3D
This works for anything in classes, does anyone have something that might work for modules?
March 24, 2004, 1:30 AM
Stealth
I don't believe you can do it in modules. The Script control only allows you to "expose" objects, including classes and form controls, to it.

The solution? Write a wrapper class such as StealthBot's ScriptSupportClass.txt. You can find ScriptSupportClass.txt (which is basically the class' source code) at http://cold-chaos.net/stealth/ScriptSupportClass.txt or installed with any copy of StealthBot.
March 24, 2004, 3:30 AM
CrAz3D
[quote author=Stealth link=board=31;threadid=5950;start=0#msg51323 date=1080099032]
I don't believe you can do it in modules. The Script control only allows you to "expose" objects, including classes and form controls, to it.

The solution? Write a wrapper class such as StealthBot's ScriptSupportClass.txt. You can find ScriptSupportClass.txt (which is basically the class' source code) at http://cold-chaos.net/stealth/ScriptSupportClass.txt or installed with any copy of StealthBot.
[/quote]

I've looked through this, what I am wondering is how you called the GetAccess function, or your Ban sub.
March 24, 2004, 4:17 AM
Fr0z3N
[quote author=UserLoser. link=board=31;threadid=5950;start=0#msg51276 date=1080091311]
Then you can do:
[code]
Sub User_Talk(Username, Text, Flags, Ping)
If InStr(1, Username, "xL", 1) Then
CommandProcessor.ProcessCommand "ban " & Username & " ew"
End If
Exit Sub
[/code]
[/quote]

Jerk lol

;)
March 24, 2004, 4:23 AM
Stealth
[quote author=CrAz3D link=board=31;threadid=5950;start=0#msg51333 date=1080101865]
I've looked through this, what I am wondering is how you called the GetAccess function, or your Ban sub.
[/quote]

The class is instantiated within my program. Classes, as a part of your program, can call public methods contained within modules (as GetAccess and Ban are). You write the wrapper functions because the script control can only access what it can see.

Think of it like this: (No smart comments ;) )
Your program is a car. The script control is in the trunk. It can't see the rest of the car -- only other things you put in the trunk. ScriptSupportClass (and similar wrappers) are like adding a small passageway between the trunk and the body of the car. Through this passage you can see a very limited bit of the inside of the car, but still not the majority of its interior.

Your wrapper class acts as a window to the rest of your program's code. You decide what the script control gets to see and what it doesn't get to see -- by controlling what functions you add to the wrapper class, you control the size and shape of the window into the body of the car.

HTH.
March 24, 2004, 5:12 AM
UserLoser.
Can add anything that's an object, which modules are not (like stated above a few times):
[code]
ScriptControl.AddObject "NameToUseInScripting", frmMain.MyObject, True 'Forgot what the boolean is for off the top of my head
ScriptControl.AddObject "PacketBuffer", MyPacketBufferClass, True
ScriptControl.AddObject "UserLiser", frmMain.lvwUsers, True
[/code]

ect.
March 24, 2004, 1:05 PM
CrAz3D
[quote author=Stealth link=board=31;threadid=5950;start=0#msg51336 date=1080105167]
[quote author=CrAz3D link=board=31;threadid=5950;start=0#msg51333 date=1080101865]
I've looked through this, what I am wondering is how you called the GetAccess function, or your Ban sub.
[/quote]

The class is instantiated within my program. Classes, as a part of your program, can call public methods contained within modules (as GetAccess and Ban are). You write the wrapper functions because the script control can only access what it can see.

Think of it like this: (No smart comments ;) )
Your program is a car. The script control is in the trunk. It can't see the rest of the car -- only other things you put in the trunk. ScriptSupportClass (and similar wrappers) are like adding a small passageway between the trunk and the body of the car. Through this passage you can see a very limited bit of the inside of the car, but still not the majority of its interior.

Your wrapper class acts as a window to the rest of your program's code. You decide what the script control gets to see and what it doesn't get to see -- by controlling what functions you add to the wrapper class, you control the size and shape of the window into the body of the car.

HTH.

[/quote]

Oh, makes sense. But how do you encorporate your ScriptSupportClass into your program, so that it works as a class?
March 24, 2004, 3:06 PM
Stealth
It's just an ordinary .cls class file. Public ScriptSupportClass as clsScriptSupportClass in a module, then on Form_Load() I initialize it (set ScriptSupportClass = new ScriptSupportClass) and on Form_Unload() I erase it (Set ScriptSupportClass = nothing). Then, when the script control is initialized I pass it as an object, as UserLoser described above.
March 24, 2004, 3:27 PM
CrAz3D
okey dokey, quite dandy.

I'll see what I can do.

Thank you very much indeed.
March 24, 2004, 3:59 PM

Search