• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

Passing values new to vb.net 2ND QUESTION

PLEASE SEE MY LAST POST: http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21210943.html

BUT WHAT IF I ADD A 3RD ONE HOW DOES IT KNOW WHICH ONE TO CALL?
0
pigmentarts
Asked:
pigmentarts
  • 5
  • 3
1 Solution
 
pigmentartsAuthor Commented:
or if i want to call the Console.WriteLine(SetupGo.strSetupMessage) it does not work.

sorry about this just want to get my head around it
0
 
pigmentartsAuthor Commented:
all i really want to do is have a lots of class with different strings in which i can call from, any i want. this is not a project i am just playing and tring to understand how classes work.
0
 
koruzicaCommented:
You can have unlimited constructors; but they must differ by parameter types,
becouse thats how language distinguishes between them:

example:

class foo

public sub new()
end sub

public sub new(str as string)
end sub

public sub new(str as string, str2 as string)
end sub

public sub new(str as boolean)
end sub

end class

In this case all the constructors take different parameters (by type)
so if you call

dim class as new foo(TRUE)
it will be
public sub new(str as boolean)
which will be called

Simon
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
koruzicaCommented:
i must correct the example:

If you create a new class with the following call:

dim myClass as new foo(TRUE)

it will be:
public sub new(str as boolean)
which will be called
0
 
pigmentartsAuthor Commented:
i get it thank you, much better understanding, thanks
0
 
pigmentartsAuthor Commented:
but what if i wanted to call another string how does it knwo which one, in your example you have str and str2, so what if i wanted to call both or just one? would this work Dim SetupGo As New Setup( str as string, str2 as string)?
0
 
koruzicaCommented:
exactly :)

So if you need to pass 3 strings to your class,
then you must create new constructor in that class:

public sub new(str1 as string, str2 as string, str3 as string)
end sub

0
 
pigmentartsAuthor Commented:
thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now