Solved

Run time adding control

Posted on 1998-08-16
7
176 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

760 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

20 Experts available now in Live!

Get 1:1 Help Now