起初,我会说我是新来的,所以我可能无法正确解释我的问题。我使用VB.Net Windows Forms应用程序。在这个项目中,我必须从另一个类调用sub
过程,以便在单击按钮时显示报告。 sub
没有返回我知道的值,而且每当我有sub
时我都会习惯这样我将在sub
中显示值但是我不能写出另一个类中的文本框。这些是我的代码,我希望你能理解我的意思。
Public Class Form1
Dim aobj As New Allowance
Dim nam As String
Dim ID, year, allowance, total As Double
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
allowance = txtamount.Text
total = aobj.calculatetotal(allowance)
txtcalculate.ForeColor = Color.Red
txtcalculate.Text = FormatNumber(total)
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
ID = txtid.Text
year = txtyear.Text
nam = txtname.Text
txtreport.ForeColor = Color.Blue
txtreport.Text = aobj.displayreport(nam, ID, year, total)
End Sub
End Class
Class Allowance
Function calculatetotal(ByVal a As Double) As Double
Return (12 * 5 * a)
End Function
Sub displayreport(ByVal nam As String, ByVal id As Double, ByVal y As Double, ByVal tot As Double)
(" The Student " & nam & " with ID: " & id & " will receivce a total allowance of " & tot & " for five years of study in YUC")
End Sub
End Class
答案 0 :(得分:0)
如果要将该字符串分配给txtreport.Text,则需要将displayreport更改为函数并返回该字符串。尝试将其更改为:
Public Function displayreport(ByVal nam As String, ByVal id As Double, ByVal tot As Double) As String
Return " The Student " & nam & " with ID: " & id & " will receivce a total allowance of " & tot & " for five years of study in YUC"
End Function
我也删除了" y为double"因为它没有被使用