![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a form that has a cluster of 9 textboxes that are named txtMatrix1_0, txtMatrix1_1, txtMatrix1_2 ... txtMatrix1_8 I want to loop through those nine textboxes, convert their values from string to byte, and then assign the value of each textbox to an array. The code could be something like the following without using a loop: dim arMatrix(8) as Byte arMatrix1(0) = CByte(txtMatrix1_0.text) arMatrix1(1) = CByte(txtMatrix1_1.text) ... arMatrix1(8) = CByte(txtMatrix1_8.text) But is there a way to do this in a for loop? Something like the following: dim X as integer dim ctl as new control for x = 0 to 8 ctl.name = "me.txtMatrix1_" + CStr(x) ctl.text = CByte(ctl.text) arMatrix1(x) = CByte(str.text) Next x I'm using the Option Strict On line so I have to convert my data types properly. I'm sure I'm doing this completely wrong and it's really driving me nuts. Appreciate any input. |
#3
| |||
| |||
|
|
Here's an example of how to loop through all the controls on a form. You have to do this recursively in case you have (for example) panels with controls in them, or option groups, or something like that. This example adds event handlers to all the textboxes and comboboxes so when the user tabs into them, or tabs out of them, it handles the event. (I'm backcoloring the entry in my event handlers). Private Sub AddEventHandlers(ByVal ctrlContainer As Control) For Each ctrl As Control In ctrlContainer.Controls If TypeOf ctrl Is TextBox _ OrElse TypeOf ctrl Is ComboBox Then AddHandler ctrl.Enter, AddressOf ProcessEnter AddHandler ctrl.Leave, AddressOf ProcessLeave End If 'If control has children, call this function recursively If ctrl.HasChildren Then AddEventHandlers(ctrl) End If Next End Sub Instead of adding event handlers, you can check the tag or name or whatever and do what you're trying to do. Hope this helps. RobinS. GoldMail, Inc. ------------------------------------- "Jonathan Brown" <JonathanBrown (AT) discussions (DOT) microsoft.com> wrote in message news:AF42C5B8-A50C-4BB0-BDD8-46EFF39478EE (AT) microsoft (DOT) com... I have a form that has a cluster of 9 textboxes that are named txtMatrix1_0, txtMatrix1_1, txtMatrix1_2 ... txtMatrix1_8 I want to loop through those nine textboxes, convert their values from string to byte, and then assign the value of each textbox to an array. The code could be something like the following without using a loop: dim arMatrix(8) as Byte arMatrix1(0) = CByte(txtMatrix1_0.text) arMatrix1(1) = CByte(txtMatrix1_1.text) ... arMatrix1(8) = CByte(txtMatrix1_8.text) But is there a way to do this in a for loop? Something like the following: dim X as integer dim ctl as new control for x = 0 to 8 ctl.name = "me.txtMatrix1_" + CStr(x) ctl.text = CByte(ctl.text) arMatrix1(x) = CByte(str.text) Next x I'm using the Option Strict On line so I have to convert my data types properly. I'm sure I'm doing this completely wrong and it's really driving me nuts. Appreciate any input. |
#4
| |||
| |||
|
|
Here's an example of how to loop through all the controls on a form. You have to do this recursively in case you have (for example) panels with controls in them, or option groups, or something like that. This example adds event handlers to all the textboxes and comboboxes so when the user tabs into them, or tabs out of them, it handles the event. (I'm backcoloring the entry in my event handlers). Private Sub AddEventHandlers(ByVal ctrlContainer As Control) For Each ctrl As Control In ctrlContainer.Controls If TypeOf ctrl Is TextBox _ OrElse TypeOf ctrl Is ComboBox Then AddHandler ctrl.Enter, AddressOf ProcessEnter AddHandler ctrl.Leave, AddressOf ProcessLeave End If 'If control has children, call this function recursively If ctrl.HasChildren Then AddEventHandlers(ctrl) End If Next End Sub Instead of adding event handlers, you can check the tag or name or whatever and do what you're trying to do. Hope this helps. RobinS. GoldMail, Inc. ------------------------------------- "Jonathan Brown" <JonathanBrown (AT) discussions (DOT) microsoft.com> wrote in message news:AF42C5B8-A50C-4BB0-BDD8-46EFF39478EE (AT) microsoft (DOT) com... I have a form that has a cluster of 9 textboxes that are named txtMatrix1_0, txtMatrix1_1, txtMatrix1_2 ... txtMatrix1_8 I want to loop through those nine textboxes, convert their values from string to byte, and then assign the value of each textbox to an array. The code could be something like the following without using a loop: dim arMatrix(8) as Byte arMatrix1(0) = CByte(txtMatrix1_0.text) arMatrix1(1) = CByte(txtMatrix1_1.text) ... arMatrix1(8) = CByte(txtMatrix1_8.text) But is there a way to do this in a for loop? Something like the following: dim X as integer dim ctl as new control for x = 0 to 8 ctl.name = "me.txtMatrix1_" + CStr(x) ctl.text = CByte(ctl.text) arMatrix1(x) = CByte(str.text) Next x I'm using the Option Strict On line so I have to convert my data types properly. I'm sure I'm doing this completely wrong and it's really driving me nuts. Appreciate any input. |
#5
| |||
| |||
|
|
I have a form that has a cluster of 9 textboxes that are named txtMatrix1_0, txtMatrix1_1, txtMatrix1_2 ... txtMatrix1_8 I want to loop through those nine textboxes, convert their values from string to byte, and then assign the value of each textbox to an array. The code could be something like the following without using a loop: dim arMatrix(8) as Byte arMatrix1(0) = CByte(txtMatrix1_0.text) arMatrix1(1) = CByte(txtMatrix1_1.text) ... arMatrix1(8) = CByte(txtMatrix1_8.text) But is there a way to do this in a for loop? Something like the following: dim X as integer dim ctl as new control for x = 0 to 8 ctl.name = "me.txtMatrix1_" + CStr(x) ctl.text = CByte(ctl.text) arMatrix1(x) = CByte(str.text) Next x I'm using the Option Strict On line so I have to convert my data types properly. I'm sure I'm doing this completely wrong and it's really driving me nuts. Appreciate any input. |
#6
| |||
| |||
|
|
So I can't specify which controls on a form to loop through? I couldn't use say, the first part of the controls' names and then append a variable string at the end to specify a specific control? I have to loop through all of the controls on a form given their type. "RobinS" wrote: Here's an example of how to loop through all the controls on a form. You have to do this recursively in case you have (for example) panels with controls in them, or option groups, or something like that. This example adds event handlers to all the textboxes and comboboxes so when the user tabs into them, or tabs out of them, it handles the event. (I'm backcoloring the entry in my event handlers). Private Sub AddEventHandlers(ByVal ctrlContainer As Control) For Each ctrl As Control In ctrlContainer.Controls If TypeOf ctrl Is TextBox _ OrElse TypeOf ctrl Is ComboBox Then AddHandler ctrl.Enter, AddressOf ProcessEnter AddHandler ctrl.Leave, AddressOf ProcessLeave End If 'If control has children, call this function recursively If ctrl.HasChildren Then AddEventHandlers(ctrl) End If Next End Sub Instead of adding event handlers, you can check the tag or name or whatever and do what you're trying to do. Hope this helps. RobinS. GoldMail, Inc. ------------------------------------- "Jonathan Brown" <JonathanBrown (AT) discussions (DOT) microsoft.com> wrote in message news:AF42C5B8-A50C-4BB0-BDD8-46EFF39478EE (AT) microsoft (DOT) com... I have a form that has a cluster of 9 textboxes that are named txtMatrix1_0, txtMatrix1_1, txtMatrix1_2 ... txtMatrix1_8 I want to loop through those nine textboxes, convert their values from string to byte, and then assign the value of each textbox to an array. The code could be something like the following without using a loop: dim arMatrix(8) as Byte arMatrix1(0) = CByte(txtMatrix1_0.text) arMatrix1(1) = CByte(txtMatrix1_1.text) ... arMatrix1(8) = CByte(txtMatrix1_8.text) But is there a way to do this in a for loop? Something like the following: dim X as integer dim ctl as new control for x = 0 to 8 ctl.name = "me.txtMatrix1_" + CStr(x) ctl.text = CByte(ctl.text) arMatrix1(x) = CByte(str.text) Next x I'm using the Option Strict On line so I have to convert my data types properly. I'm sure I'm doing this completely wrong and it's really driving me nuts. Appreciate any input. |
#7
| |||
| |||
|
|
What does it mean, if control has children? (try to keep the answer as clean as possible) ![]() "RobinS" wrote: Here's an example of how to loop through all the controls on a form. You have to do this recursively in case you have (for example) panels with controls in them, or option groups, or something like that. This example adds event handlers to all the textboxes and comboboxes so when the user tabs into them, or tabs out of them, it handles the event. (I'm backcoloring the entry in my event handlers). Private Sub AddEventHandlers(ByVal ctrlContainer As Control) For Each ctrl As Control In ctrlContainer.Controls If TypeOf ctrl Is TextBox _ OrElse TypeOf ctrl Is ComboBox Then AddHandler ctrl.Enter, AddressOf ProcessEnter AddHandler ctrl.Leave, AddressOf ProcessLeave End If 'If control has children, call this function recursively If ctrl.HasChildren Then AddEventHandlers(ctrl) End If Next End Sub Instead of adding event handlers, you can check the tag or name or whatever and do what you're trying to do. Hope this helps. RobinS. GoldMail, Inc. ------------------------------------- "Jonathan Brown" <JonathanBrown (AT) discussions (DOT) microsoft.com> wrote in message news:AF42C5B8-A50C-4BB0-BDD8-46EFF39478EE (AT) microsoft (DOT) com... I have a form that has a cluster of 9 textboxes that are named txtMatrix1_0, txtMatrix1_1, txtMatrix1_2 ... txtMatrix1_8 I want to loop through those nine textboxes, convert their values from string to byte, and then assign the value of each textbox to an array. The code could be something like the following without using a loop: dim arMatrix(8) as Byte arMatrix1(0) = CByte(txtMatrix1_0.text) arMatrix1(1) = CByte(txtMatrix1_1.text) ... arMatrix1(8) = CByte(txtMatrix1_8.text) But is there a way to do this in a for loop? Something like the following: dim X as integer dim ctl as new control for x = 0 to 8 ctl.name = "me.txtMatrix1_" + CStr(x) ctl.text = CByte(ctl.text) arMatrix1(x) = CByte(str.text) Next x I'm using the Option Strict On line so I have to convert my data types properly. I'm sure I'm doing this completely wrong and it's really driving me nuts. Appreciate any input. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |