Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ VBscript ➜ Need some VBS help

Need some VBS help

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Sleaker   (24 posts)  Bio
Date Tue 25 Mar 2003 09:03 AM (UTC)
Message
Okay, I have my script execute this Subroutine on a command.

Sub OCLR()
Dim astrVarNames
Dim strVarName
Dim astrDataSplit
world.note "Contact Information"
astrVarNames = world.GetVariableList
For Each strVarName In astrVarNames
If (Left(strVarName, 9) = "OCLRDATA_") Then
astrDataSplit = regex_exec(world.GetVariable(strVarName), "([[A-Za-z]+]) (\- [A-Z]{2} [A-Za-z]+ \-) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([SDFJMm]{0,4})")
OtherProcessSub astrDataSplit(0), astrDataSplit(1), CSng(astrDataSplit(2)), CSng(astrDataSplit(3)), CSng(astrDataSplit(4)), CSng(astrDataSplit(5)), CSng(astrDataSplit(6)), CSng(astrDataSplit(7)), astrDataSplit(8)
World.note "[" & astrDataSplit(0) & "] - " & astrDataSplit(1) & " - x: " & astrDataSplit(2) & " y: " & astrDataSplit(3) & " z: " & astrDataSplit(4) & " Range: " & astrDataSplit(5) & " Speed: " & astrDataSplit(6) & " Head: " & astrDataSplit(7) & " Status: " & astrDataSplit(8)
End If
Next

End Sub

it parses lines of saved Variables in mushclient. but for some reason it is only displaying "Contact Information" and not any of the saved data.. here are some example lines of data that i have:

[CW] - SR Shrike - 5 5 0 3.8 0.0 0 S
[fd] - SR Stinger - 5 5 0 3.8 0.0 0 S
[JH] - DO Mammoth - 177 238 1 24.4 0.0 240
[YG] - SS Mammoth - 131 216 0 26.3 0.0 240
Top

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #1 on Tue 25 Mar 2003 05:26 PM (UTC)

Amended on Tue 25 Mar 2003 05:31 PM (UTC) by Magnum

Message
I'm just gonna repost that with formatting. Sorry, no time to look into it now.

Sub OCLR()
  Dim astrVarNames
  Dim strVarName
  Dim astrDataSplit
  world.note "Contact Information"
  astrVarNames = world.GetVariableList
  For Each strVarName In astrVarNames
    If (Left(strVarName, 9) = "OCLRDATA_") Then
      astrDataSplit = regex_exec(world.GetVariable(strVarName), "([[A-Za-z]+]) (\- [A-Z]{2} [A-Za-z]+ \-)" & _
        " ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([SDFJMm]{0,4})")
      OtherProcessSub astrDataSplit(0), astrDataSplit(1), CSng(astrDataSplit(2)), CSng(astrDataSplit(3)), _
        CSng(astrDataSplit(4)), CSng(astrDataSplit(5)), CSng(astrDataSplit(6)), _
        CSng(astrDataSplit(7)), astrDataSplit(8)
      World.note "[" & astrDataSplit(0) & "] - " & astrDataSplit(1) & " - x: " & astrDataSplit(2) & _
        " y: " & astrDataSplit(3) & " z: " & astrDataSplit(4) & " Range: " & astrDataSplit(5) & " Speed: " & astrDataSplit(6) & _
        " Head: " & astrDataSplit(7) & " Status: " & astrDataSplit(8)
    End If
  Next
End Sub

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #2 on Wed 26 Mar 2003 12:39 AM (UTC)

Amended on Wed 26 Mar 2003 12:42 AM (UTC) by Nick Gammon

Message
Can you show us the relevant variables? Select them in the variables configuration window, click the Copy button and paste the results here.

You would have to do that one at a time. Otherwise edit the world file, find the <variables> section and copy the relevant lines.

Or, more easily, when editing the variables in the configuration window, click the "save" button - that will save the lot to a text file. Edit that, and copy and paste the <variable name="blah> lines into your message.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Sleaker   (24 posts)  Bio
Date Reply #3 on Wed 26 Mar 2003 01:32 AM (UTC)
Message
Quote: "Can you show us the relevant variables? Select them in the variables configuration window, click the Copy button and paste the results here."

That's EXACTLY what I did. Those lines of data I gave are the variables I just forgot the variable names mebe I should post thost :D
Top

