|
-
Sep 11th, 2009, 01:43 PM
#7
Re: HELP putting an integer in the middle of a string
 Originally Posted by stateofidleness
vb Code:
Dim Count as Integer = 1
Dim currentIndex as Integer = 0
For Count = 1 to 31 'You need to go to 31 because indexes are 0-based
DirectCast(Me.Controls("XB" & Count.ToString & "TextBox"), TextBox).Text = T(currentIndex.ToString)
currentIndex+=1
Next
See if that works. The syntax on the DirectCast may be off a bit, but should be very close. I'm unable to test at the moment
Just as a side note here, you don't need to cast a control type to a textbox type just to access its .text property. The text property is inherited from the base control class anyway. You only need to cast when you need to access something specific to the given class, that is not inherited from the base class you already have an instance of.
Also, 1 to 31 is 31 iterations, not 30... 0 to 29 or 1 to 30 is 30 iterations of a loop.
I would code this out something like this:
Code:
For Count As Integer = 1 To 30
Me.Controls(String.Format("XB{0}TextBox", Count.ToString)).Text = T(Count - 1)
Next
where I am assuming T is some 30 element array of strings?
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
|