2017年11月21日 星期二

[ VB2010 ] - 007 副程式流程003


[ VB2010 ] - 007 副程式流程003

Optional 用來宣告參數帶有預設值:


●參數透過傳參照的方式傳遞陣列:


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox3.Text = CStr(SubProg0003())
    End Sub

    Function SubProg0003(Optional ByVal Param1 As Integer = 1234, Optional ByVal Param2 As Integer = 5678) As Integer

        TextBox1.Text = CStr(Param1)
        TextBox2.Text = CStr(Param2)
        SubProg0003 = Param1 + Param2

    End Function

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

        A(0) = 123
        A(1) = 456
        TextBox3.Text = CStr(SubProg0004(A))

    End Sub

    Function SubProg0004(ByRef A() As Integer)
        TextBox1.Text = CStr(A(0))
        TextBox2.Text = CStr(A(1))
        SubProg0004 = A(0) + A(1)
    End Function

End Class

沒有留言:

張貼留言

WOKWI LED + MQTT Node-Red SQLite

WOKWI LED + MQTT Node-Red SQLite const char *mqtt_broker = "broker.mqtt-dashboard.com" ; const char *topic1 = "alex9ufo/e...