Wrox Programmer Forums
|
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 August 11th, 2005, 08:35 AM
Authorized User
 
Join Date: Jul 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default better code

I have my ugly code:

dim o1, o2, o3,... as object

object1.property = 100
object2.property = 100
...
How I make it better,
for example by array object?
(I am beginner.)

Dieser Beitrag wurde schon 1 mal editiert,


 
Old August 11th, 2005, 04:58 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

--With array:

dim o() as object

redim o(9)

for k = 0 ubound(o)
set o(k) = new object
o(k).Property = 100

--With collections

dim c as new Collection
dim o as object

for k = 0 to 9
set o = new object
c.add o

for each o in c
o.property = 100

----

what is nice of collection is that objects can be added, removed, inserted. If each object can have an unique key (string), objects can be accessed very fast using that key. For example, a collection of persons can use the SSN as an index when the object is added:

personCollection.add personObject, SSNofThisPerson

to retrive the object:

personObject = personCollection.Item(SSNofThisPerson)

Marco





Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM
Writing Client Side Script from Code-Behind code sajid_pk Classic ASP Databases 1 January 18th, 2005 12:53 AM
disable forum code within [code] blocks? nikolai Forum and Wrox.com Feedback 0 October 23rd, 2003 07:52 PM





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