How can I use a select case in vb.net for 5 text boxes? did vb.net remove the control array option?
Printable View
How can I use a select case in vb.net for 5 text boxes? did vb.net remove the control array option?
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.
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...
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:
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.
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...
Quote:
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:
txtUsername.Text = "username" txtFirstName.Text = "first name" txtLastName.Text = "last name" Dim ctrls() As TextBox={txtUsername,txtFirstName,txtLastName} Dim txt As TextBox For Each txt In ctrls txt.Enable = false Next
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:
Private Sub TextBoxes_Click(ByVal sender As Object, ByVal e As EventArgs) Handles txtUsername.Click, txtFirstName.Click, txtLastname.click Dim txt As TextBox=CType(sender,Textbox) Select Case txt.Name Case "txtUsername" Case "txtFirstname" Case "txtLastname" End Select End Sub