|
-
Jun 1st, 2003, 11:25 PM
#1
Thread Starter
Hyperactive Member
Select Case
How can I use a select case in vb.net for 5 text boxes? did vb.net remove the control array option?
-
Jun 1st, 2003, 11:45 PM
#2
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.
-
Jun 2nd, 2003, 12:11 AM
#3
Thread Starter
Hyperactive Member
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...
-
Jun 2nd, 2003, 01:25 AM
#4
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.
-
Jun 2nd, 2003, 06:07 AM
#5
Thread Starter
Hyperactive Member
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...
-
Jun 2nd, 2003, 12:14 PM
#6
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
-
Jun 2nd, 2003, 12:19 PM
#7
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|