If you are trying to get a value out of a Sub
with a ByRef
parameter rather than the return value of a Function
then this:
TextBox10.Text = za.hungrys(gutom)
would need to be this:
za.hungrys(gutom)
TextBox10.Text = gutom
The first line calls the Sub
and assigns a new value to the variable and the second line displays the variable's value in the TextBox
.
Unless it's as a learning exercise though, there's no good reason to use a ByRef
parameter there. You'd normally write that method like this:
Public Function hungrys() As String
Dim gutom As String
If hungry Then
gutom = "The zoo animal is hungry"
Else
gutom = "The zoo animal is not hungry "
End If
Return gutom
End Sub
and then call it like this:
Dim gutom As String = za.hungrys()
TextBox10.Text = gutom
or just:
TextBox10.Text = za.hungrys()
Notice that that method uses an If...Else
rather than two separate If
blocks.
By the way, that is a terrible, terrible name for a method. Firstly, it should start with an upper-case letter. Secondly, "hungrys" doesn't tell you what the method does. If I read that with no context, I'd have little idea what it's purpose was.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…