Valhalla Legends Forums Archive | Visual Basic Programming | Right(message, Len(message)

AuthorMessageTime
Yegg
I am having a problem with the following code:

[code]Right(message, Len(message) - 4)[/code]

For instance, (im using this code for commands) when i do something like:

[code]If LCase(username) = Master And LCase(Message) = Trigger & "say" Then
Send Right(message, Len(message) - 4)
End If[/code]

Of course i want the bot to send what the user says after Trigger & "say"
Im not sur y, but with this code, the bot wont do ne thing at all. Can ne1 help me?
October 30, 2004, 8:24 PM
Newby
[code]If LCase(Message) = Trigger & "say" Then[/code]

Message = ".say Hi!!!!!"
Trigger = '.'

<You> .say Hi!!!11

[code]LCase(Message) = Trigger & "say"[/code]
False.

Solution? Check to see if the first four characters == Trigger + "say"
October 30, 2004, 8:46 PM
Yegg
Could u hav made that ne more confusing?
October 30, 2004, 9:07 PM
UserLoser.
Your code:
[code]
If LCase(Message) = Trigger & "say" Then
[/code]

Let's use . as our trigger...

Your code will only work if a user types ".say" --  If someone types ".say Hello", well guess what,  ".say Hello" is not equal to ".say".  Becuase you're only checking for <trigger>say, nobody will ever be able to say anything from your bot.  So, what you should be doing is checking for something like:
[code]
If (Left$(LCase(Message), 4) = (Trigger & "say")) Then
[/code]
October 30, 2004, 9:29 PM
Grok
[quote author=Yegg link=topic=9365.msg86648#msg86648 date=1099167889]
Of course i want the bot to send what the user says after Trigger & "say"
Im not sur y, but with this code, the bot wont do ne thing at all. Can ne1 help me?
[/quote]


[code]Public Sub ProcessTalk(ByVal UserName As String, ByVal Msg As String)
   'check if message is a command (look for trigger)
   If Left(Msg,1) = "." And Instr(Msg, " ") > 1 Then
       bCmd = True
   End If
   'figure out which command it is ...
   If bCmd Then
       sCmd = Split(Msg," ")(0)
       If Len(sCmd) > 1 Then
       sCmd = UCase(Mid(sCmd,2))
       Select Case sCmd
       Case "SAY"
           eCmd = E_SAY
           sParms = Mid(Msg, 6)        'everything starting with 6th char are parameters
       Case "BAN"
           eCmd = E_BAN
           sParms = Mid(Msg, 6)        'everything starting with 6th char are parameters
       Case "KICK"
           eCmd = E_KICK
           sParms = Mid(Msg, 7)        'everything starting with 7th char are parameters
       Case Else  'etc
       End Select
   End If
[/code]

see how you incrementally break apart the message, first deciding if its a trigger, then if its a command, then what the parameters are?  it keeps it really simple to manage that way.  i'm sure there are other ways, but this is pretty easy to understand and code.
October 30, 2004, 9:36 PM
The-FooL
[quote author=Yegg link=topic=9365.msg86648#msg86648 date=1099167889]
I am having a problem with the following code:

[code]Right(message, Len(message) - 4)[/code]
[/quote]

[code]Mid$(Message,4)[/code]
October 30, 2004, 9:54 PM
Yegg
I now have:

[code]If LCase(username) = Master And(Left$(LCase(Message), 4) = (Trigger & "say")) Then
Send (im not sure wut goes here)
End If[/code]

and as u can see in the code, im not sure wut im supposed 2 send now.
October 30, 2004, 9:54 PM
HdxBmx27
[code]If LCase(username) = Master And(Left$(LCase(Message), 4) = (Trigger & "say")) Then
Send (im not sure wut goes here)
End If[/code]
Lets see if I can help you with this.

[code]I LCase(UserName) = Master And Left(Lcase(Message), 4) = Trigger & "say" then
    Send Mid(Message, 5) 'Length of ".say" + 1 for the fallowing space
end if[/code]

This IS NOT a good way to do this if you trying to make a commands parsing sub, but if its just one Thing then your fine i guess.
~-~(HDX)~-~
October 30, 2004, 10:12 PM
Newby
[quote author=Yegg link=topic=9365.msg86659#msg86659 date=1099173287]
I now have:

[code]If LCase(username) = Master And(Left$(LCase(Message), 4) = (Trigger & "say")) Then
Send (im not sure wut goes here)
End If[/code]

and as u can see in the code, im not sure wut im supposed 2 send now.

[/quote]
You were partially correct in what you were sending in the first post.

[code]Send (Right$(Message, Len(Message) - 5))[/code]
October 30, 2004, 10:30 PM
LivedKrad
[quote author=Yegg link=topic=9365.msg86659#msg86659 date=1099173287]
I now have:

[code]If LCase(username) = Master And(Left$(LCase(Message), 4) = (Trigger & "say")) Then
Send (im not sure wut goes here)
End If[/code]

and as u can see in the code, im not sure wut im supposed 2 send now.

[/quote]

Hmm, LCase(username) = Master? That will make Visual Basic treat it first as a String value, and then something other than a string. (I would just say a Variant). That shouldn't work at all for (I'm assuming) checking whether or not your user has the access of "Master". Try creating some function to check on a user's access, and then having it return a string with said access type.

[code]
Public Function chkAccess(username as String) As String
'perform some sort of check comparison to a user ("username") and their 'respective access, then..
If (access of)username = "Master" Then
chkAccess = "Master"
End Function


'after "TALK" event is fired...

Sub chkCommand(message as String, username as String)
If Left$(message, 1) = (Trigger var, in quotes) Then
    Select Case chkAccess(username)
          Case "Master"
              Select Case Mid$(message, 2, 3)
                    Case "say "  ' remember to include the space
                    Dim toSay as String
                    toSay = Mid$(message, 6)
                    'Additional 3 letter command conditionals for rank of "Master"
              Select Case 'additional n letter commands for "Master"
    Select Case 'Additional commands for rank of x
GoTo processor
End If

Else 'not a command!
  Exit Sub
End if

processor:
'Do operations
End Sub
[/code]
It should also be pretty fast considering it really doesn't do any Variant conversions and it does not continuing checking the entire statement for each message once a command is found.

Edit: BTW, I just wrote that as I did this post, so let me know if there are inconsistencies/errors.
October 31, 2004, 1:45 AM
HdxBmx27
Ok no offence to be ment but,  wouldn't it be easer to just check Mid(Split(Message & Space(1), Space(1))(0), 2)  the 1st word subtract the 1st chr (the trigger) of the message.
And then check the access in each case? (it would only end up checking the access once cuz its only gona fit 1 case)
Insted of checking the access, the making a hell of a lot of select cases?

Also I beleace the LCase(Username) = Master means that he has a string Var nasmed Master witch is a username that has complet access to the bot (maby he hasnt made an access/ranks system yet?)

Just an idea..
~-~(HDX)~-~
October 31, 2004, 4:36 AM
LivedKrad
[quote author=HdxBmx27 link=topic=9365.msg86729#msg86729 date=1099197385]
Ok no offence to be ment but  wouldnt it be easer to jsut check Mid(Split(Message &Space(1), Space(1))(0), 2)  the 1st word subtract the 1st chr (the trigger)
And then check the access in each case? (it would only end up checkinbg the access once cuz its only gona fit 1 case)
Insted of checking the access, the making a a hell aot of select cases?

Also I beleace the LCase(Username) = Master means that he has a string Var nasmed Master witch is a username that has complet access to the bot (maby he hasnt made an access/ranks system yet?)

Just an idea..
~-~(HDX)~-~
[/quote]

My entire reasoning for using Select Case was so that it would end the comparisons immediately when a truth statement was found. Would I not then, be processing commands by only rank? Notice that my first Select Case is to check for Master, if something other than Master is returned by chkAccess, it skips the entire collection of Case clauses underneath it. How would this be "a hell of a lot of select cases"? Secondly, I am aware that he was "attempting" to check access of "Master".  But, I see no implication that he meant Master was a variable referring to some other string that had access of "Master". It would not only be redundant, but bad policy. And, even if he has not made alternate ranks/access values, my method shows easily how to impliment other ranks into the chkCommand sub.
October 31, 2004, 4:46 AM
Dyndrilliac
Space() is not an array, it is a function that returns a string of spaces equal to the integer past to it.
October 31, 2004, 4:51 AM
LivedKrad
Notice, I modified my post. Somehow I misread it.
October 31, 2004, 4:51 AM
Dyndrilliac
[code]Private Type UserList
    UserName As String
    Access As Integer
    Flags As String
End Type

Private UL() As UserList

Private Sub LoadUsers()
    Dim Splt() As String, sInput As String, File As String, pfNum As Integer, I As Integer
   
    ReDim UL(0)
   
    pfNum = FreeFile
    File = App.Path & "\Users.txt"
    I = 0
   
    If Dir$(File) = vbNullString Then
        MsgBox "UserList could not be found!", vbCritical, "Error!"
        Exit Sub
    End If
   
    Open (File) For Input As #pfNum
        Do Until EOF(pfNum)
            Input #pfNum, sInput
            If sInput = vbNullString Then
                ReDim Preserve UL(0 To UBound(UL) - 1)
                Exit Sub
            End If
            Splt() = Split(sInput, ":", 2) '// Userlist syntax is "Username:Access:Flags"
            UL(I).UserName = Splt(0)
            UL(I).Access = CInt(Splt(1))
            UL(I).Flags = Splt(2)
            I = I + 1
            ReDim Preserve UL(0 To UBound(UL) + 1)
        Loop
    Close #pfNum
End Sub

Private Function GetAccess(ReqAccess As Integer, ReqFlag As String, UserName As String) As Boolean
    For I = 0 To UBound(UL)
        If LCase$(UserName) = LCase$(UL(I).UserName) Then
            Select Case True
                Case ReqAccess >= UL(I).Access
                    GetAccess = True
                Case InStr(UL(I).Flags, ReqFlag)
                    GetAccess = True
                Case InStr(UL(I).Flags, "M")
                    GetAccess = True
                Case Else
                    GetAccess = False
            End Select
        End If
    Next I
End Function

Public Sub CommandRecognition(UserName As String, Message As String)
    Dim Tmp As String
    Tmp = UserName
    UserName = Replace$(UserName, "*", vbNullString)
   
    If LCase$(varProduct) = "px2d" Or LCase$(varProduct) = "vd2d" Then
        If InStr(Tmp, "*") = 0 Then Tmp = "*" & UserName
    End If
   
    Dim tChar As String
    tChar = Left$(Message, 1)
    If Not tChar = varTrigger Then Exit Sub
    Dim CommandName As String
    Dim CommandCount() As String
    Dim Text() As String
    CommandCount() = Split(Message, "; ")
    For I = 0 To UBound(CommandCount)
        If CommandCount(I) = vbNullString Then GoTo ErrCommand
        CommandName = Split(CommandCount(I), vbNullString)(0)
        If CommandName = vbNullString Then GoTo ErrCommand
        If InStr(CommandName, varTrigger) <> 0 Then CommandName = Replace$(CommandName, varTrigger, vbNullString)
        Text() = Split(CommandCount(I), vbNullString, 2)
        Select Case LCase$(CommandName)
            Case "ver"
                If Not GetAccess(10, "I", UserName) = True Then GoTo ErrCommand
                AddQ "I'm a KickAssBot v1.0 Biatch!"
        End Select
ErrCommand:
    Next I
End Sub[/code]

1337! I was bored.
October 31, 2004, 6:07 AM
HdxBmx27
I was trying to suggest just one Select case.
My main reasoning is just that its alot cleaner to read and what if you want more then one access level to be able to use the same command? Making a select case of all your commands, and then haveing one "If MyAccess < ReqAccess then Exit Sub" Line for each command would be easier, but thats just my opinion, and I don't want to get into anything about it.
~-~(HDX)~-~
October 31, 2004, 7:29 AM
LivedKrad
I would think it would be rather impossible to incorporate all possible ranks into one If/Then or one Select Case/Case structure. Unless of course, you want each rank to have all of the same commands. You would have to direct flow to differing parts of the sub to test whether or not this access can use this command or this command or the next two, etc. How would you set up multiple flows without , incidentally, setting up multiple flows?
October 31, 2004, 4:43 PM
Yegg
:o, um i have my own way in which my bot reads a users access level. all i wanted to know wus a simple way in the bot reading wut is said after a certain message, like in my first post.

[code]Dim Master As String
Master = Form2.txtMaster.text
If LCase(username) = Master And LCase(Message) = Trigger & "say" Then
Send Right(message, Len(message) - 4)
End If[/code]

by using that exact code, it used 2 work for me. but for some odd reason 1 day it just stopped. I figured i must have done something wrong with it. i dont need a ton of help on check access or a million other things.

Edit:
........cant belive it wus so obvious, but i figured out wut i did wrong it works now, but ty for the help guys.
October 31, 2004, 4:53 PM

Search