473,569 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Create Object at Runtime

This is probably simple but it has stumped me. I want to create objects at
runtime for example:
A program that would allow you to draw lines on a form. For each new line I
would like to create a new line object in an array the same way you would a
simple variable.

if it was just a variable I could

dim a(0) as single
..
(some code)
..
b=ubound(a)+1
redim preserve a(b) as single
..
(other code)

Is it possible to do this with controls ... say 10 textboxs today 12
tomarrow etc.
right now I put a bunch in an array and hide the ones I don't need.

Thanks
Tom
Jul 17 '05 #1
4 22151
Assuming you have one textbox on the form named Text1, with its index
property set to 0 to create a control array:
--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"Tom Rathbun" <tj*******@comc ast.net> wrote in message
news:jJ******** ************@co mcast.com...
: This is probably simple but it has stumped me. I want to create objects
at
: runtime for example:
: A program that would allow you to draw lines on a form. For each new line
I
: would like to create a new line object in an array the same way you would
a
: simple variable.
:
: if it was just a variable I could
:
: dim a(0) as single
: .
: (some code)
: .
: b=ubound(a)+1
: redim preserve a(b) as single
: .
: (other code)
:
: Is it possible to do this with controls ... say 10 textboxs today 12
: tomarrow etc.
: right now I put a bunch in an array and hide the ones I don't need.
:
: Thanks
: Tom
:
:
Jul 17 '05 #2
grrrrrrr ...

.... use:

'load
Private Sub Command1_Click( )

Dim cnt As Long

For cnt = 0 To 25

If cnt > 0 Then Load Text1(cnt)

With Text1(cnt)
.Move 300, 210 + (300 * cnt), 1700
.Visible = True
End With

Next

End Sub

'unload
Private Sub Command2_Click( )

Dim cnt As Long

For cnt = 25 To 0 Step -1

If cnt > 0 Then Unload Text1(cnt)

Next

End Sub

You can't unload the control added at design time, so it's important to test
to ensure the index > 0.

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"Randy Birch" <rg************ @mvps.org> wrote in message
news:N3******** **********@twis ter01.bloor.is. net.cable.roger s.com...
: Assuming you have one textbox on the form named Text1, with its index
: property set to 0 to create a control array:
:
:
: --
:
: Randy Birch
: MVP Visual Basic
: http://www.mvps.org/vbnet/
: Please respond only to the newsgroups so all can benefit.
:
:
: "Tom Rathbun" <tj*******@comc ast.net> wrote in message
: news:jJ******** ************@co mcast.com...
: : This is probably simple but it has stumped me. I want to create objects
: at
: : runtime for example:
: : A program that would allow you to draw lines on a form. For each new
line
: I
: : would like to create a new line object in an array the same way you
would
: a
: : simple variable.
: :
: : if it was just a variable I could
: :
: : dim a(0) as single
: : .
: : (some code)
: : .
: : b=ubound(a)+1
: : redim preserve a(b) as single
: : .
: : (other code)
: :
: : Is it possible to do this with controls ... say 10 textboxs today 12
: : tomarrow etc.
: : right now I put a bunch in an array and hide the ones I don't need.
: :
: : Thanks
: : Tom
: :
: :
:
:
Jul 17 '05 #3
Try this:
Dim line2 As VB.Line
Private Sub Form_Load()

Set line2 = Controls.Add("v b.line", "line2")

line2.X1 = 2520
line2.X2 = 360
line2.Y1 = 400
line2.Y2 = 2000
line2.Refresh
line2.BorderCol or = red
line2.Visible = True
' etc etc
End Sub

"Tom Rathbun" <tj*******@comc ast.net> wrote in message news:<jJ******* *************@c omcast.com>...
This is probably simple but it has stumped me. I want to create objects at
runtime for example:
A program that would allow you to draw lines on a form. For each new line I
would like to create a new line object in an array the same way you would a
simple variable.

if it was just a variable I could

dim a(0) as single
.
(some code)
.
b=ubound(a)+1
redim preserve a(b) as single
.
(other code)

