How do I make this work?

R

Ron

I have a couple of questions about this class.....:
Public Class WordPair
Private word1 As String
Private word2 As String
Public Sub New()
word1 = ""
word2 = ""
End Sub
Public Sub New(ByVal w1 As String, ByVal w2 As String)
word1 = w1
word2 = w2
End Sub
Public Property first() As String
Get
Return word1
End Get
Set(ByVal w1 As String)
word1 = w1
End Set
End Property
Public Property second() As String
Get
Return word2
End Get
Set(ByVal w2 As String)
word2 = w2
End Set
End Property
Public Function isFull() As Boolean
'Determines if a WordPair object contains both words
End Function

I then have a form that has a button, display, a testbox and a
label. I want to give the class an object called ones and then
twoes

I then want to fill ones word1 with smoke and word2 with alarm
After the pressing the button the label would display word1 and word2,
but they would actually have the values smoke and alarm in them/?

How do I do something like this?
 
R

Ron

Yes sort of although not for a grade just to learn classes, i just
dont know where to start with this.
 
R

RobinS

You need to instantiate your new class, and you can use your constructor
that takes both arguments; then you can access the properties [first] and
[second] for that object.

ones = new WordPair("smoke", "alarm")
debug.print(ones.first) --> smoke
debug.print(ones.second) --> alarm

Robin S.
-------------------------------
 
R

Ron

Here is what I did, I created a new module and did this:
Module word
Dim ones As New WordPair
Dim twos As New WordPair
wordpair.ones = ("","")
wordpair.twos=("smoke","alarm")

End Module

What it is doing now is underlining in blue WORDPAIR and says
decleration expected ?


You need to instantiate your new class, and you can use your constructor
that takes both arguments; then you can access the properties [first] and
[second] for that object.

ones = new WordPair("smoke", "alarm")
debug.print(ones.first) --> smoke
debug.print(ones.second) --> alarm

Robin S.



Yes sort of although not for a grade just to learn classes, i just
dont know where to start with this.

- Show quoted text -
 
R

RobinS

You have to tell it what you're defining them as before "new-ing" them.

Dim ones as WordPair = New WordPair()
Dim twos as WordPair = New WordPair()

Robin S.
--------------------------

Ron said:
Here is what I did, I created a new module and did this:
Module word
Dim ones As New WordPair
Dim twos As New WordPair
wordpair.ones = ("","")
wordpair.twos=("smoke","alarm")

End Module

What it is doing now is underlining in blue WORDPAIR and says
decleration expected ?


You need to instantiate your new class, and you can use your constructor
that takes both arguments; then you can access the properties [first]
and
[second] for that object.

ones = new WordPair("smoke", "alarm")
debug.print(ones.first) --> smoke
debug.print(ones.second) --> alarm

Robin S.
message



Yes sort of although not for a grade just to learn classes, i just
dont know where to start with this.
On Feb 15, 3:51 pm, "Cor Ligthert [MVP]" <[email protected]>
wrote:
Homework?
"Ron" <[email protected]> schreef in
berichtnews:[email protected]...
I have a couple of questions about this class.....:
Public Class WordPair
Private word1 As String
Private word2 As String
Public Sub New()
word1 = ""
word2 = ""
End Sub
Public Sub New(ByVal w1 As String, ByVal w2 As String)
word1 = w1
word2 = w2
End Sub
Public Property first() As String
Get
Return word1
End Get
Set(ByVal w1 As String)
word1 = w1
End Set
End Property
Public Property second() As String
Get
Return word2
End Get
Set(ByVal w2 As String)
word2 = w2
End Set
End Property
Public Function isFull() As Boolean
'Determines if a WordPair object contains both words
End Function
I then have a form that has a button, display, a testbox and a
label. I want to give the class an object called ones and then
twoes
I then want to fill ones word1 with smoke and word2 with alarm
After the pressing the button the label would display word1 and
word2,
but they would actually have the values smoke and alarm in them/?
How do I do something like this?- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
R

Ron

OK thanks that makes sense.
So what if I want to display Smoke and Alarm, those values in a label
do I just:
labelword.text = "1st word =" & word1 & "2nd word =" & word2 ?


