Results 1 to 6 of 6

Thread: Simpler Select Case maintenance for long list of cases

  1. #1

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    Simpler Select Case maintenance for long list of cases

    Took me way too long to think of this.

    Remember that game engine I've been writing? Well it's come a long way since last time I posted anything about it.

    But one of the things is long lists of Select Case statements that I keep editing - mostly adding to.

    So instead of going from lowest number to highest, do just the opposite.

    Now everything I need is at the top of the procedure instead of the bottom.


    Code:
    ' Declarations.
    
    Private Const NON_CONSECUTIVE_RANDOM_MULTIPLIER As Double = 0.75
    
    
    Public Property Get GotBuffed() As String
    Const MAX_CHOICE As Long = 17
    Static nRecentChoice(1 To MAX_CHOICE * NON_CONSECUTIVE_RANDOM_MULTIPLIER) As Long
    Dim nChoice As Long
    
    nChoice = SelectNonConsecutiveRandomChoice(MAX_CHOICE, nRecentChoice)
    
    Select Case nChoice
    
      Case 17
    
        GotBuffed = "It's dangerous to go alone.  Take this."
    
      Case 16
    
        GotBuffed = "You've been hitting the gym!"
    
      Case 15
    
        GotBuffed = "Great job on those TPS reports!"
    
      Case 14
    
        GotBuffed = "You found the perfect balance between exploiting labor and resources for profit while selling the public an image of 'Corporate Responsibility'."
    
      Case 13
    
        ' Etc.
    
    End Select
    
    End Property
    
    Public Function SelectNonConsecutiveRandomChoice(ByRef NumChoices As Long, ByRef RecentChoices() As Long) As Long
    Dim nRnd As Long
    Dim n As Long
    Dim s() As String
    
    Do
    
      nRnd = RollDie(NumChoices)
    
    Loop While ArrayItemExistsLong(nRnd, RecentChoices)
    
    ReDim s(LBound(RecentChoices) To UBound(RecentChoices))
    
    For n = UBound(RecentChoices) To LBound(RecentChoices) + 1 Step -1
    
      RecentChoices(n) = RecentChoices(n - 1)
    
      s(n) = CStr(RecentChoices(n))
    
    Next n
    
    RecentChoices(LBound(RecentChoices)) = nRnd
    
    s(LBound(RecentChoices)) = CStr(nRnd)
    
    AddPlayerMessage vbCrLf & "Recent Choices: " & Join(s, ","), 0, True
    
    SelectNonConsecutiveRandomChoice = nRnd
    
    End Function

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Simpler Select Case maintenance for long list of cases

    Feel like something like an array would be better...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    Re: Simpler Select Case maintenance for long list of cases

    Well, both approaches are "wrong" because it's really just resource data in this case an doesn't belong in the exe at all.

    The content wasn't the point though.

    It's just that over the years I've added a lot of things to existing select case blocks and never thought to do it this way. Have always had to scroll to the bottom to add a new thing.

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Simpler Select Case maintenance for long list of cases

    Quote Originally Posted by techgnome View Post
    Feel like something like an array would be better...

    -tg
    A Dictionary is the best abstraction here.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: Simpler Select Case maintenance for long list of cases

    Quote Originally Posted by Niya View Post
    A Dictionary is the best abstraction here.
    Yep - initially filled from a matching Resorces-DB-Table at App-Startup.

    A disconnected Recordset would be another nice container-alternative to an Array -
    (no datacopying-loop into a Dictionary necessary, ... a Delete-Method id available on Rs as well).

    Olaf

  6. #6
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Simpler Select Case maintenance for long list of cases

    I like that idea. A Recordset is even better in cases where you may want more fields than just a key/value pair.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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