|
-
May 27th, 2004, 05:29 PM
#1
Thread Starter
Frenzied Member
Class Question
If I have a class called MyClass structured as follows:
VB Code:
Public Class MyClass
Public Sub Property1 As String
Public Sub Property2 As String
Public Sub Property3 As String
End Class
and i have 2 ways to fill those properties...
Way 1
Property1 = "Jim"
Property2 = "Jimmy"
Property3 = "Jimmers"
Way2
Property1 = "Tim"
Property2 = "Timmy"
Property3 = "Timothy"
How can I take an instance of my class (let's call it MyBigClass)... and instantiate it so that it's properties fall in line with either way 1 or way 2??? So that they are "automatically" filled???
Thanks,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 27th, 2004, 05:43 PM
#2
PowerPoster
Hi,
"and i have 2 ways to fill those properties...
Way 1
Property1 = "Jim"
Property2 = "Jimmy"
Property3 = "Jimmers"
Way2
Property1 = "Tim"
Property2 = "Timmy"
Property3 = "Timothy" "
I know it's nearly midnight here, but I can't see the difference
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
May 27th, 2004, 05:49 PM
#3
Thread Starter
Frenzied Member
Sorry, I'll try to be more clear...
What I mean is...
I want the class to be able to set the properties for the MyBigClass object...
The values themselves....
I don't know if this is close to what I would need to do, but...
If I were to say something like...
Dim MyBigClass as New MyClass.Jim
It would set the Properties to match Way 1
Understand now?
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 27th, 2004, 05:58 PM
#4
PowerPoster
Hi,
You've convinced me I'm going to bed now and see what responses you've had by the morning
Oh. Just one thing. Looking at your interests do you consider there is a difference between "God" and "Jesus" or "God" and "The Holy Ghost"?
Goodnight!
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
May 27th, 2004, 06:22 PM
#5
Thread Starter
Frenzied Member
LOL...
Ok... I hope you get some good rest...
And no, there is no difference... unless you count the order in which they came to be known to us 
The idea is not to change the property type or anything, but the data in the properties to begin with...
"Tim" and "Jim" are very different... (well, in the first character anywayz)
I hope you understand now...
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 27th, 2004, 06:43 PM
#6
Lively Member
Use a constructor
VB Code:
Class MyClass
private aName1 as String
private aName2 as String
private aName3 as String
Public Sub New(byVal name1 as String, byVal name2 as String, byVal name3 as String)
aName1 = name1
aName2 = name2
aName3 = name3
End Sub
End Class
dim someClass as MyClass
someClass = new MyClass("John", "Tim", "suxor")
Obviously if you didn't want to pass the variables to the constructor you'd just assign them as follows...
VB Code:
Class MyClass
private aName1 as String
private aName2 as String
private aName3 as String
Public Sub New()
aName1 = "John"
aName2 = "Tim"
aName3 = "Hacker"
End Sub
End Class
Hope this helps.
-
May 27th, 2004, 07:51 PM
#7
Thread Starter
Frenzied Member
Yeah, that helps some...
I guess I could use some string constants (LoadJim, LoadTim for expample)
and then do something like a select statement to set the values accordingly...
is there a better way?
It could be that my LoadJim, LoadTim and so forth options will be generated from the items in a collection... any ideas to utilize this better?
Thanks,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 27th, 2004, 07:52 PM
#8
Thread Starter
Frenzied Member
And just a tidbit more info...
The items in the collection will be of the same type of the item that I am wanting to initialize... or the properties will be very closely related...
squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 27th, 2004, 08:51 PM
#9
Lively Member
VB Code:
Class MyClass
private aName1 as String
private aName2 as String
private aName3 as String
Public Sub New(byVal name1 as String, byVal name2 as String, byVal name3 as String)
aName1 = name1
aName2 = name2
aName3 = name3
End Sub
End Class
dim someClass as MyClass
select case way
case 1
someClass = new MyClass("John", "Tim", "suxor")
case 2
someClass = new MyClass("a", "b", "c"
end select
-
May 27th, 2004, 09:30 PM
#10
Thread Starter
Frenzied Member
Is there NO other way to do this???
There are like 50 different properties... and i won't be able to hard code them in like you are describing...
I guess I will have to use a variable for each of the properties and .... shoot...
What's the use?
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 27th, 2004, 10:05 PM
#11
Lively Member
Well, how about posting what you do actually have to do? Maybe you aren't structuring your data in appropriate manner for the task? Maybe we could come up with another solution?
-
May 28th, 2004, 12:42 AM
#12
If your values are coming from a collection, declare an array of objects of MYCLASS and run a loop through the collection, populating the properties accordingly for each element of your MYCLASS array.
Tell me if I'm not understanding something here.
-
May 28th, 2004, 06:57 AM
#13
PowerPoster
Hi squirrelly1,
"And no, there is no difference... unless you count the order in which they came to be known to us "
Amen.
With regard to your problem, it looks like some of us are not clear on what you are trying to do. It is obviously not just trying to fill properties with values. If you are trying to create properties with different names in different instances of the class, could you not set up the properties as a collection and loop through them using a reference? (This is a bit beyond me really - just a thought)
Last edited by taxes; May 28th, 2004 at 07:12 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
May 28th, 2004, 08:47 AM
#14
Frenzied Member
Why not use set & get property procedures? If you had a set procedure in your class called MyName, you could then use the dot notation to set the value. This wouldn't work for the constructor unless you passed the values in, but if you had an instance of your class named clsTryThis, you could do clsTryThis.Somename = "Jim". If you also had a get procedure, you could do strUsername = clsTryThis.SomeName. Plus, you'd have intellisense.
-
May 28th, 2004, 03:45 PM
#15
Thread Starter
Frenzied Member
Ok. These classes I'm using are huge so I will try to reconstruct what I want to do on a smaller scale...
Let's say I have a class as follows:
VB Code:
Public Class ModelObject
Public ModelName As String
Public String1 As String
Public String2 As String
End Class
And I have a collection of these ModelObject classes
VB Code:
Public Class ModelObjectCol
'Collection stuff (add, remove, item, search, so forth)
End Class
And I have another collection of Production classes...
What I would like to be able to do is to create a Production Object from the data held in a specific model object (found in the model object collection)
Am I going about this the wrong way? Is there a better way to structure this?
Thanks,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 28th, 2004, 03:46 PM
#16
Thread Starter
Frenzied Member
It's almost like an inventory/production system, but not quite...
squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 28th, 2004, 04:34 PM
#17
Frenzied Member
I'm not at work where VB is, and am on my 2nd glass of wine.
But here's a conceptual stab...
Dim myProd as new Production
myProd.Something = myModelCol.Model("name_or_index").ModelName
myProdCol.Add(myProd)
Look at the dataset for examples. A dataset is a collection of tables, which in turn have properties and objects (some of which are also collections), etc.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|