You have to tell it what you're defining them as before "new-ing" them.

Dim ones as WordPair = New WordPair()
Dim twos as WordPair = New WordPair()

Robin S.
--------------------------




Here is what I did, I created a new module and did this:
Module word
Dim ones As New WordPair
Dim twos As New WordPair
wordpair.ones = ("","")
wordpair.twos=("smoke","alarm")
End Module
What it is doing now is underlining in blue WORDPAIR and says
decleration expected ?
You need to instantiate your new class, and you can use your constructor
that takes both arguments; then you can access the properties [first]
and
[second] for that object.
ones = new WordPair("smoke", "alarm")
debug.print(ones.first) --> smoke
debug.print(ones.second) --> alarm
Robin S.
message

Yes sort of although not for a grade just to learn classes, i just
dont know where to start with this.
On Feb 15, 3:51 pm, "Cor Ligthert [MVP]" <[email protected]>
wrote:
Homework?
"Ron" <[email protected]> schreef in
bericht
I have a couple of questions about this class.....:
Public Class WordPair
Private word1 As String
Private word2 As String
Public Sub New()
word1 = ""
word2 = ""
End Sub
Public Sub New(ByVal w1 As String, ByVal w2 As String)
word1 = w1
word2 = w2
End Sub
Public Property first() As String
Get
Return word1
End Get
Set(ByVal w1 As String)
word1 = w1
End Set
End Property
Public Property second() As String
Get
Return word2
End Get
Set(ByVal w2 As String)
word2 = w2
End Set
End Property
Public Function isFull() As Boolean
'Determines if a WordPair object contains both words
End Function
I then have a form that has a button, display, a testbox and a
label. I want to give the class an object called ones and then
twoes
I then want to fill ones word1 with smoke and word2 with alarm
After the pressing the button the label would display word1 and
word2,
but they would actually have the values smoke and alarm in them/?
How do I do something like this?- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
R

RobinS

No, word1 and word2 are private within the class. Go back down and look at
my example that prints out the results.

Robin S.
-----------------------------------
Ron said:
OK thanks that makes sense.
So what if I want to display Smoke and Alarm, those values in a label
do I just:
labelword.text = "1st word =" & word1 & "2nd word =" & word2 ?


You have to tell it what you're defining them as before "new-ing" them.

Dim ones as WordPair = New WordPair()
Dim twos as WordPair = New WordPair()

Robin S.
--------------------------




Here is what I did, I created a new module and did this:
Module word
Dim ones As New WordPair
Dim twos As New WordPair
wordpair.ones = ("","")
wordpair.twos=("smoke","alarm")
End Module
What it is doing now is underlining in blue WORDPAIR and says
decleration expected ?
You need to instantiate your new class, and you can use your
constructor
that takes both arguments; then you can access the properties [first]
and
[second] for that object.
ones = new WordPair("smoke", "alarm")
debug.print(ones.first) --> smoke
debug.print(ones.second) --> alarm
Robin S.
message

Yes sort of although not for a grade just to learn classes, i just
dont know where to start with this.
On Feb 15, 3:51 pm, "Cor Ligthert [MVP]" <[email protected]>
wrote:
Homework?
"Ron" <[email protected]> schreef in
berichtnews:[email protected]...
I have a couple of questions about this class.....:
Public Class WordPair
Private word1 As String
Private word2 As String
Public Sub New()
word1 = ""
word2 = ""
End Sub
Public Sub New(ByVal w1 As String, ByVal w2 As String)
word1 = w1
word2 = w2
End Sub
Public Property first() As String
Get
Return word1
End Get
Set(ByVal w1 As String)
word1 = w1
End Set
End Property
Public Property second() As String
Get
Return word2
End Get
Set(ByVal w2 As String)
word2 = w2
End Set
End Property
Public Function isFull() As Boolean
'Determines if a WordPair object contains both words
End Function
I then have a form that has a button, display, a testbox and a
label. I want to give the class an object called ones and
then
twoes
I then want to fill ones word1 with smoke and word2 with alarm
After the pressing the button the label would display word1 and
word2,
but they would actually have the values smoke and alarm in
them/?
How do I do something like this?- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top