[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Run time adding control

Posted on 1998-08-16
7
Medium Priority
?
186 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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…
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

872 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