473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 22126
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*******@comcast.net> wrote in message
news:jJ********************@comcast.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******************@twister01.bloor.is.net.c able.rogers.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*******@comcast.net> wrote in message
: news:jJ********************@comcast.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("vb.line", "line2")

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

"Tom Rathbun" <tj*******@comcast.net> wrote in message news:<jJ********************@comcast.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).Visible = True
Next i
End Sub
Regards,
Joon Nan

"Tom Rathbun" <tj*******@comcast.net> wrote in message
news:jJ********************@comcast.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
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 ...
2
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...
2
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...
2
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
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
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...
1
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...
1
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...
0
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...
1
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 = "";...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.