Results 1 to 7 of 7

Thread: Select Case usage

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    50

    Select Case usage

    Greetings,

    I built a form where a user enters an id and then a SQL statement is run using that id then populates a datagrid. In this case, I set up the connection to a production MS SQL db. However, I would like to add in 4 Select Case statments to point to differenty db's respectively. I have the code built to query the 4 other db's but I do not know how to code the radio buttons (Select Case) to point to a db when selected. I've never used Select Case functionality before so any help would be greatly appreciated.

    Thanks,
    J

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Select Case usage

    Quote Originally Posted by dolomite
    Greetings,

    I built a form where a user enters an id and then a SQL statement is run using that id then populates a datagrid. In this case, I set up the connection to a production MS SQL db. However, I would like to add in 4 Select Case statments to point to differenty db's respectively. I have the code built to query the 4 other db's but I do not know how to code the radio buttons (Select Case) to point to a db when selected. I've never used Select Case functionality before so any help would be greatly appreciated.

    Thanks,
    J
    Set up a control array of option buttons and then try this code:

    VB Code:
    1. Private Sub Option1_Click(Index As Integer)
    2.     Select Case Index
    3.         Case 0
    4.             ' Option Button 0 selected
    5.         Case 1
    6.             ' Option Button 1 selected
    7.         Case 2
    8.             ' Option Button 2 selected
    9.         Case 3
    10.             ' Option Button 3 selected
    11.     End Select
    12. End Sub
    Attached Files Attached Files
    Last edited by Mark Gambo; Aug 26th, 2005 at 12:07 PM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Select Case usage

    VB Code:
    1. select case dbbutton(index)
    2. case 0
    3.    sql statement for this db
    4. case 1
    5.    sql statement for this db
    6. case 2
    7.    sql statement for this db
    8. case else
    9.    sql statement for this db
    10. end select
    11. update your data control

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Select Case usage

    I realize this may be a picky point, but I'm going to make it anyway. It would actually be
    VB Code:
    1. Private Sub Option1_Click(Index As Integer)
    2.     Select Case Index
    3.         Case 0
    4.             ' Option Button 1 selected
    5.         Case 1
    6.             ' Option Button 2 selected
    7.         Case 2
    8.             ' Option Button 3 selected
    9.         Case 3
    10.             ' Option Button 4 selected
    11.     End Select
    12. End Sub

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    50

    Re: Select Case usage

    Great thanks guys!

    I was able to build this from your help

    Code:
        Select Case True
            Case optProd
                stConn = "ConnectString Persist Security Info=False;" & _
                         "Initial Catalog=vantive; Data Source=vanpsqlcluster;" & _
                         "Uid=foo;Pwd=foo"
            Case optdev1
                stConn = "ConnectString Persist Security Info=False;" & _
                         "Initial Catalog=vandev; Data Source=foo;" & _
                         "Uid=report;Pwd=report"
                         
            Case optdev2
                stConn = "ConnectString Persist Security Info=False;" & _
                         "Initial Catalog=vandev2; Data Source=foo;" & _
                         "Uid=report;Pwd=report"
                         
            Case optVanStage
                stConn = "ConnectString Persist Security Info=False;" & _
                         "Initial Catalog=vanstage; Data Source=foo;" & _
                         "Uid=report;Pwd=report"
            
            Case optVanTest
                stConn = "ConnectString Persist Security Info=False;" & _
                         "Initial Catalog=vantest; Data Source=foo;" & _
                         "Uid=report;Pwd=report"
        End Select
    Is there a way to set a default? I'd like to have optProd set to true by default.

    Thanks alot
    J

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Select Case usage

    Move it to the bottom of the list, and then change the CASE to CASE ELSE, and it wil be selected if nothing else matches.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Select Case usage

    Quote Originally Posted by dolomite
    Is there a way to set a default? I'd like to have optProd set to true by default.

    Thanks alot
    J
    VB Code:
    1. Private Sub Form_Load()
    2. optProd.Value = True
    3. End Sub

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