Shoutbox

VB Help With /Commands - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Forum: Plug-Ins (/forumdisplay.php?fid=28)
+------ Thread: VB Help With /Commands (/showthread.php?tid=17723)

VB Help With /Commands by f3nd3r on 11-05-2003 at 06:22 PM

Hey,

How can I make something happen on a particular Command Argument?  Have a look at my code below. It may help you see what i'm trying to do. It doesnt work though.

Any help is much appreciated



code:
Public Function ParseCommand(ByVal sCommand As String, ByVal sCommandArg As String, ByVal oConversationWnd As Object, ByRef sResult As String) As Boolean
      If (StrComp(LCase(sCommand), "/xtest", vbTextCompare) = 0) & sCommandArg = "%test" Then
       
        MsgBox "Test"
       
        ParseCommand = True
        Exit Function
End Function


RE: VB Help With /Commands by Jutx on 11-05-2003 at 06:33 PM

I would use a nested if statement
the code below would display a message box if the user types /xtest hello

code:
Public Function ParseCommand(ByVal sCommand As String, ByVal sCommandArg As String, ByVal oConversationWnd As Object, ByRef sResult As String) As Boolean
      If (StrComp(LCase(sCommand), "/xtest", vbTextCompare) = 0) Then

If sCommandArg = "hello" then
       
        MsgBox "This Msgbox will be activated if user sends /xtest hello"
       
End if

        ParseCommand = True
        Exit Function
End Function

RE: VB Help With /Commands by f3nd3r on 11-05-2003 at 07:31 PM

Thats sweet dude. Thanks very much. That method didnt occur to me, yet its so obvious now I think about it.

Ok now my next problem is how do i get the sResult to display written text aswell as something a command has triggered...Look at the source below.

code:
Public Function ParseCommand(ByVal sCommand As String, ByVal sCommandArg As String, ByVal oConversationWnd As Object, ByRef sResult As String) As Boolean
      If (StrComp(LCase(sCommand), "/xtest", vbTextCompare) = 0) Then

If sCommandArg = "%hello" then
       
        sResult = "Hello"
       
End if
End if

        ParseCommand = True
        Exit Function
End Function


if someone types /xtest this is me saying %hello

How do i get sResult to display "this is me saying hello" ?
RE: VB Help With /Commands by Jutx on 11-05-2003 at 11:21 PM

I think i get what you mean you want sResult to display what the command argument said but with text added to it. Correct me if i am wrong.

code:
Public Function ParseCommand(ByVal sCommand As String, ByVal sCommandArg As String, ByVal oConversationWnd As Object, ByRef sResult As String) As Boolean
      If (StrComp(LCase(sCommand), "/xtest", vbTextCompare) = 0) Then

If sCommandArg = "%hello" then
       
        sResult = "You just said to this plug-in: " & Replace(sCommandArg,"%","")

       
End if
End if

        ParseCommand = True
        Exit Function
End Function

The Replace bit just gets rid of the percent. If you want it there you could just say:

sResult = "You just said to this plug-in: " & sCommandArg
RE: VB Help With /Commands by f3nd3r on 11-05-2003 at 11:40 PM

This is almost what im looking for, but not quite. I think %hello is a bad example. I will eventually be making it to show something like CPU speed...so i want to be able to make something like this
/xtest this is my CPU speed %cpu     but i want it so the user can type anything...for example /xtest hey, my spu speed is %cpu    or /xtest %cpu  ...thats my CPU speed.    So want i want is the %cpu to be able to be replaced anywhere in the message but keeping what the user is saying. I hope this makes sense


RE: VB Help With /Commands by Jutx on 11-06-2003 at 12:07 AM

Ah i think i understand what you mean so you would want to show CPU speed for example but in the format the user wants. Perhaps a tag is better than this instead of a command so instead of the user typing:

/xtest My Computer zooms at %cpu

The user would write:

My Computer Zooms at (!CPU)


(The code is pretty much the same except it is the ParseTag option that you want.) If you still would prefer it as a command then here is the code format you want.


EDIT: The code has been updated a bit

code:
Public Function ParseCommand(ByVal sCommand As String, ByVal sCommandArg As String, ByVal oConversationWnd As Object, ByRef sResult As String) As Boolean
      If (StrComp(LCase(sCommand), "/xtest", vbTextCompare) = 0) Then

If Instr(Lcase(sCommandArg), "%cpu") <> 0  then
       
Dim CPUSpeed As Long


' Type Code to get CPUSpeed
' then return the number of megahertz the CPU speed is (here the code will always say 1000 coz i don't know how to get CPU Speed)

CPUSpeed = 1000

        sResult = Replace(sCommandArg,"%cpu", CPUSpeed)

       
End if
End if

        ParseCommand = True
        Exit Function
End Function


RE: VB Help With /Commands by f3nd3r on 11-06-2003 at 12:44 PM

Ok, I chose to use the command code. Heres what I'm faced with now.  When i choose a variable such as:

   sResult = Replace(sCommandArg,"%cpu", CPUSpeed)

it will work if the user does /xtest %cpu   but it wont work if anything else is in the text..such as:

/xtest %cpu ...thats my CPU speed.

However, if it is a string, and not a variable, it will work fine with other text.. for example see below.

   sResult = Replace(sCommandArg,"%cpu", "cpu speed")

With that someone can type '/xtest look at my %cpu'  and it would result in MSN saying "look at my cpu speed"  instead of just returning nothing like the variable does.

So now i am left confused as to why it doesnt allow extra text if it is a variable, but it does if it is a string.

Any ideas?

I really appreciate your help Jutx


RE: VB Help With /Commands by Jutx on 11-06-2003 at 04:19 PM

Have you actually got code to get the CPU Speed? because the code i posted will not actually work "off the shelf"  for two reasons.

1) I did not declare the variable CPUSpeed
2) I did not put the actual code to get CPU Speed. (I don't know how)

I'll edit the code in my previous post and declare the variable


RE: VB Help With /Commands by f3nd3r on 11-06-2003 at 05:11 PM

Yea, i do have the CPU code because it works if i do just:
  /xtest %cpu

but if i add anything else to it like:
  /xtest %cpu ...thats my cpu speed

Then nothing happens


RE: VB Help With /Commands by Jutx on 11-06-2003 at 05:20 PM

I really cannot understand why it won't work then, everything seems to be fine, unless it is capitalisation.

If so just change:

        sResult = Replace(sCommandArg,"%cpu", CPUSpeed)

into

        sResult = Replace(lcase(sCommandArg),"%cpu", CPUSpeed)


RE: VB Help With /Commands by f3nd3r on 11-06-2003 at 05:38 PM

Thanks for the help once again.

I tried what you suggested and now it doesnt display anything when i type just the basic command /xtest %cpu

I dont understand why it only displays the variable on its own. Maybe i should start from scratch again.


RE: VB Help With /Commands by Hah on 11-06-2003 at 06:47 PM

Are you getting any errors at all? Try whipping the command into a module and call it from an exe with an error handler, it could be a type mismatch error with the long and the string:

try replacing:

CPUSPEED

with

CStr(CPUSPEED) or Str(CPUSPEED) etc.

might help,

Tom