Hey guys,
(I hope this is the right category for this topic)
I have some problems with Classes! I wrote the following test class:
I also have a Form and a Button in my TestProject, when pressing the button, this happens:
Problem:
The MessageBox shows an empty string (It should display "Test1", shouldn't it? Has somebody an idea why?
(Edit: and has somebody an idea how to post better readable VB code in here? Edit: ahhh, just found it)
(I hope this is the right category for this topic)
I have some problems with Classes! I wrote the following test class:
Visual Basic:
Public Class TestClass
Public Structure structWord
Public ID As Integer
Public Text As String
End Structure
Public Words() As structWord
Public Sub New()
ReDim Words(-1)
AddWord("Test1")
AddWord("Test2")
AddWord("Test3")
End Sub
Private Sub AddWord(ByVal Text As String)
Dim t As Integer
t = UBound(Words) + 1
ReDim Words(t)
Words(t).ID = t
Words(t).Text = Text
End Sub
End Class
I also have a Form and a Button in my TestProject, when pressing the button, this happens:
Visual Basic:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim haha As New TestClass
MsgBox(haha.Words(0).Text)
End Sub
Problem:
The MessageBox shows an empty string (It should display "Test1", shouldn't it? Has somebody an idea why?
(Edit: and has somebody an idea how to post better readable VB code in here? Edit: ahhh, just found it)
Last edited: