Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 16th, 2003, 04:44 AM
Authorized User
 
Join Date: Jun 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating new objects from existing classes

This is what I am attempting to do...I want to create an instance of the VB.CommandButton class in code, without drawing an actual object on the form until run time.
something along the lines of;

dim x as object
set x = new vb.commandbutton

but this doesn't work...(and i don't know how to make it =o(

alternitavely...I tried creating instances of the commandbutton class from an existing control drawn on the control at design time. the name of the control was "Command1", and here is the code I wrote that failed to duplicate it.

Dim MyObject As Object
Set MyObject = New Command1
Load MyObject

I get "User defined-type not defined!" error. However, if I set it as...a copy of my form(form1), then it works just fine. Is there a reason I can't reference the controls already on the forms...and not just the forms themselves when trying to do this? Is there an easier way?

Thank you,
Hunter
 
Old June 16th, 2003, 05:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

The easiest way to do this is to copy from an existing control which is a control array - just set the Index property to 0 to make it a control array.
Then to create a new control use the Load statement:
Code:
Load Command1(newIndex)
You just need to keep a track of how many controls you've added, so you can set "newIndex" appropriately.

BTW there is a corresponding Unload statement too.

hth
Phil
 
Old June 16th, 2003, 07:24 PM
Authorized User
 
Join Date: Jun 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes...I meant to include that in my original posting. I am trying to create objects solely from the VB.CommandBox class, without any actual objects on the form at design time.
 
Old June 17th, 2003, 07:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, I understand that. What I am saying (and you are finding out by experiment) is that there is no easy way to do that. It is, however, very easy to create new objects from control "arrays" already present on the form. Don't forget that these existing control "arrays" don't have to be visible at all.

rgds
Phil





Similar Threads
Thread Thread Starter Forum Replies Last Post
creating new xml file from existing deepee XML 1 July 25th, 2006 10:35 AM
Dynamically Creating Objects of Array of Classes dinkarsinha General .NET 0 January 28th, 2005 06:22 AM
Creating classes!! NitinJoshi General .NET 2 January 24th, 2005 10:44 AM
Help with classes and Objects stalker C# 3 November 4th, 2004 06:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.