1 / 16

程式設計

程式設計. Visual Basic 簡介 週次: 4 建國技術學院 資管系 饒瑞佶 2003 年 10 月 18 日. 儲存專案. .vbp :專案檔,儲存與專案相關的資訊 .frm :表單檔,儲存與表單相關的資訊(包含程式碼) .scc :程式碼管理檔案 .vbw :記錄 VB 工作環境中表單視窗或程式視窗最後的位置及 大小。刪除此一檔案對專案並沒有任何影響. 開啟專案. 可以在專案檔上使用滑鼠左鍵快按兩下或 由 VB 的環境中選擇檔案 開啟舊檔. 製作 EXE 檔案. 由 VB 的環境中選擇檔案 製成 XXX.EXE

luke-foley
Télécharger la présentation

程式設計

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 程式設計 Visual Basic簡介 週次:4 建國技術學院 資管系 饒瑞佶 2003年10月18日

  2. 儲存專案 .vbp:專案檔,儲存與專案相關的資訊 .frm:表單檔,儲存與表單相關的資訊(包含程式碼) .scc:程式碼管理檔案 .vbw:記錄VB 工作環境中表單視窗或程式視窗最後的位置及 大小。刪除此一檔案對專案並沒有任何影響

  3. 開啟專案 可以在專案檔上使用滑鼠左鍵快按兩下或 由VB的環境中選擇檔案開啟舊檔

  4. 製作EXE檔案 由VB的環境中選擇檔案製成 XXX.EXE 可攜性依程式的複雜度而定

  5. 副程式 • 將可以重複使用的程式區塊獨立而成 寫在Private Sub 函數名稱() 副程式碼 End Sub • 呼叫副程式 可以使用call或直接使用副程式的姓名 課本p.5-56, ch5_15

  6. 函數 • 內定函數,如Time, date, cls, line • 自訂函數 寫在 Function 函數名稱() 程式碼 函數名稱=傳回值 End Function • 可以有傳回值 • 直接使用其函數名接上參數就可以使用

  7. 偵測鍵盤按鍵 使用 KeyPress事件,並由KeyAscii 參數接收哪一個按鍵被按下 物件_KeyPress(KeyAscii As Integer) ch=Chr (KeyAscii) 將KeyAscii轉成字元 Keyascii=Asc (ch) 將ch轉成ASCII碼 範例CH5_1, p.5-3

  8. 範例CH5_1, p.5-3 ' ----------------------------------------------- ' 物件名稱:Form 事件名稱:KeyPress - ' 只要有按鍵發生即產生此事件,若是按q或Q鍵則程 - ' 式執行結束 - ' ----------------------------------------------- Private Sub Form_KeyPress(KeyAscii As Integer) ch = Chr(KeyAscii) If ch = "q" Or ch = "Q" Then ' 檢查是否按q或Q End ' 若是則程式結束 End If End Sub

  9. DblClick 表示連續按下兩次滑鼠鍵所觸發的事件 配合範例ch5_1加入DblClick事件CLS

  10. Paint事件 • 視窗大小改變時 (也會有ReSize事件) • 視窗部分內容被遮住時 範例ch5_3 Private Sub Form_Paint() Cls For i = 1 To num Print "歡迎使用Visual Basic 6" Next i End Sub 只要把AutoRedraw屬性設定為True就可以

  11. 繪圖 使用line函式 Line (起始x,起始y) - (終點x,終點y) VB座標原點與繪圖單位Twip 1吋=72 Pixel 1 Twip = 1/20 pixel

  12. 偵測滑鼠按鍵 MouseDown與MouseUP中的Button屬性

  13. 範例CH5_6, p.5-20 Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If (Button = 1) Then ' 按滑鼠左邊鍵 xpt(num) = X ' 記住滑鼠位置 ypt(num) = Y PSet (X, Y) ' 在滑鼠位置繪點 num = num + 1 End If If (Button = 2) Then ' 按滑鼠右邊鍵 For i = 0 To num - 2 ' 將各點連線 For j = i + 1 To num - 1 Line (xpt(i), ypt(i))-(xpt(j), ypt(j)) Next j Next i End If End Sub

  14. 偵測滑鼠移動 MouseMove的Button與Shift屬性 (ch5_8 & DrawWidth)

  15. 輸入輸出資料對話框 輸入使用內定函數 InputBox InputBox 提示訊息,[標題],[輸入預設值],[xpos,ypos] 輸出使用MsgBox MsgBox 回應訊息,視窗類型,標題 視窗類型如p.5-49

  16. 表單視窗屬性 表單視窗屬性

More Related