Need some VBS help

Posted by Sleaker on Tue 25 Mar 2003 09:03 AM — 13 posts, 41,755 views.

#0
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
Canada #1
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
Amended on Tue 25 Mar 2003 05:31 PM by Magnum
Australia Forum Administrator #2
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.
Amended on Wed 26 Mar 2003 12:42 AM by Nick Gammon
#3
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
#4
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.
Australia Forum Administrator #5
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."



#6
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.

Australia Forum Administrator #7
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?
#8
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.
Amended on Thu 27 Mar 2003 02:52 AM by Sleaker
Australia Forum Administrator #9
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.
Australia Forum Administrator #10
Try getting the latest VBscript DLL if you don't have it already.
#11
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.
Amended on Thu 27 Mar 2003 08:43 PM by Sleaker
Australia Forum Administrator #12
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.