|
-
May 31st, 2007, 06:29 AM
#1
Thread Starter
Lively Member
[2005] String
Let me explain what I say
I am making a game
there are 2 characters.
And I make a class called character
dim char1 as new character
dim char2 as new character
And I make a function
Function result(i as integer) as integer
char1.sth.....
char2.sth
But I don't want to write each line of code twice....
And I write that char & i ,but it can't work
what should I do?
Last edited by s021126; May 31st, 2007 at 09:36 AM.
-
May 31st, 2007, 06:36 AM
#2
Re: [2005] String
 Originally Posted by s021126
abc.ab1
abc.ab2
for i = 1 to 2
abc.ab & i = "...."
What's wrong?
Thx
How about trying to explain what you are trying to do?
Using arrays would be helpful in your case.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
May 31st, 2007, 06:45 AM
#3
Thread Starter
Lively Member
Re: [2005] String
Public Shared char1 As New sprite("char1")
spirte is a class
And I cant use array in this case
-
May 31st, 2007, 07:08 AM
#4
Re: [2005] String
 Originally Posted by s021126
Public Shared char1 As New sprite("char1")
spirte is a class
And I cant use array in this case
You have still not explained what you are trying to do?
And why can't you use Arrays?
Use [code] source code here[/code] tags when you post source code.
My Articles
-
May 31st, 2007, 07:42 AM
#5
Fanatic Member
Re: [2005] String
You cannot access Properties/Methods/events of a class using enumeration. You have to access them by name.
Myclass.Property1 = x
Myclass.Property2 = x
When you declare a new class object:
Public _myclass as New Myclass
you then use this to access the properties:
_myclass.Property1 = x
_myclass.Property2 = x
If you have defaults for class properties that you want to set with ANY new instantiation (spelling??) of that class then you set it up like this (in the class itself):
Code:
Public Sub New()
Property1 = x
Property2 = x
End Sub
You can also set New to accept arguements and overload itself:
Code:
Public Sub New(ByVal String1 as String, ByVal Int1 as Integer)
Property1 = String1
Property2 = Int1
End Sub
If you already know all of this, then I apologize but I saw what you posted and thought this information may be of some use.
D
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you. 
Please remember to mark threads as closed if your issue has been resolved.
Reserved Words in Access | Connection Strings
-
May 31st, 2007, 09:36 AM
#6
Thread Starter
Lively Member
Re: [2005] String
Let me explain what I say
I am making a game
there are 2 characters.
And I make a class called character
dim char1 as new character
dim char2 as new character
And I make a function
Function result(i as integer) as integer
char1.sth.....
char2.sth
But I don't want to write each line of code twice....
And I write that char & i ,but it can't work
what should I do?
-
May 31st, 2007, 09:47 AM
#7
Fanatic Member
Re: [2005] String
I do not believe there is any way around this with individual variables.
The only thing I can come up with is to create an array of characters and use a for loop to access each one in the array and set the property once:
Code:
For i as integer = 0 to array.length-1
array(i).PropertyName = FunctionName(Byval ParameterName as Type)
Next
Did that on the fly so it will probably need tweaking, but am hoping that it gives you a general idea....
Good Luck!!
D
Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP
Please Rate If I helped you. 
Please remember to mark threads as closed if your issue has been resolved.
Reserved Words in Access | Connection Strings
-
May 31st, 2007, 09:51 AM
#8
Re: [2005] String
 Originally Posted by s021126
Let me explain what I say
I am making a game
there are 2 characters.
And I make a class called character
dim char1 as new character
dim char2 as new character
And I make a function
Function result(i as integer) as integer
char1.sth.....
char2.sth
But I don't want to write each line of code twice....
And I write that char & i ,but it can't work
what should I do?
If you dont want to write each line over and over again, you would need a loop. And what does a loop need? Something to loop through; an array or a collection. You would need to create one of those and populate it with your instances of the character class.
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
|