adding dynamic textbox control array

adding dynamic textbox control array by code

Page 1 of 1

6 Replies - 17778 Views - Last Post: 17 March 2013 - 10:43 PM Rate Topic: -----

#1 EMOHD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-April 07

adding dynamic textbox control array

Post icon  Posted 12 January 2009 - 05:07 AM

' i already make a textbox with name text(0) on the form
' and i want to add 3 another textbox's on the form using code
' but an error appears telling me that (NOT LEGAL NAME)
' i tried many times and using collection and every thing possible
' but it didn't solve the problem

' May you help me or give me notes

Dim ctrl  As Control

 for i=1 to 3 

Set ctrl = Me.Controls.Add("vb.textbox", "text(" & i & ")", me)
With ctrl
.Left = text(0).left
.Top =  text(0).top+text(0).height+50
.Width = text(0).width
.Height =  text(0).height
.Alignment = 1
.Appearance = 0
 .Visible = True
End With
  
Next i


This post has been edited by EMOHD: 12 January 2009 - 06:58 AM


Is This A Good Question/Topic? 0
  • +

Replies To: adding dynamic textbox control array

#2 Guest_Shankar Roy*


Reputation:

Re: adding dynamic textbox control array

Posted 30 March 2010 - 10:57 PM

You can read this to get an idea : http://www.vbexplore...0/april2000.asp

Regards.

Shankar
Was This Post Helpful? 0

#3 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: adding dynamic textbox control array

Posted 31 March 2010 - 03:03 AM

just view this link

http://www.dreaminco...01&#entry948901
Was This Post Helpful? 0
  • +
  • -

#4 Cplusman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-March 13

Re: adding dynamic textbox control array

Posted 15 March 2013 - 05:50 PM

>> "text(" & i & ")"

I know this is old, but we still find it with Google.
You are creating your own name for each control.
The idea is that all controls in an array have the same name.
That's how they share the same events.
Replace
"text(" & i & ")"
with the name of the control you defined with Index = 0.
Was This Post Helpful? 0
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: adding dynamic textbox control array

Posted 17 March 2013 - 12:35 PM

I'm sorry, but you might wish to read the link that thava provided too, because your answer is wrong.
Was This Post Helpful? 0
  • +
  • -

#6 Cplusman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-March 13

Re: adding dynamic textbox control array

Posted 17 March 2013 - 03:23 PM

I would really like to hear exactly what is wrong with my comment.

The reference from Thava describes a method of creating an array of
“control variables”(what a C programmer would call a “control pointer”).
The question was about creating a “textbox control array”, which is
an array of controls, not an array of control variables.
If you don’t know the difference, this is a great opportunity for you.

As “Guest_evry1falls* “ said, “thanks for the link ...
it was helpful but still did not answer my question !!”

What he’s having trouble with is handling the events from the
controls he’s adding at run-time. What Raziel suggested does
the same thing I said except it used Load instead of Add, and you
don’t need to do that. I don’t understand how you specify with Load
where the control goes, i.e. what Form it goes on. With Add, you
specify the form whose controls collection you are adding to.

I say again, the important feature is that the name of each
control must be the same. I still think I’m right.

Raziel? Guest_evry1falls?
Was This Post Helpful? 0
  • +
  • -

#7 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: adding dynamic textbox control array

Posted 17 March 2013 - 10:43 PM

I see. Well, I'm sorry for the missed opportunity, but I'm afraid I do know the difference. My read of thava's link differs from yours: raziel shows the correct technique pretty clearly.

Now, perhaps you will demonstrate with a code sample the method of using Controls.Add to create a control array. If you do, I will say you were right all along, and eat humble pie. (This is a great opportunity for you--you get to make a VB expert with 1000 hours of Microsoft Official Teaching Experience in VB look foolish! :) ) But I just spent a half hour making sure that I hadn't spent all those hours teaching this wrong (it's been 10 years, so of course I could be getting a bit rusty, thought I), and I haven't been able to create a control array in this manner.

Unless and until you do that, I'm going to say that you only still think you're right because you haven't tried to do it.

This post has been edited by BobRodes: 17 March 2013 - 10:56 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1