VB 2008-运行时问题

时间:2013-12-03 09:00:38

标签: vb.net

这是我的程序代码....

Public Class Form1
    Dim adult As Decimal
    Public Function getadult(ByRef adult As Decimal) As Decimal
        Return adult
    End Function
    Public Function setadult(ByVal value As Decimal) As Decimal
        value = adult
    End Function
    Public Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call setadult(adult)
        TextBox1.Text = adult

    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim adult As Decimal
        Call getadult(adult)
        MsgBox("the rate for adults is " & adult)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

当我在文本框中输入一个值并按下“设置”按钮时,它会重置为0.请帮助我

2 个答案:

答案 0 :(得分:0)

Public Function setadult(ByVal value As Decimal) As Decimal
        **value = adult**
    End Function

应该是..

Public Function setadult(ByVal value As Decimal) As Decimal
        **adult = value**
    End Function

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        **Dim adult As Decimal** <<<< Remove this

但我真的不明白你为什么要用两个函数设置并获得成人的价值。要么直接设置,要么使用属性。 对于前者

Public Function getadult(ByRef adult As Decimal) As Decimal
        Return adult
    End Function

这将只返回传递给函数O.o

的值

也许这就是你想要实现的目标:

Public Class Form1

    Dim adult As Decimal

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        adult = CDec(TextBox1.Text)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        MsgBox("the rate for adults is " & adult.toString())
    End Sub

End Class

答案 1 :(得分:0)

成人没有收据价值。 TEST Edit按钮1单击call setadult(textBox1.text)。

Public Class Form1
    Dim adult As Decimal
    Public Function getadult(ByRef adult As Decimal) As Decimal
        Return adult
    End Function
    Public Function setadult(ByVal value As Decimal) As Decimal
        value = adult
    End Function
    Public Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call setadult(textBox1.text)

    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim adult As Decimal
        Call getadult(adult)
        MsgBox("the rate for adults is " & adult)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class