Is it possible to do this with controls ... say 10 textboxs today 12
tomarrow etc.
right now I put a bunch in an array and hide the ones I don't need.

Thanks
Tom

Jul 17 '05 #4
This is simple,

Create a Line object or TextBox object, set Index to 0, set Visible=False
Put in the example code like below:

Private Sub Form_Load()
Dim i As Integer
For i = 1 To 5
Load Line1(i)
Line1(i).Y1 = i * 100
Line1(i).Y2 = i * 100
Line1(i).Visibl e = True
Next i
End Sub
Regards,
Joon Nan

"Tom Rathbun" <tj*******@comc ast.net> wrote in message
news:jJ******** ************@co mcast.com...
This is probably simple but it has stumped me. I want to create objects at runtime for example:
A program that would allow you to draw lines on a form. For each new line I would like to create a new line object in an array the same way you would a simple variable.

if it was just a variable I could

dim a(0) as single
.
(some code)
.
b=ubound(a)+1
redim preserve a(b) as single
.
(other code)

Is it possible to do this with controls ... say 10 textboxs today 12
tomarrow etc.
right now I put a bunch in an array and hide the ones I don't need.

Thanks
Tom

Jul 17 '05 #5

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

Similar topics

3
8373
by: hoho^_^ | last post by:
hello when I run a script on my server I get a error messeage.. Microsoft VBScript runtime error '800a01ad' ActiveX component can't create object: 'CDO.message I don't know how to solve it,Thank you for your reply^_^
2
15745
by: brazilnut | last post by:
Hi. Let me explain the setup. I am using Visual Studio .NET to develop a sort of add-in (COM class) for Excel called SQLAddin. It basically queries a SQL server and pulls in data. Now within my Visual Studio Project, the SQLAddin references a compiled COM object built with Visual Studio 6.0 called SQLOld.dll. When I complie the project I get the...
2
13392
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class template and by setting output to a type library (DLL). All the object does is return a string value. At this point I have not checked the option to...
2
7103
by: sonu | last post by:
I am tring to create activexobject like var Fo =new ActiveXObject("Scripting.FileSystemObject"); but i am finding error that automation server cant create object any help
1
1960
by: SAN CAZIANO | last post by:
how can i create a runtime table and define a new field to allow null value and set the rquired to true or false ???
1
2132
by: kathyk | last post by:
Hi, I created an application in MS Access 2000. Since upgrading to MS Access 2003 I have been finding all sorts of strange things. My current problem is with the function below. Ig get an error "429 ActiveX Componant Can't Create Object" How can I correct this error? Thanks very Much! Kathy Here is the function: ' By Glen Appleton found...
1
13785
by: Astra | last post by:
Hi All Was running my ASP app no problem on a Windows XP Pro SP2 machine with IIS, dragged a copy my app folder and put it on another Windows XP Pro SP2 machine with IIS and I get the below problem: Error Type: Microsoft VBScript runtime (0x800A01AD) ActiveX component can't create object: 'Scripting.FileSystemObject' /asp/forms.asp,...
1
2820
by: malgreen | last post by:
Good morning everyone. I recently did an upgrade on a webserver that required me to combine two seperate servers(one front end and one backend). The process is all but complete, however there is a mail server attached to this web page. Now I have recreated the mail server , but I belive that due to the fact that the old server ran IIS 5.x and the...
0
2302
by: syedsarfaraz | last post by:
Hi There! Could anybody please help regarding the below issue. We had a COM+ component deployed on Windows 2000/NT machine it was working fine, I mean when it was being invoked from other machines it was creating object and was serving the purpose. Recently as an upgrade we moved all the COM+ component from Windows 2000/NT to WINDOWS 2003...
1
2245
by: Moiseszaragoza | last post by:
Hey i am having this problem with email <%@Language=JScript%> <% var mail = Server.CreateObject("CDONTS.NewMail"); mail.BodyFormat = 0; mail.MailFormat = 0; mail.ContentBase = ""; mail.To = "mZaragoza@xxx.com"; mail.From = "moisesz@xxx.com";
0
7609
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...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
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...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3651
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...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
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
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.