Solved

Run time adding control

Posted on 1998-08-16
7
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 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