一道vb的题我写的程序是Public Class Form1 Subjiecheng(ByRef m%) Dimi%,n%,x% x = 1 Fori = 1 To n x = x * i Next m = x TextBox2.Text = m EndSub PrivateSub Button1_Click(ByValsender

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 10:48:29
一道vb的题我写的程序是PublicClassForm1Subjiecheng(ByRefm%)Dimi%,n%,x%x=1Fori=1Tonx=x*iNextm=xTextBox2.Text=mEn

一道vb的题我写的程序是Public Class Form1 Subjiecheng(ByRef m%) Dimi%,n%,x% x = 1 Fori = 1 To n x = x * i Next m = x TextBox2.Text = m EndSub PrivateSub Button1_Click(ByValsender
一道vb的题

我写的程序是

Public Class Form1
    Subjiecheng(ByRef m%)
        Dimi%,n%,x%
        x = 1
        Fori = 1 To n
            x = x * i
        Next
        m = x
        TextBox2.Text = m
    EndSub
    PrivateSub Button1_Click(ByValsender As System.Object,ByVal e AsSystem.EventArgs) Handles Button1.Click
        Dimn%
        n = Val(TextBox1.Text)
        IfRadioButton1.Checked = True Then
            jiecheng(n)
        Else
            jiecheng(n + 2)
        EndIf
    EndSub
End Class
运行结果总出错求大神解答

一道vb的题我写的程序是Public Class Form1 Subjiecheng(ByRef m%) Dimi%,n%,x% x = 1 Fori = 1 To n x = x * i Next m = x TextBox2.Text = m EndSub PrivateSub Button1_Click(ByValsender
Public Class Form1

    Sub jiecheng(m%)
    
        Dim i%, n%, x%
    
        n = m

        x = 1

        For i = 1 To n

            x = x * i

        Next

        TextBox2.Text = x

    End Sub

    Private Sub Button1_Click(ByValsender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click

        Dim n%

        n = Val(TextBox1.Text)

        If RadioButton1.Checked = True Then

            jiecheng(n)

        Else

            jiecheng(n + 2)

        End If

    End Sub

End Class
试试,
最主要的问题在于 jiecheng 函数 没有取得 n 的值,反而跟一个不相关的变量 m 纠缠不清.