Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Tontow on May 02, 2004, 10:12 PM

Title: VB 6 :Reconizeing a string that varies
Post by: Tontow on May 02, 2004, 10:12 PM
ok, frist the code;

   Select Case UCase(strText)
       Case "!SIGNUP"
           frmui.signup strUser, UCase(strText)
   End Select


Problem;

this is for a bot plugin, strUser = the current user talking and strText = what he typed.

the problem is that the command !signup isnt alwasy an exact match because another word (an aka) sometimes follows it (ie: a person could type "!signup" or he could type "!signup tontow")
Title: Re:VB 6 :Reconizeing a string that varies
Post by: Grok on May 02, 2004, 10:23 PM
I prefer a structure such as the following for parsing triggers:

Private Sub HandleTrigger(strLine As String)
   Dim sChar As String
   If Len(strLine) = 0 Then Exit Sub
   sChar = Left(strLine, 1)
   Select Case sChar
   Case "!"        'handle all ! triggers
       sCmd = Split(Mid(strLine, 2), " ")(0)
       Select Case True
       Case sCmd = "ban"
           Call BanUser(strLine)
       Case sCmd = "kick"
           Call KickUser(strLine)
       Case sCmd = "adduser"
           Call AddUser(strLine)
       End Select
   Case "#"        'handle all # triggers
       sCmd = Split(Mid(strLine, 2), " ")(0)
       Select Case True
       Case sCmd = "time"
           Call CheckCurrentTime
       Case sCmd = "temperature"
           Call CheckCurrentTemperature
       End Select
   End Select
End Sub


(obviously missing security checks, thorough string parsing, etc)
Title: Re:VB 6 :Reconizeing a string that varies
Post by: Tontow on May 02, 2004, 11:48 PM
thx that helped some :) , but how would i grab the username? (ie: !signup tontow or !signup nova1313 )

strLine is returing the whole thing; "!signup tontow" returns "!signup tontow" and i just want the second word
Title: Re:VB 6 :Reconizeing a string that varies
Post by: effect on May 02, 2004, 11:54 PM
sCmd = Split(Mid(strLine, 2), " ")(0)
Title: Re:VB 6 :Reconizeing a string that varies
Post by: Stealth on May 03, 2004, 02:27 PM
Quote from: effect on May 02, 2004, 11:54 PM
sCmd = Split(Mid(strLine, 2), " ")(0)

Example:

sIn = "!signup bob"

Mid$(sIn, 2) = "signup bob"

Split(Mid$(sIn, 2), " ")(0) = "signup"
Split(Mid$(sIn, 2), " ")(1) = "bob"

Specifying the split index calling it is the same as Split()ting into an array and retrieving that index thereof.
Title: Re:VB 6 :Reconizeing a string that varies
Post by: Spht on May 03, 2004, 04:01 PM
The method I use feeds each spaced variable into p(), and variable and followed text into p_().

So with the command botnetmessage [vL] Spht[vL] protect on, for example, p(0) is botnetmessage, p(1) is [vL], p(2) is Spht[vL], and p_(3) is protect on.
Title: Re:VB 6 :Reconizeing a string that varies
Post by: Grok on May 03, 2004, 06:04 PM
Quote from: Spht on May 03, 2004, 04:01 PM
The method I use feeds each spaced variable into p(), and variable and followed text into p_().

So with the command botnetmessage [vL] Spht[vL] protect on, for example, p(0) is botnetmessage, p(1) is [vL], p(2) is Spht[vL], and p_(3) is protect on.

Sure that's what we all do in our full fledged bots, it's the easiest way VB allows.  This guy is just getting started though, so my goal was to educate him on a code structure that first parses the trigger, then parses a command and does something with it.

When he gets the hang of it, he can get into command recognition and parsing parameters.  For example, each different command will have its own unique number of parameters.  Some 2, 3, or even 4 or 5 parameters.  The third argument of your Split() function will vary depending on which command is called.