2017年11月21日 星期二

[ VB2010 ] - 007 副程式流程002

[ VB2010 ] - 007 副程式流程002

副程式名稱後面括號裡面可以有參數(邏輯設定,Parameter),用來設定傳遞引數(實質資料,Argument)類型,傳遞資料的方式有傳值與傳參照兩種:


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ans1 As String
        Dim A As Integer
        Dim B As Integer

        A = 123
        B = 456
        TextBox1.Text = CStr(A)
        TextBox2.Text = CStr(B)
        ans1 = CStr(SubProg0001(A, B))
        TextBox5.Text = ans1

    End Sub


     Function SubProg0001(ByVal Param1 As Integer, ByVal Param2 As Integer) '傳值

        TextBox3.Text = CStr(Param1)
        TextBox4.Text = CStr(Param2)

        SubProg0001 = Param1 + Param2

    End Function

    Function SubProg0002(ByRef Param1 As Integer, ByRef Param2 As Integer) '傳參照

        TextBox3.Text = CStr(Param1)
        TextBox4.Text = CStr(Param2)

        SubProg0002 = Param1 + Param2

    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim ans1 As String
        Dim A As Integer
        Dim B As Integer

        A = 321
        B = 654
        TextBox1.Text = CStr(A)
        TextBox2.Text = CStr(B)
        ans1 = CStr(SubProg0002(A, B))
        TextBox5.Text = ans1
    End Sub
End Class

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...