Solved

Run time adding control

Posted on 1998-08-16
7
177 Views
Last Modified: 2010-04-30
I want to do some thing like this.
When i click on a button once, a textbox will be created.
I click again, another textbox will be created. How many textbox appear on the form will depend on how many times i click on the  button.
The textbox is created at run time.
Sample code will be most helpful.
Thanks.
0
Comment
Question by:chualk
  • 4
  • 2
7 Comments
 
LVL 1

Accepted Solution

by:
lbk earned 70 total points
ID: 1429148
In order to be able to create a control at run time, you must already have at least one of this type on your form before compilation. The first one must be a control array (which you can accomplish by setting its index property to 0)
Then, at run time, you load new instances of the control. If you want NO textbox at the very beginning, just make the original one visible.

Try this (btnAdd is the button to add the text box, txtText is the text box, whose index must be 0)

sub btnAdd_Click
   static iNewIndex    As Integer

   if iNewIndex > 0 then
       'New control must be loaded first
       Load txtText(iNewIndex)
       txtText(iNewIndex).top = txtText(iNewIndex - 1).Top + _
             txtText(inewindex - 1).Height * 1.2
   else
      'Take the first control (the one already on the form)
   end if
   txtText(iNewIndex).Visible=True

   iNewindex=inewindex+1
end sub

0
 
LVL 1

Author Comment

by:chualk
ID: 1429149
Ibk :

If i want to put the textbox in different tab pages. How am i going to assign it?
I want only one  textbox in one tab page.
I am using sstab.
10Q!
0
 
LVL 1

Expert Comment

by:lbk
ID: 1429150
My personal advice for you is to either put a textbox array on each tab, and then load the specific one, or to use the old fashion tab control found in common controls. But thats even more complicated.
Maybe tell me what it is you need to do.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:chualk
ID: 1429151
Ibk:

I don't want to create a textbox array at each page.
Just one textbox array at form load and when i goto next page, a new textbox control will be created.
0
 
LVL 1

Expert Comment

by:lbk
ID: 1429152
yeah, see.. you can't do, sorry. The tab control is a control container, which only takes controls at run time. You can't transfer them from page to page.
Maybe the old fashion tab strip is better for you, especially since adding tabs at run time is very easy to do. But because that tab strip doesn't take controls itself, you'd have to create a picture box that acts as a container. That way you could use the same picture box for each tab. You would have to load/unload textboxes constantly though, as the user changes from tab to tab.
0
 

Expert Comment

by:dkaratzios
ID: 1429153
Concerning your problem, were you able to create a textbox in runtime without creating one unvisible on your screen? I am experincing the same problem and was not able to solve it as well !
0
 
LVL 1

Expert Comment

by:lbk
ID: 1429154
There is no way to do that, becuase VB needs the information about the control at compilation time. It's just impossible to do. (Unless you're using an OLE container, but that would be senseless)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now