我想從我的zooanimal類調用此公共子庫(gutom作爲字符串)到我的form1.vb。作爲參考,請參閱我的代碼。 我總是得到一個錯誤「表達式不會產生一個值」在我Textbox10.text = za.hungrys(gutom作爲字符串)調用子表達式時不會產生一個值
Public Class ZooAnimal
Public Sub New()
hungry = isHungry()
Public Function isHungry() As Boolean
If age > 0 Then
hungry = True
End If
If age <= 0 Then
hungry = False
End If
Return hungry
End Function
Public Sub hungrys(ByRef gutom As String)
If hungry = True Then
gutom = "The zoo animal is hungry"
End If
If hungry = False Then
gutom = "The zoo animal is not hungry "
End If
End Sub
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim za As New ZooAnimal
Dim gutom As String = ""
TextBox10.Text = za.hungrys(gutom)
請閱讀[問]並參加[旅遊]。錯誤是準確的。 'hungrys'是一個子表示它什麼都沒有返回,但是你正試圖分配一個結果,就像你把它寫成一個函數一樣......或者把這個字符串參數分配給文本框。你也應該設置'選項嚴格開' - '年齡'出來 – Plutonix