Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Run time adding control

Posted on 1998-08-16
7
Medium Priority
?
185 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 210 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
Suggested Courses

636 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