|
-
Jul 18th, 2004, 10:52 PM
#1
Thread Starter
Fanatic Member
Select case wildcard?
I have a select case I want to be able to check certain expressions... ie:
VB Code:
Select Case Command
case "spawn "+x+":"+y
'do this
case "spawn "+x1+":"+y2+" "+x2+":"+y2"
'do that
end select
Any idea how I would go about doing that?
If wishes were fishes we'd all cast nets.
-
Jul 19th, 2004, 12:31 AM
#2
Addicted Member
I assume by wildcard you mean to catch anything that you don't have in your other case expressions. Use Else.
eg
VB Code:
Select Case command
case "spawn "+x+":"+y
'do this
case "spawn "+x1+":"+y2+" "+x2+":"+y2"
'do that
case Else
'do something else
end select
-
Jul 19th, 2004, 07:49 AM
#3
Thread Starter
Fanatic Member
Actally I was referring to the first two cases. In this situation I never know for sure what x, y, x1, y1, x2 and y2 may be
If wishes were fishes we'd all cast nets.
-
Jul 19th, 2004, 08:06 AM
#4
PowerPoster
Hi,
First of all, if you never know what any of those values are, then how do you expect to differentiate between them? If you want to treat x and y as anything and also treat x1, x2, y1 and y2 as anything, they will all be treated as the same.
What you are looking for is something like:
VB Code:
Dim strCommand As String = "Spawn this"
Select Case UCase(Microsoft.VisualBasic.Left(strCommand, 5))
Case "SPAWN"
MessageBox.Show("Spawn")
End Select
or with Option Compare set to Text,
VB Code:
Dim strCommand As String = "Spawn this"
Select Case Microsoft.VisualBasic.Left(strCommand, 5)
Case "SPAWN"
MessageBox.Show("Spawn")
End Select
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 19th, 2004, 08:12 AM
#5
Thread Starter
Fanatic Member
"if you never know what any of those values are, then how do you expect to differentiate between them? "
by their syantax, one gives absolute coordinates and one gives a range
You're solution probably won't work since theres going to be more than just the two commands so I might just switch to if/else
If wishes were fishes we'd all cast nets.
-
Jul 19th, 2004, 08:59 AM
#6
Frenzied Member
If their syntax differentiates them, you can check that. But as variable x a/o variable y (which is all you gave us), Taxes is right.
-
Jul 19th, 2004, 09:00 AM
#7
PowerPoster
Hi Graff
Getting information out of you is like extracting teeth.
How many commands are there going to be? If there are several then you need a different approach entirely.
Do you apply a different action depending upon the name of the command?
If so, perhaps you should set up a sub or function (which must be Public or Shared) with the same name as the command and then use the CallByName function (I LOVE that one ). If you do this in conjunction with overloading you have no need for Select Case or If....ElseIf routines.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 19th, 2004, 10:43 AM
#8
Thread Starter
Fanatic Member
I don't know how many commands there will be but there are already 6
BanList
BanList Count
HelpList
HelpList Count
Spawn x:y (where x and y are coordinates)
Spawn x1:y1 x2:y2
It comes from parsing a tab delimited log file that is structured as:
msgtype receiver sender msg
I would parse
2 Newbie1 Graff %spawn 23,40
And then I would spawn newbie1 at the specific coords if I got
2 Newbie1 Graff %spawn 0,0 30,30
it would spawn them randomly somewhere in that range
If wishes were fishes we'd all cast nets.
-
Jul 19th, 2004, 12:13 PM
#9
Thread Starter
Fanatic Member
How does the callbyname function work in this case, don't I need a control?
I just had a thought, if I the split function I may be able to do
VB Code:
dim arrCommand() as string
arrCommand = split(Command," ")
select case arrCommand(0)
case "%spawn"
if arrCommand(3) is nothing then
Spawn(arrCommand(2))
else
Spawn(arrCommand(2),arrCommand(3))
end if
'do other commands
end select
If wishes were fishes we'd all cast nets.
-
Jul 19th, 2004, 06:37 PM
#10
PowerPoster
Hi,
Just to clarify your last post, what it appears to me that you are doing is:
1. Put each separate word (or anything else delimited by a space) into one element of an array.
2. If array(0) = "%spawn" you then call a procedure named spawn, which is obviously overloaded, passing to it the required parameter(s).
You also seem to be using "spawn" as though it is a VB.NET function or command. What precisely do you mean by
"And then I would spawn newbie1 at the specific coords if I got"
I have previously assumed that you had procedures named "spawn", "banlist" and "helplist" etc which required parameters to be passed for x & y (denoting 2 coordinates)and that you then had similarly named procedures requiring parameters for x1,y1 x2,y2 (denoting 2 ranges).
Please confirm my understanding.
One last thought. You are talking about VB.NET here arn't you?
Last edited by taxes; Jul 19th, 2004 at 06:42 PM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 19th, 2004, 07:16 PM
#11
Thread Starter
Fanatic Member
Yes VB.Net
My program is a bot for a game which parses log files and then responds accordingly via predefined commands.
1. yes
2. yes
The spawn function does precisely this
VB Code:
Public Sub Spawn(Coord as String)
dim x,y as integer
'Some authentication goes here
'to make sure user has proper rights
'to request this command
'Coord comes in as x:y
x = Coord.substring(1,1)
y = Coord.substring(3,1)
'Send Message to game
' SendMsg is a method that uses the postMessage api to communicate with the game
'ReplyTo is a global variable to the class and is defined elsewhere
SendMsg(":" + ReplyTo + ":*spawn " + x + "," + y)
end sub
Public Sub Spawn(Coord1 as string, Coord2 as string)
dim x,y,x1,x2,y1,y2 as integer
'Some authentication goes here
'to make sure user has proper rights
'to request this command
'Coord comes in as x:y
x1 = Coord1.substring(1,1)
y1 = Coord1.substring(3,1)
x2 = Coord2.substring(1,1)
y2 = Coord2.substring(3,1)
x = (x2 - x1 + 1) * Rnd() + x1
y = (y2 - y1 + 1) * Rnd() + y1
'Send Message to game
' SendMsg is a method that uses the postMessage api to communicate with the game
'ReplyTo is a global variable to the class and is defined elsewhere
SendMsg(":" + ReplyTo + ":*spawn " + x + "," + y)
end sub
Not all commands require ranges, infact so far only the spawn one does which is why it was in the example and the others were not.
If wishes were fishes we'd all cast nets.
-
Jul 19th, 2004, 08:17 PM
#12
PowerPoster
HI,
OK. All is now clear.
In order to avoid a long Select Case or If.. Else If.... you will have to use the CallByName function.
e.g. put the name of the procedure to be called into a string, say strName
then use something like
if number of parameters>1 then
CallByName(strName)(param1, param2)
else
CallByName(strName)(param1)
End If
You will of course have to use dummy parameters in those procedures which do not require parameters.
All procedures will have to be Public.
Hope that is clear.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 19th, 2004, 09:13 PM
#13
Thread Starter
Fanatic Member
I'll give it a shot, thanks.
If wishes were fishes we'd all cast nets.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|