Results 1 to 13 of 13

Thread: Select case wildcard?

  1. #1

    Thread Starter
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668

    Select case wildcard?

    I have a select case I want to be able to check certain expressions... ie:


    VB Code:
    1. Select Case Command
    2.    case "spawn "+x+":"+y
    3.         'do this
    4.    case "spawn "+x1+":"+y2+" "+x2+":"+y2"
    5.         'do that
    6. end select

    Any idea how I would go about doing that?
    If wishes were fishes we'd all cast nets.

  2. #2
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153
    I assume by wildcard you mean to catch anything that you don't have in your other case expressions. Use Else.

    eg

    VB Code:
    1. Select Case command
    2.    case "spawn "+x+":"+y
    3.         'do this
    4.    case "spawn "+x1+":"+y2+" "+x2+":"+y2"
    5.         'do that
    6.    case Else
    7.         'do something else
    8. end select

  3. #3

    Thread Starter
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    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.

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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:
    1. Dim strCommand As String = "Spawn this"
    2.         Select Case UCase(Microsoft.VisualBasic.Left(strCommand, 5))
    3.             Case "SPAWN"
    4.                 MessageBox.Show("Spawn")
    5.         End Select

    or with Option Compare set to Text,

    VB Code:
    1. Dim strCommand As String = "Spawn this"
    2.         Select Case Microsoft.VisualBasic.Left(strCommand, 5)
    3.             Case "SPAWN"
    4.                 MessageBox.Show("Spawn")
    5.         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.

  5. #5

    Thread Starter
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    "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.

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    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.

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  8. #8

    Thread Starter
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    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.

  9. #9

    Thread Starter
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    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:
    1. dim arrCommand() as string
    2. arrCommand = split(Command," ")
    3.  
    4. select case arrCommand(0)
    5.    case "%spawn"
    6.         if arrCommand(3) is nothing then
    7.             Spawn(arrCommand(2))
    8.         else
    9.              Spawn(arrCommand(2),arrCommand(3))
    10.         end if
    11.     'do other commands
    12. end select
    If wishes were fishes we'd all cast nets.

  10. #10
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  11. #11

    Thread Starter
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    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:
    1. Public Sub Spawn(Coord as String)
    2.     dim x,y as integer
    3.     'Some authentication goes here
    4.     'to make sure user has proper rights
    5.     'to request this command
    6.  
    7.     'Coord comes in as x:y
    8.     x = Coord.substring(1,1)
    9.     y = Coord.substring(3,1)
    10.  
    11.     'Send Message to game
    12.     ' SendMsg is a method that uses the postMessage api to communicate with the game
    13.     'ReplyTo is a global variable to the class and is defined elsewhere
    14.     SendMsg(":" + ReplyTo + ":*spawn " + x + "," + y)
    15. end sub
    16.  
    17. Public Sub Spawn(Coord1 as string, Coord2 as string)
    18.     dim x,y,x1,x2,y1,y2 as integer
    19.         'Some authentication goes here
    20.     'to make sure user has proper rights
    21.     'to request this command
    22.  
    23.     'Coord comes in as x:y
    24.     x1 = Coord1.substring(1,1)
    25.     y1 = Coord1.substring(3,1)
    26.    
    27.     x2 = Coord2.substring(1,1)
    28.     y2 = Coord2.substring(3,1)
    29.    
    30.     x = (x2 - x1 + 1) * Rnd() + x1
    31.     y = (y2 - y1 + 1) * Rnd() + y1
    32.     'Send Message to game
    33.     ' SendMsg is a method that uses the postMessage api to communicate with the game
    34.     'ReplyTo is a global variable to the class and is defined elsewhere
    35.     SendMsg(":" + ReplyTo + ":*spawn " + x + "," + y)
    36. 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.

  12. #12
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  13. #13

    Thread Starter
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    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
  •  



Click Here to Expand Forum to Full Width