Results 1 to 5 of 5

Thread: [RESOLVED] Help With a Long Select Case : / (need to trim it down)

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    9

    [RESOLVED] Help With a Long Select Case : / (need to trim it down)

    I'm working on an online RPG and in one of my modules, I store code for the spellbar. This chunk of code controls the image that is displayed on the spellbar. The picture that is displayed depends on which spell is in which slot in their spell book. My problem is.. I have alot of spells in the game and 11 buttons on the spellbar. I have a huge select case block and its so long that the End Select doesn't recognize the Select Case (because they're so far away from each other...). I tried doing an array but the spellbar images were all the same. Here's a little bit of the code from this module:


    VB Code:
    1. For i = 1 To MAX_PLAYER_SPELLS
    2.             Player(MyIndex).Spell(i) = Val(Parse(i))
    3.             'If Player(MyIndex).Spell(i) <> 0 Then
    4.                 frmGame.lstSpells.AddItem i & ": " & Trim(Spell(Player(MyIndex).Spell(i)).name)
    5.                 Select Case Trim(Spell(Player(MyIndex).Spell(i)).name)
    6.                     Case "Fireball I"
    7.                         Select Case i
    8.                             Case 0: frmGame.lstSpells.AddItem "Empty spell slot."
    9.                             Case 1: frmGame.Picture11.Picture = frmGame.Fireball.Picture
    10.                             Case 2: frmGame.Picture13.Picture = frmGame.Fireball.Picture
    11.                             Case 3: frmGame.Picture15.Picture = frmGame.Fireball.Picture
    12.                             Case 4: frmGame.Picture16.Picture = frmGame.Fireball.Picture
    13.                             Case 5: frmGame.Picture17.Picture = frmGame.Fireball.Picture
    14.                             Case 6: frmGame.Picture18.Picture = frmGame.Fireball.Picture
    15.                             Case 7: frmGame.Picture19.Picture = frmGame.Fireball.Picture
    16.                             Case 8: frmGame.Picture20.Picture = frmGameFireball.Picture
    17.                             Case 9: frmGame.Picture21.Picture = frmGame.Fireball.Picture
    18.                             Case 10: frmGame.Picture22.Picture = frmGame.Fireball.Picture
    19.                             Case 11: frmGame.Picture23.Picture = frmGame.Fireball.Picture
    20.                         End Select
    21.                     Case "Raging Strike I"
    22.                         Select Case i
    23.                             Case 0: frmMirage.lstSpells.AddItem "Empty spell slot."
    24.                             Case 1: frmMirage.Picture11.Picture = frmGame.RagingStrike.Picture
    25.                             Case 2: frmGame.Picture13.Picture = frmGame.RagingStrike.Picture
    26.                             Case 3: frmGame.Picture15.Picture = frmGame.RagingStrike.Picture
    27.                             Case 4: frmGame.Picture16.Picture = frmGame.RagingStrike.Picture
    28.                             Case 5: frmGame.Picture17.Picture = frmGame.RagingStrike.Picture
    29.                             Case 6: frmGame.Picture18.Picture = frmGame.RagingStrike.Picture
    30.                             Case 7: frmGame.Picture19.Picture = frmGame.RagingStrike.Picture
    31.                             Case 8: frmGame.Picture20.Picture = frmGame.RagingStrike.Picture
    32.                             Case 9: frmGame.Picture21.Picture = frmGame.RagingStrike.Picture
    33.                             Case 10: frmGame.Picture22.Picture = frmGame.RagingStrike.Picture
    34.                             Case 11: frmGame.Picture23.Picture = frmGame.RagingStrike.Picture
    35.  
    36. ..................................................
    37.  
    38. ..................................................
    39.  
    40.                   End Select

    There's over 50 blocks like this..so you could see how the End Select after all this doesn't recognize the top. Someone help please.

    //Dulokz

    Note: Each number in the Case are the spellbar buttons (1-11 and 0 displays an empty button)
    Last edited by Dulokz; Apr 30th, 2006 at 04:55 PM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    9

    Re: Help With a Long Select Case : / (need to trim it down)

    Here's a screenshot of the last compiled game version when the spellbar worked. This was before I added more spells so the Select Case worked fine. :P Hope this helps. ><

    //Dulokz
    Attached Images Attached Images  

  3. #3
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Lightbulb Re: Help With a Long Select Case : / (need to trim it down)

    My suggestion would be to use a control array so that you can index the proper control. This could reduce your code to something like:
    VB Code:
    1. Select Case Trim(Spell(Player(MyIndex).Spell(i)).Name)
    2.   Case "Fireball I"
    3.     frmGame.picSpells(i).Picture = frmGame.Fireball.Picture
    4.   Case "Raging Strike I"
    5.     frmGame.picSpells(i).Picture = frmGame.Fireball.Picture
    6.   '...
    7. End Select
    In the code you posted, I don't see how "i" could ever have the value of zero; so the "Case 0" options could be eliminated. At the very least, it could be checked before the Select. However, if I'm not understanding correctly, you could still handle it rather easily like:
    VB Code:
    1. Select Case Trim(Spell(Player(MyIndex).Spell(i)).Name)
    2.   Case "Fireball I"
    3.     If i = 0 Then
    4.       'Do something special here.
    5.     Else
    6.       frmGame.picSpells(i).Picture = frmGame.Fireball.Picture
    7.     End If
    8.   Case "Raging Strike I"
    9.     If i = 0 Then
    10.       'Do something special here.
    11.     Else
    12.       frmGame.picSpells(i).Picture = frmGame.Fireball.Picture
    13.     End If
    14.   '...
    15. End Select
    If, however, none of this is an option for you, you could move each of the inner Select statements into a subroutine:
    VB Code:
    1. Select Case Trim(Spell(Player(MyIndex).Spell(i)).Name)
    2.   Case "Fireball I"
    3.     HandleFireball i
    4.   Case "Raging Strike I"
    5.     HandleRagingStrike i
    6.   '...
    7. End Select
    8.  
    9. '...
    10.  
    11. Private Sub HandleFireball(ByVal Index As Long)
    12.   Select Case i
    13.     Case 0: frmGame.lstSpells.AddItem "Empty spell slot."
    14.     Case 1: frmGame.Picture11.Picture = frmGame.Fireball.Picture
    15.     Case 2: frmGame.Picture13.Picture = frmGame.Fireball.Picture
    16.     Case 3: frmGame.Picture15.Picture = frmGame.Fireball.Picture
    17.     Case 4: frmGame.Picture16.Picture = frmGame.Fireball.Picture
    18.     Case 5: frmGame.Picture17.Picture = frmGame.Fireball.Picture
    19.     Case 6: frmGame.Picture18.Picture = frmGame.Fireball.Picture
    20.     Case 7: frmGame.Picture19.Picture = frmGame.Fireball.Picture
    21.     Case 8: frmGame.Picture20.Picture = frmGameFireball.Picture
    22.     Case 9: frmGame.Picture21.Picture = frmGame.Fireball.Picture
    23.     Case 10: frmGame.Picture22.Picture = frmGame.Fireball.Picture
    24.     Case 11: frmGame.Picture23.Picture = frmGame.Fireball.Picture
    25.   End Select
    26. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    9

    Re: Help With a Long Select Case : / (need to trim it down)

    You know just after I posted this I thought of moving it into a sub routine. It works fine now. I don't know why I didn't think of this before. I tried using a control array before and for some odd reason..the spellbar *worked* fine...but the images didn't display. I have 19 forms and 12 modules just clientside.. a little less in the server software code...I didn't feel like searching that much. ><

    Thanks for the help.

    //Dulokz
    Last edited by Dulokz; Apr 30th, 2006 at 04:41 PM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    9

    Re: Help With a Long Select Case : / (need to trim it down)

    Well..it seemed to be working but once again..when I added more spells I got errors. This time it says "Variable Not Defined" and points to the "Case i" in the new sub procedures. Everytime it points to a different one. Anyone know the cause of this?

    //Dulokz

    Edit: Nevermind I got it working. I had to dim i inside each sub again, and set it to the value of index. Thanks alot for the help!
    Last edited by Dulokz; Apr 30th, 2006 at 04:55 PM.

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