Posted by Sleaker   (24 posts)  Bio
Date Reply #4 on Wed 26 Mar 2003 01:33 AM (UTC)
Message
OCLRDATA_CW = [CW] - SR Shrike - 5 5 0 3.8 0.0 0 S
OCLRDATA_fd = [fd] - SR Stinger - 5 5 0 3.8 0.0 0 S
OCLRDATA_JH = [JH] - DO Mammoth - 177 238 1 24.4 0.0 240
OCLRDATA_YG = [YG] - SS Mammoth - 131 216 0 26.3 0.0 240

OCLRDATA_xx is the variable name, everything after the = is what it contains.. I have like over 30 of these so I only selected a few.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #5 on Wed 26 Mar 2003 05:52 AM (UTC)
Message
Well, it isn't *exactly* what you did, because if you had we would see something like this:

<variable name="OCLRDATA_CW">[CW] - SR Shrike - 5 5 0 3.8 0.0 0 S</variable>

However, leaving that aside, I would be interested to see what the array of variables returned.

Perhaps put into your loop a couple of displays, like this:


For Each strVarName In astrVarNames
   
    world.note "Got variable: " & strVarName

    If (Left(strVarName, 9) = "OCLRDATA_") Then

    world.note "Variable prefix matched."




- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Sleaker   (24 posts)  Bio
Date Reply #6 on Wed 26 Mar 2003 10:59 AM (UTC)
Message
Okay when I put in that line it only displays stuff in lowercase..

Got variable: oclrdata_jv
Got variable: oclrdata_jw
Got variable: oclrdata_jx


so I decided to try a few things I tried using UCase(Left(strVarName, 9)) and that just spit out an error in a completely unrelated part of the script.. which is confusing, and then I tried making OCLRDATA_ into oclrdata_ and that did the same thing

I figured it'd probly pop the same error message but it's wierd it's giving me an error in a Subroutine that isn't even called by either of the subroutines I'm using.

Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #7 on Wed 26 Mar 2003 07:48 PM (UTC)
Message
Taking your script that used to work (apart from the lack of displays) and changing the string literal to lower case certainly should not introduce errors elsewhere. Are you sure you didn't accidentally change something else?

What was the error message?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Sleaker   (24 posts)  Bio
Date Reply #8 on Thu 27 Mar 2003 02:51 AM (UTC)

Amended on Thu 27 Mar 2003 02:52 AM (UTC) by Sleaker

Message
Error number: -2146828283

Event: Execution of line 2111 column 3

Description: Invalid procedure call or argument
Line in error:

Called by: Immediate execution

the error is inside just a bunch of Cases...
This is basically all it contains:

Function ClassifyWeapon(WeaponName)
Select Case WeaponName
Case "CoolantGun"
ClassifyWeapon = "CG"
Case "AcidThrower"
ClassifyWeapon = "AT"
Case "SmallLaser"
ClassifyWeapon = "SL"
End Select
End Function

There are a bunch more Cases but I dont wanna post ehm all cause it'd be really long.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #9 on Thu 27 Mar 2003 03:52 AM (UTC)
Message
That is weird. I can't really help with that. Your original problem was that the word you were matching on should be in lower case, however why VBscript won't accept that I can't say.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #10 on Thu 27 Mar 2003 03:54 AM (UTC)
Message
Try getting the latest VBscript DLL if you don't have it already.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Sleaker   (24 posts)  Bio
Date Reply #11 on Thu 27 Mar 2003 10:10 AM (UTC)

Amended on Thu 27 Mar 2003 08:43 PM (UTC) by Sleaker

Message
Okay It IS going into the if statement, and it is displaying Variable prefix matched but then it pumps out the error when it attempts to set the variable equal to the regex_exec.. which does this:

Function regex_exec(ByVal strMatch, ByVal strRegex)
Dim regEx, Matches, Match

Set regEx = New RegExp
regEx.Pattern = strMatch
Set Matches = regEx.Execute(strRegex)
Set Match = Matches(0)

Set regEx = Nothing
Set Matches = Nothing

Set regex_exec = Match.SubMatches

Set Match = Nothing

Set strMatch = Nothing
Set strRegex = Nothing
End Function

any new ideas? I kinda didn't write half of this script so it's kidna hard for me to figure out what it all does sometimes.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #12 on Fri 28 Mar 2003 09:18 PM (UTC)
Message
I think you have the arguments around backwards.

Quote:

Set regEx = New RegExp
regEx.Pattern = strMatch
Set Matches = regEx.Execute(strRegex)


The "pattern" is the regular expression, and you execute against a string to match, however you are doing it the other way around.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


31,400 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.