我想从我的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