473,664 Members | 3,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding controls to a form using generated code (VB6)

Dear all,

I would like to figure out a way to add controls to a form using specs
stored in a table. Any assistance in fleshing this idea out would be
greatly appreciated. I'm using VB6.

Right now I am thinking I would loop through the specs table
(containing control name, control type, width, max length, etc) and
print lines of code to a text file. The code would look something
like the following:

Dim lblcontrol1 As Label
Set lblcontrol1 = Controls.Add("V B.Label", "lblControl 1")
lblcontrol1.Vis ible = True

Dim WithEvents txtControl1 As TextBox
Set txtControl1 = Controls.Add("V B.TextBox", "txtControl 1")
txtControl1.Vis ible = True

The code generator would substitute the appropriate control names,
property settings, and so forth.

I would then need to run this code at design time to get the controls
on the form, but I'm not sure how to create a form and run this code.
I can put it in the Form_Load event, but then the controls are created
only at run time, and I would like to be able to save the controls on
the form.

Can anyone point me in the right direction?

Thanks,
Chris
Jul 17 '05 #1
4 12803
In VB6 - you you have to create a control array of each control type you
want to add at run time.(by setting the index property to 0) - you can set
the visible property to false if you don't want it to show. You can add
additional members of the control array - but you can't just add a control
programatically (unless its part of a control array) - go figure.
Then
load Command1(1)
load Command1(2)
Command1.Visibl e = True
Command1.left = 100
Command1.Top = 257
etc

"Chris" <ch*****@mailin ator.com> wrote in message
news:a0******** *************** **@posting.goog le.com...
Dear all,

I would like to figure out a way to add controls to a form using specs
stored in a table. Any assistance in fleshing this idea out would be
greatly appreciated. I'm using VB6.

Right now I am thinking I would loop through the specs table
(containing control name, control type, width, max length, etc) and
print lines of code to a text file. The code would look something
like the following:

Dim lblcontrol1 As Label
Set lblcontrol1 = Controls.Add("V B.Label", "lblControl 1")
lblcontrol1.Vis ible = True

Dim WithEvents txtControl1 As TextBox
Set txtControl1 = Controls.Add("V B.TextBox", "txtControl 1")
txtControl1.Vis ible = True

The code generator would substitute the appropriate control names,
property settings, and so forth.

I would then need to run this code at design time to get the controls
on the form, but I'm not sure how to create a form and run this code.
I can put it in the Form_Load event, but then the controls are created
only at run time, and I would like to be able to save the controls on
the form.

Can anyone point me in the right direction?

Thanks,
Chris

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Jul 17 '05 #2
On Tue, 3 Aug 2004 20:52:38 -0400, "Hal Rosser"
<hm******@bells outh.net> wrote:
In VB6 - you you have to create a control array of each control type you
want to add at run time.(by setting the index property to 0) - you can set
the visible property to false if you don't want it to show. You can add
additional members of the control array - but you can't just add a control
programaticall y (unless its part of a control array) - go figure.


I think you'll find that you can do it in VB6

But it is not much use

The Control Array approach is, I think the best
Jul 17 '05 #3

"J French" <er*****@nowher e.com> wrote in message
news:41******** *******@news.bt click.com...
| On Tue, 3 Aug 2004 20:52:38 -0400, "Hal Rosser"
| <hm******@bells outh.net> wrote:
|
| >In VB6 - you you have to create a control array of each control type
you
| >want to add at run time.(by setting the index property to 0) - you
can set
| >the visible property to false if you don't want it to show. You can
add
| >additional members of the control array - but you can't just add a
control
| >programaticall y (unless its part of a control array) - go figure.
|
| I think you'll find that you can do it in VB6
|
| But it is not much use
|
| The Control Array approach is, I think the best

There wouldn't be much point in adding a control at runtime that wasn't
part of a control array, since you would have no event handlers for it
anyway.

If the OP really wants to do a code generator, OP could develop an
Add-In, which means learning the whole VBIDE object model and messing
with that. Or, OP could generate .frm files directly, then go to VB and
put them in a project.

