Results 1 to 7 of 7

Thread: Select Case

  1. #1

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    Select Case

    How can I use a select case in vb.net for 5 text boxes? did vb.net remove the control array option?

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What are you trying to do with the 5 textboxes? The syntax for a Select Case is the same. As for Control Arrays they are a bit different. Some controls have a seperate control to mimic the old control array or you can literally put them in an array. Usually there is a better, more .NET way to do it though.

  3. #3

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    control array

    since i dont know the .net way of a control array right now i am just using if then statements for each text box, not efficient. i rather use a select case for the text boxes using the index of each box...

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Usually the textboxes in a control array would perform a similar function. You can add controls to an array the same as any other values if you want or use a collection type.

    VB Code:
    1. Dim Ctrls() As TextBox={Textbox1,Textbox2,Textbox3,Textbox4}

    Although that might be what you are really looking for. What is it you are trying to do? Maybe we can help you find a more ".NET" way of doing it.

  5. #5

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    vb6 example

    here is an example from vb6. this is what i am trying to accomplish using .net

    -------------------------------------------------------------------
    txtTextbox(0).text = "username"
    txtTextbox(1).text = "first name"
    txtTextbox(2).text = "last name"

    dim x as integer

    for x = lbound(txtTextbox) to ubound(txtTextbox)
    txtTextbox.enable = false
    next x
    -------------------------------------------------------------------

    or a select case statement such as

    select case txtTextbox.index
    case index = 0
    case index = 1
    case index = 2
    end select

    rather than using if then statements...

    if txttextbox1.enable = true then
    txttextbox1.enable =false
    elseif txttextbox2.enable = true ten
    txttextbox2.enable = false
    end if...

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    txtTextbox(0).text = "username"
    txtTextbox(1).text = "first name"
    txtTextbox(2).text = "last name"

    dim x as integer

    for x = lbound(txtTextbox) to ubound(txtTextbox)
    txtTextbox.enable = false
    next x
    VB Code:
    1. txtUsername.Text = "username"
    2. txtFirstName.Text = "first name"
    3. txtLastName.Text = "last name"
    4.  
    5. Dim ctrls() As TextBox={txtUsername,txtFirstName,txtLastName}
    6. Dim txt As TextBox
    7.  
    8. For Each txt In ctrls
    9.    txt.Enable = false
    10. Next

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Also if you have the same eventhandler for each then you can check out the sender parameter to see which one is firing the event.

    VB Code:
    1. Private Sub TextBoxes_Click(ByVal sender As Object, ByVal e As EventArgs) Handles txtUsername.Click, txtFirstName.Click, txtLastname.click
    2.   Dim txt As TextBox=CType(sender,Textbox)
    3.   Select Case txt.Name
    4.     Case "txtUsername"
    5.  
    6.     Case "txtFirstname"
    7.  
    8.     Case "txtLastname"
    9.  
    10.   End Select
    11. 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