2017年11月22日 星期三

物件導向 / Object orientation [ VB2010 ] - 002 類別成員 001

物件導向 / Object orientation [ VB2010 ] - 002 類別成員 001

當把變數宣告為類別,在變數後打上點符號,VB 會自動列出一堆東西可以選擇,這些東西就是該類別的成員:





●VB 最簡單的類別成員就是宣告為 Public 變數:
Public Class Form1

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

    End Sub

    Class Vehicle
        Public SkinColor As Color
    End Class

End Class

●該類別的變數就多了 SkinColor 可被使用:



Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x As Vehicle = New Vehicle
        x.SkinColor = Color.Olive
        Me.BackColor = x.SkinColor
    End Sub

    Class Vehicle
        Public SkinColor As Color
    End Class
End Class

●執行後按下 Button1 後的結果:


沒有留言:

張貼留言

2026 作業3 RFID+ Telegram 練習

 2026 作業3  RFID+ Telegram  練習 (Wokwi 與 Telegram 二者溝通訊息反映比較慢 ) 歡迎 Alex 使用 RFID 控制系統 /on : 開啟 LED /off : 關閉 LED /flash : 閃爍模式 /timer : 開啟 5 秒 ...