【发布时间】:2016-10-04 15:50:33
【问题描述】:
首先,我会说我是新来的,所以我可能无法正确解释我的问题。我使用 VB.Net Windows 窗体应用程序。在这个项目中,我必须从另一个类调用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
【问题讨论】:
-
你有什么理由用 C# 标记这个?
-
displayreport是一个 sub,你将aobj.displayreport分配给不可能的事情。同样在displayreport内部,你只是有一个没有做任何事情的表达式(甚至没有分配给一些本地人)我认为这也会导致问题 -
非常感谢。