Dobrý večer. Pokúšam sa pochopiť prácu s triedami a jednej veci nerozumiem, samozrejme je ich viac, ale teraz mi nefunguje toto: Mám triedu:
Public Class Trieda1
'''' <summary>
'''' Vypočíta súčet čísel
'''' </summary>
'''' <param name="cislo1"></param>
'''' <param name="cislo2"></param>
'''' <remarks></remarks>
'Sub New(ByVal cislo1 As Integer, ByVal cislo2 As Integer)
' MsgBox(cislo1 + cislo2)
' Return
'End Sub
'''' <summary>
'''' Zapíše a vypočíta rozdiel
'''' </summary>
'''' <param name="text1"></param>
'''' <param name="cislo2"></param>
'''' <param name="cislo3"></param>
'''' <remarks></remarks>
'Sub New(ByVal text1 As String, ByVal cislo2 As Integer, ByVal cislo3 As Integer)
' MsgBox(text1 & ": " & cislo2 - cislo3)
'End Sub
Private _text2 As String
''' <summary>
''' Zadaj alebo získaj Text2
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Text2() As String
Get
Return _text2
End Get
Set(ByVal value As String)
_text2 = value
End Set
End Property
''' <summary>
''' Vypíše Txt2 v MsgBox
''' </summary>
''' <remarks></remarks>
Public Sub Zobraz()
MsgBox(_text2)
End Sub
End Class
ktorú volám z Form1
Public Class Form1
Dim c As Trieda1
'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' c = New Trieda1(1, 2)
'End Sub
'Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' c = New Trieda1("Toto je iné kafe ", 13, 7)
'End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
c = New Trieda1
c.Text2 = "No toto!"
c.Zobraz()
End Sub
End Class
a funguje mi to buď zavolaním z Button1 a Button2, teraz je to zeleným, alebo Button3. Súčasne to nefunguje. Vysvetlil by mi niekto, prosím, čomu ešte nerozumiem.
|