472,795 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,795 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 22069
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 = "";...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.