Wrox Programmer Forums
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 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 January 24th, 2005, 07:45 PM
Registered User
 
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Nameing a object

Hi, i was wondering if anyone knew a easy way of nameing a object instance somthing that gets input in to the .text section of a text box?


Thanks

 
Old January 24th, 2005, 07:54 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

There are languages that will allow you to modify the code as you go, but VB isn’t one of them. (Nor is C...)

Why do you want to do this? (Just curious...)
 
Old January 25th, 2005, 06:04 AM
Registered User
 
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

basicly i need to creat lots of instances of a class called newspaper, in real time. the user can input data in to some text boxes on a form, click on a button at the bottem and it creates a instance of the class. would this be posible at all? or would i have to create a a set number of instances befor, and acess them through an array or something? any ideas?

 
Old January 25th, 2005, 11:37 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

It is absolutely possible!

One way is to create an array whose type is this object. When you want a new instance of the class, ReDim the array to be 1 element larger, and set that new element as a New instance of the class. (In VB6 this requires redimming with the Preserve keyword, that might be the case still with .NET...)

Another way is to use a Collection. When you add the item to the Collection, you can set the key to a meaningful string, and use that string to gain access to the class later.
 
Old January 27th, 2005, 07:25 PM
Registered User
 
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks! thats set me on the right track.. heres the final code

ReDim Preserve Nnewspaper(UBound(Nnewspaper) + 1)


This shold presrve all data in the array, and then add 1 to an array called Nnewspaer, using the UBound command to find out the size of the array. im 90% shure it will work, havent tested yet

thanks

 
Old January 28th, 2005, 12:18 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Pretty good. But since you are going to be using the new-element index more than once, I like
Code:
    Dim i As Long

    i = UBound(Nnewspaper) + 1
    ReDim Preserve Nnewspaper(i)

    Nnewspaper(i) = ...





Similar Threads
Thread Thread Starter Forum Replies Last Post
object reference not set to instant of an object shahidrasul ASP.NET 2.0 Basics 1 September 5th, 2008 02:01 PM
Serializing Object Graph - Assigning Object to Jag venkat.kl C# 0 August 28th, 2006 10:39 AM
create a Line object ,Box object in CR at Runtime? thanhnt Pro VB 6 1 May 16th, 2005 06:51 AM
Error Occurred creating Report Object: Object does sa_moizatyahoo Classic ASP Professional 0 February 1st, 2005 10:29 AM





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