|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Newbie Question 2, Reference To Controls On A FormIn other high level languages I've played with, there were functions that let you build commands or lines of code. For instance, you could assemble a string variable, and convert it to a line of code, then execute the line of code. That would be one way to do what I want. Something like (in English), Set CommandVariable equal to String1 & String2 & String3 Execute CommandVariable This would make it simple for me to step through an array and assign my bytes to a series of sequentially numbered textboxes in a form. I could do a loop and change the value of one part of it. I've waded into the discussions about control arrays that don't work anymore, and I got mired in quicksand. Do I have to create classes and all that just to transfer information to textboxes without having to type out each one by name in the code? I'd rather use a for / next loop ...... This would be nice if it worked, :) (I've placed some text boxes on my form and named them Txtbx0, Txtbx1, etc.) For I = 0 to 4 Form1.Txtbx(I).Text = MyArray(I) Next Thanks for helping the newbie, --NinerSevenTango-- 97T,
If I understand what you are trying to do, it seems that you are trying to add controls at runtime. If thats right then, this article should be able to give you some direction. Let me know if thats not what you were trying to do. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolslistitemcollectionclassremovetopic.asp Jeff "Jeff" <jeffmag***@gmail.com> wrote in message Jeff,news:1139093748.218813.39570@g44g2000cwa.googlegroups.com... > 97T, > > If I understand what you are trying to do, it seems that you are trying > to add controls at runtime. If thats right then, this article should be > able to give you some direction. Let me know if thats not what you were > trying to do. > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolslistitemcollectionclassremovetopic.asp > > Jeff > Thank you for your response, sir. This article is about removing items from a listbox control. I'll keep looking, thanks for trying, maybe you gave me a different link than you were thinking of? --NinerSevenTango-- Private myTextBoxesAry As TextBox()
Private Sub Form1_Load(...)... myTextBoxesAry = New TextBox() {TextBox1, TextBox2, TextBox3} End Sub Doesn't get easier than that!... Except of course if the Form Designer did this for you behind the scenes... (as VB.Classic could do). Or you can set a reference to Visual Basic Compatibility library... I think it contains a ControlArray component... though MS discourages the use of this library as it might not be supported forever. To create an array of text boxes at runtime I use code similar to the
following: Public cells(4) as TextBox For j = 1 To 4 cells(j) = New TextBox cells(j).Name = CStr( j) cells( j).Width = 40 cells(j).Height = 40 cells(j).Text = "Cell " & CStr(j) cells(j).Top = 150 cells(j).Left = 200 + j * (cells(j).Width + 2) cells(j).ForeColor = Color.Black cells(j).BackColor = Color.LightBlue cells(j).BorderStyle = BorderStyle.FixedSingle cells(j).TextAlign = HorizontalAlignment.Center cells(j).AutoSize = False AddHandler cells(j).Click, AddressOf Me.TextBoxClick Me.Controls.Add(cells(j)) Next Show quoteHide quote "97T" <not@spamthis.com> wrote in message news:u4ceqEdKGHA.2300@TK2MSFTNGP15.phx.gbl... > Please excuse my ignorance. > > In other high level languages I've played with, there were functions that > let you build commands or lines of code. > > For instance, you could assemble a string variable, and convert it to a > line of code, then execute the line of code. > > That would be one way to do what I want. > > Something like (in English), > > Set CommandVariable equal to String1 & String2 & String3 > Execute CommandVariable > > This would make it simple for me to step through an array and assign my > bytes to a series of sequentially numbered textboxes in a form. I could > do a loop and change the value of one part of it. > > I've waded into the discussions about control arrays that don't work > anymore, and I got mired in quicksand. > > Do I have to create classes and all that just to transfer information to > textboxes without having to type out each one by name in the code? I'd > rather use a for / next loop ...... > > This would be nice if it worked, :) > > (I've placed some text boxes on my form and named them Txtbx0, Txtbx1, > etc.) > For I = 0 to 4 > Form1.Txtbx(I).Text = MyArray(I) > Next > > Thanks for helping the newbie, > > --NinerSevenTango-- > >
Show quote
Hide quote
"97T" <not@spamthis.com> wrote in message Thank you all for your responses, I will investigate what it takes to do it news:u4ceqEdKGHA.2300@TK2MSFTNGP15.phx.gbl... > Please excuse my ignorance. > > In other high level languages I've played with, there were functions that > let you build commands or lines of code. > > For instance, you could assemble a string variable, and convert it to a > line of code, then execute the line of code. > > That would be one way to do what I want. > > Something like (in English), > > Set CommandVariable equal to String1 & String2 & String3 > Execute CommandVariable > > This would make it simple for me to step through an array and assign my > bytes to a series of sequentially numbered textboxes in a form. I could > do a loop and change the value of one part of it. > > I've waded into the discussions about control arrays that don't work > anymore, and I got mired in quicksand. > > Do I have to create classes and all that just to transfer information to > textboxes without having to type out each one by name in the code? I'd > rather use a for / next loop ...... > > This would be nice if it worked, :) > > (I've placed some text boxes on my form and named them Txtbx0, Txtbx1, > etc.) > For I = 0 to 4 > Form1.Txtbx(I).Text = MyArray(I) > Next > > Thanks for helping the newbie, > > --NinerSevenTango-- > > by adding the boxes at runtime. But in my application, I have already placed a good number of them into my form, because they will always be there. I just want to populate them with text which will already be in an array, without having to type in the name of each one in turn in the code. I would rather loop through them if it is at all possible. Since I will be making a large number of such screens, if I can't loop through them like I hoped to do, I guess I will generate them at runtime. Thanks again for your help, --NinerSevenTango-- 97T,
There is almost always a way to do whatever you want to do in .NET. Try the following code and see if it is what you had in mind. You will need 3 TextBoxes and 1 Button on the form to run it. The elegant RecurseControls code was copied from an earlier post by Herfried K. Wagner a couple of days ago in response to a question about Control Collections. The somewhat less elegant code is mine :-). I often just read the questions and answers here to pick up tips on how to do things. ----------------------- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click RecurseControls(Me) End Sub Private Sub RecurseControls(ByVal ctr As Control) Debug.WriteLine(ctr.Name) If TypeOf (ctr) Is TextBox Then Dim i As Integer Dim myTextBoxCounter As Integer = 3 Dim myTextArray As String() = {"Box 1", "Box 2", "Box 3"} For i = 1 To myTextBoxCounter If ctr.Name = "TextBox" & i Then ' myTextArray is 0 based ctr.Text = myTextArray(i - 1) End If Next (i) End If If ctr.HasChildren Then For Each c As Control In ctr.Controls RecurseControls(c) Next c End If End Sub ----------------------------- Herfried's orignal code: \\\ Private Sub RecurseControls(ByVal ctr As Control) Debug.WriteLine(ctr.Name) If ctr.HasChildren Then For Each c As Control In ctr.Controls RecurseControls(c) Next c End If End Sub .. .. .. RecurseControls(Me) /// Stan Stan Smith ACT! Certified Consultant ADS Programming Services 2320 Highland Avenue South Suite 290 Birmingham, AL 35205 205-222-1661 www.adsprogramming.com ssmith_at_adsprogramming.com Show quoteHide quote "97T" <not@spamthis.com> wrote in message news:u4ceqEdKGHA.2300@TK2MSFTNGP15.phx.gbl... > Please excuse my ignorance. > > In other high level languages I've played with, there were functions that > let you build commands or lines of code. > > For instance, you could assemble a string variable, and convert it to a > line of code, then execute the line of code. > > That would be one way to do what I want. > > Something like (in English), > > Set CommandVariable equal to String1 & String2 & String3 > Execute CommandVariable > > This would make it simple for me to step through an array and assign my > bytes to a series of sequentially numbered textboxes in a form. I could > do a loop and change the value of one part of it. > > I've waded into the discussions about control arrays that don't work > anymore, and I got mired in quicksand. > > Do I have to create classes and all that just to transfer information to > textboxes without having to type out each one by name in the code? I'd > rather use a for / next loop ...... > > This would be nice if it worked, :) > > (I've placed some text boxes on my form and named them Txtbx0, Txtbx1, > etc.) > For I = 0 to 4 > Form1.Txtbx(I).Text = MyArray(I) > Next > > Thanks for helping the newbie, > > --NinerSevenTango-- > > Thanks, Stan, I think this one will give me what I need to get it done.
I'm off to try it out. --NinerSevenTango-- Show quoteHide quote "Stan Smith" <ssm***@adsprogramming.com> wrote in message news:eJHBU3hKGHA.1676@TK2MSFTNGP09.phx.gbl... > 97T, > > There is almost always a way to do whatever you want to do in .NET. Try > the following code and see if it is what you had in mind. You will need 3 > TextBoxes and 1 Button on the form to run it. > > The elegant RecurseControls code was copied from an earlier post by > Herfried K. Wagner a couple of days ago in response to a question about > Control Collections. The somewhat less elegant code is mine :-). I often > just read the questions and answers here to pick up tips on how to do > things. > > ----------------------- > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > > RecurseControls(Me) > > End Sub > > Private Sub RecurseControls(ByVal ctr As Control) > > Debug.WriteLine(ctr.Name) > > If TypeOf (ctr) Is TextBox Then > > Dim i As Integer > > Dim myTextBoxCounter As Integer = 3 > > Dim myTextArray As String() = {"Box 1", "Box 2", "Box 3"} > > For i = 1 To myTextBoxCounter > > If ctr.Name = "TextBox" & i Then > > ' myTextArray is 0 based > > ctr.Text = myTextArray(i - 1) > > End If > > Next (i) > > End If > > If ctr.HasChildren Then > > For Each c As Control In ctr.Controls > > RecurseControls(c) > > Next c > > End If > > End Sub > > ----------------------------- > > Herfried's orignal code: > > \\\ > Private Sub RecurseControls(ByVal ctr As Control) > Debug.WriteLine(ctr.Name) > If ctr.HasChildren Then > For Each c As Control In ctr.Controls > RecurseControls(c) > Next c > End If > End Sub > . > . > . > RecurseControls(Me) > /// > > Stan > > > Stan Smith > ACT! Certified Consultant > ADS Programming Services > 2320 Highland Avenue South > Suite 290 > Birmingham, AL 35205 > 205-222-1661 > www.adsprogramming.com > ssmith_at_adsprogramming.com > > "97T" <not@spamthis.com> wrote in message > news:u4ceqEdKGHA.2300@TK2MSFTNGP15.phx.gbl... >> Please excuse my ignorance. >> >> In other high level languages I've played with, there were functions that >> let you build commands or lines of code. >> >> For instance, you could assemble a string variable, and convert it to a >> line of code, then execute the line of code. >> >> That would be one way to do what I want. >> >> Something like (in English), >> >> Set CommandVariable equal to String1 & String2 & String3 >> Execute CommandVariable >> >> This would make it simple for me to step through an array and assign my >> bytes to a series of sequentially numbered textboxes in a form. I could >> do a loop and change the value of one part of it. >> >> I've waded into the discussions about control arrays that don't work >> anymore, and I got mired in quicksand. >> >> Do I have to create classes and all that just to transfer information to >> textboxes without having to type out each one by name in the code? I'd >> rather use a for / next loop ...... >> >> This would be nice if it worked, :) >> >> (I've placed some text boxes on my form and named them Txtbx0, Txtbx1, >> etc.) >> For I = 0 to 4 >> Form1.Txtbx(I).Text = MyArray(I) >> Next >> >> Thanks for helping the newbie, >> >> --NinerSevenTango-- >> >> > >
Problem to write a good serie of bytes in a file.
Additional information: Cast from string "" to type 'Double' is not valid. error Visual Basic 2005 Report writers for VB.NET current working directory problem taskbar icon Making Bitmaps and Graphics objects - two ways Newbie Question Saving Projects Some error apper to me in my declerations visual basic 2005 free download |
|||||||||||||||||||||||