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 ➜ More help for me Maybe?

More help for me Maybe?

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


Posted by Sleaker   (24 posts)  Bio
Date Sun 22 Sep 2002 12:45 AM (UTC)
Message
Heh, Nick I love you! Now can I get more help? please please :D

Okay, so I have my VBScript set a variable in the world for every contact it gets. the lines look like so:
OCLRDATA_NY [NY] - AT BlackAdde - 5 5 0 19.1 0.0 240 S

OCLRDATA_NY is the name, and everything after that is the data it contains.
Now I've got a bunch of different comboes and I want to go back through with my VBScript and find all the different OCLRDATA_XX comboes where XX is any 2 letters. Then when it pulls 1 up it will determine if the XX is uppercase or lowercase, then it will return true or false for being Up/lowercase. Then it parses the line and splits it up into all the diff parts which would be
[NY]
- AT BlackAdde -
5
5
0
19.1
0.0
240
and S

then passes these values to another Sub for processing :D
wow complicated huh? well you'll probly have questions about what exactly I'm trying to do. but first all I need to know how to do I Recall each variable in turn and see if the [XX] is uppercase or lower.
Top

Posted by Vaejor   (120 posts)  Bio
Date Reply #1 on Sun 22 Sep 2002 02:53 AM (UTC)
Message
Try to start with this. Let us know if you have any questions about it.

Note: I haven't tested this myself, just threw the code together.

'OCLRDATA_

'Variable Name:
'OCLRDATA_NY
'Variable Data:
'[NY] - AT BlackAdde - 5 5 0 19.1 0.0 240 S

Sub FindData
  Dim astrVarNames
  Dim strVarName
  Dim astrDataSplit
  
  astrVarNames = world.GetVariables
  For Each strVarName In astrVarNames
    If (Left(strVarName, 9) = "OCLRDATA_") Then
      If (CheckUpper(Right(strVarName, 2)) = True) Then
        astrDataSplit = regex_exec(world.GetVariable(strVarName), _
            "([[A-Z]+]) (\- AT [A-Za-z]+ \-) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([A-Z])")
        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)
      End If
    End If
  Next
  
End Sub

' Default to false
' If it's already uppercase, change to true
Function CheckUpper(ByStr strData)
  CheckUpper = False
  If (strData = UCase(strData)) Then CheckUpper = True
End Function

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
Top

Posted by Sleaker   (24 posts)  Bio
Date Reply #2 on Sun 22 Sep 2002 04:18 AM (UTC)
Message
Okay You are gonna hafta explain some of this too me as I'm not totally familiar with VBScript yet.
the Left(OCLRDATA_, 9) will check each variable in order and execute this Code for each one with the first 9 letters of OCLRDATA_ ...

But I don't get what this does:
For Each strVarName In astrVarNames
(\- AT [A-Za-z]+ \-) <-- Not all will be AT, some will be BC, GL, UN, FC, CC, RV, etc. but there will always be 2 letters there then a space and then the name of something.
the 2 letters indicate the Faction and the name is the unit name.. so they will be different.
and all those 0-9s should be able to go into the hundreds
and the last A-Z needs to have 4 of ehm but heh, and there can only be D, S, M, F, J, m

other than that I have absolutely no idea what it does.

If (strData = UCase(strData)) <--- you never defined the strData or set it to = something so I dunno why this is there.
I think it looks like
strData = astrDataSplit(0) would work.. but there are some problems with the regexp matching thingy..

thanks for giving me an idea! I'll try making something.
Top

Posted by Vaejor   (120 posts)  Bio
Date Reply #3 on Sun 22 Sep 2002 06:39 AM (UTC)
Message
Small problem in the 'CheckUpper' function, it should be:

' Default to false
' If it's already uppercase, change to true
Function CheckUpper(ByVal strData)
  CheckUpper = False
  If (strData = UCase(strData)) Then CheckUpper = True
End Function


1) The code:

Left(strVarName, 9)


will take the data in 'strVarName' and pull out the first 9 characters starting at the beginning(left side) of the string.

In this case, all the variables you are looking for should start with "OCLRDATA_", so you can test the first 9 characters to match this.

If the variable name starts with this, then it will continue processing, otherwise it will ignore it and continue into the next 'for each' loop and grab the next variable name.

In this way you will basically check the names for ALL your variables you currently have, but only use the ones that start with that specific code. You could also put additional checks in if needed, say checking to make sure the length of the variable name is 9 characters long.

