【发布时间】:2017-09-27 00:21:39
【问题描述】:
我想将我的 zooanimal 类中的这个公共子饥饿(gutom 作为字符串)称为我的 form1.vb。供参考,请参阅我的代码。 我的 Textbox10.text = za.hungrys(gutom as string) 中总是出现错误“表达式不产生值”
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)
【问题讨论】:
-
请阅读How to Ask 并使用tour。错误是准确的。
hungrys是一个 sub ,这意味着它什么也不返回,但是您正试图分配一个结果,就好像您将它编写为一个函数一样......或者将该字符串参数分配给文本框。您还应该设置Option Strict On-age不知从何而来