A .frm file is just a text file, you can open several in NotePad to see
what they look like, and also the project.vbp file, to see how forms get
included in a project.

A bit scary, but maybe fun to play around with...

Jul 17 '05 #4
On Wed, 4 Aug 2004 19:31:54 -0700, "Steve Gerrard"
<my********@com cast.net> wrote:

"J French" <er*****@nowher e.com> wrote in message
news:41******* ********@news.b tclick.com...
| On Tue, 3 Aug 2004 20:52:38 -0400, "Hal Rosser"
| <hm******@bells outh.net> wrote:
|
| >In VB6 - you you have to create a control array of each control type
you
| >want to add at run time.(by setting the index property to 0) - you
can set
| >the visible property to false if you don't want it to show. You can
add
| >additional members of the control array - but you can't just add a
control
| >programaticall y (unless its part of a control array) - go figure.
|
| I think you'll find that you can do it in VB6
|
| But it is not much use
|
| The Control Array approach is, I think the best

There wouldn't be much point in adding a control at runtime that wasn't
part of a control array, since you would have no event handlers for it
anyway.
Agreed
If the OP really wants to do a code generator, OP could develop an
Add-In, which means learning the whole VBIDE object model and messing
with that. Or, OP could generate .frm files directly, then go to VB and
put them in a project.
Yes, but I rather suspect that the OP does not want to ship the VB
compiler to his users
A .frm file is just a text file, you can open several in NotePad to see
what they look like, and also the project.vbp file, to see how forms get
included in a project.
And it would be a good idea to copy that structure
- a way of 'double testing' during App development
A bit scary, but maybe fun to play around with...


While the OP would probably land up storing Control array parameters
in UDTs (for speed), it would be a good idea to write something that
generates a UDT from a Form and a Form from a UDT
- it would really show up errors
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2892
by: Terry | last post by:
I have a very basic program, but for some reason I can't get it to behave properly. What I want is a basic form with a TabControl that fills the entire form. The tab control should have 4 tabs with a single PropertyGrid control on each tab that fills it's parent's tab page's client area. Here's what I did. 1. Create a new project.
4
5476
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
6
436
by: Nathan Sokalski | last post by:
I am trying to dynamically add controls to my page, but am having trouble with controls such as buttons. I have been able to add simple controls such as Label controls, because they can be placed anywhere. I have managed to add Labels using the following code: Dim extralabel As Label = New Label extralabel.Text = "Generated Label" Me.Controls.Add(extralabel)
3
2339
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example ABAP, BDC etc..etc.. on every click event as Checkboxes. And these controls(checkboxes) should remain...
14
1984
by: 97T | last post by:
Well this is still bugging me. I know there are other ways around this, but for a number of reasons I would like to be able to do this one simple thing. I have a form with a number of controls on it. I have created these controls in the form design tool, and given them unique names. I would like to be able to put together a line of code that allows this:
1
4073
by: npaulus | last post by:
Hi, I am trying to dynamically add user controls on to my web form but for some reason my form isnt displaying the user control. form1.cs: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms;
3
2087
by: Toe Dipper | last post by:
In short we have a lengthy process when a form is loaded that adds activex controls to our windows form. This process in itself works fine however we would like to push this processing to a thread but are stumped so far. Our goal is simply to allow the form to fully display while the controls are being added. Preferrably with a progressbar to let them know that the form is still being built. Here are some snippets.
1
2046
by: srneu71 | last post by:
I have a project that requires a dynamically generated matrix table. The table is setup with 4 quadrants (N,S,E,W) with checkboxes to "link" the data in adjacent quadrants. The table has to be able to grow & shrink according to the number of items in each quadrant. I have coded the table as a user control in vb.net. My question is on how to retrieve the data out of the table on a post back. I have tried adding check boxes as straight...
4
4475
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is selected, the row is added using JavaScript. The script uses cloneNode to clone a hidden template row and all of its children and then adds the new row to the table, updates all of the child control Ids and sets visibility etc. The hidden...
0
8348
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7375
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4185
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2764
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1759
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.