2) For Each strVarName in astrVarNames
If you look in the functionality for Mushclient, world.GetVariables will return a list(array) of all the names of all the variables it currently has stored. I store this list into 'astrVarNames'(array, string, Variable Names).

This specific command is formatted as such:
For Each <variable> In <array>
<... process using variable>
Next

So it will store the first variable name into 'strVarName' on the first loop, then process what is between the 'for each' and 'next' statements. When it finds the 'next' statement, it will jump back to the 'for each' statement and pull the next variable name out of the list and store it into 'strVarName'. It will continue to do this until it runs out of information from the list that is stored in 'astrVarNames', or until it sees an 'Exit For' command(which I don't use, but it's available).

For additional infomation on the 'For Each ... Next' statement as well as other VBScript functionality, you can always use the reference at the following link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vbscripttoc.asp

The 'For Each ... Next' statement can be found under the Statements link on the table of contents.

3) (\- AT [A-Za-z]+ \-)
With only 1 instance of what you wanted to match, some minimal guessing has to be made, and I guessed that 'AT' was going to be the only data right there, although that was incorrect. For better first runs on creating regular expressions, it's good to have several extremely different examples to match against so that all possibilities can be found.

Here's probably how you want it if you just want to match against 2 capitalized letters:
(\- [A-Z]{2} [A-Za-z]+ \-)

This will match 2(the reason for the brackets around the number 2) capitalized letters.

Alternatively, if you know the list of possible double letters and want to only check for them, you could use(as an example with the data you gave so far):
(\- (?:AT|BC|GL|UN|FC|CC|RV) [A-Za-z]+ \-)

This will limit it to finding only one of those pairs of letters.

You'll notice the (?:<data>) format. I think it was mentioned already, but this will cause the regex not to remember this data as something that it should store and return as one of the values, even though it is between a pair of parenthesis. Normally everything between parenthesis is returned as one of the items that the regex pushes back to be used. It is useful when you need to use something that is only easily available using the parenthesis(in this case, the ability to put a list of items to pick from), but don't want to return it with the normal data.

For other examples of using regular expressions, and advanced techniques, there is a file that is installed with MushClient called "RegularExpressions.txt" under the "doc" subfolder from where you installed MushClient.

4) 0-9s should be able to go into the hundreds
The current code would allow it to take any amount of numbers and periods in them. You can restrict this further, but unless you really don't trust your data, I'd leave it like this for simplicity for now.

5) last A-Z needs to have 4; there can only be D, S, M, F, J, m
You can change it from
([A-Z])

to:
([DSMFJm]{4})


This requires 4 characters, but they can only be what's between the square brackets.

If you want to change this so it will allow anywheres from 1 to 4 characters, it would look like this:
([DSMFJm]{1,4})

But would still be limited to the characters between the brackets.

6) you never defined the strData
strData is defined in the Function line as follows:
Function CheckUpper(ByStr strData)


So when you call CheckUpper(<data>), whatever <data> is will be stored into 'strData'.

The following line:
If (strData = UCase(strData)) Then

basically compares the exact string you sent through against the same sting that has had all of its letters forced to be capitlized. If the letters in 'strData' are already capitalized, then forcing them to be capitlized won't change it, so they'll match. If any letters in strData are lower case, then it will change from a lower case letter to an upper case letter and they won't match anymore.


-----

I think that covers most of the questions so far.

Good luck. :)
Top

Posted by Vaejor   (120 posts)  Bio
Date Reply #4 on Sun 22 Sep 2002 06:45 AM (UTC)
Message
Also, here's a correction for the 'CheckUpper' function:

' Default to false
' If it's already uppercase, change to true
Function CheckUpper(ByVal strData)
  CheckUpper = False
  If (strData = UCase(strData)) Then CheckUpper = True
End Function

The first line, I changed 'ByStr' to 'ByVal'.

Neither is actually needed(actually, ByStr isn't even a real keyword in VBScript), but that would leave the VBScript interpreter to do what it felt was right, which might disagree with what I think is right, so I force it to do what I know my code will like.

Sorry about that.
Top

Posted by Sleaker   (24 posts)  Bio
Date Reply #5 on Sun 22 Sep 2002 08:33 PM (UTC)
Message
Okay, well
World.GetVariables is not a valid Function, what is though is World.GetVariableList which grabs a list of all the variables. Which works, I think...
Now my major question is. I want to use the variables you have defined in the OtherProcess line so I can print them to the screen.
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.


20,061 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.