1 / 17

Visual Basic 程式語言初體驗

Visual Basic 程式語言初體驗. 台東高中 哈熊老師. 認識 VB. Label. TextBox. 常用工具箱物件. CommandButton. Image. 一個物件有著許多的屬性 使用方式 : 物件名稱 . 屬性名稱 = xxx 假設目前使用文字方塊 (textbox) 而此物件 Name 是 T1 假設要設定文字方塊顯示資料內容則為 T1.text = “Hello 大家好” 要設定文字大小則為 T1.fontsize = 20 設定方塊大小則為 T1.Width = 2000. 程式發射器.

Download Presentation

Visual Basic 程式語言初體驗

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程式語言初體驗 台東高中 哈熊老師

  2. 認識VB

  3. Label TextBox 常用工具箱物件 CommandButton Image

  4. 一個物件有著許多的屬性 使用方式 : 物件名稱.屬性名稱= xxx 假設目前使用文字方塊(textbox) 而此物件Name是T1 假設要設定文字方塊顯示資料內容則為T1.text = “Hello大家好” 要設定文字大小則為 T1.fontsize = 20 設定方塊大小則為 T1.Width = 2000

  5. 程式發射器 • Command1.Caption=“小畫家” • Shell “執行程式的路徑” , vbNormalFocus (Shell用來呼叫程式) • Msgbox “版權蔡女東所有,不可以拷貝!” (message box縮寫,” ”內放入要顯示的字串) • Windows程式路徑 : 直接到執行程式的連結處, 按滑鼠右鍵內容,路徑就在顯示在”目標” 作業 : 舉一反三,將彈珠台,ie等自己喜歡的程 式加入二至三項

  6. VB的運算符號

  7. 計算機 • Textbox 文字方塊, 切記輸入的資料是字串,不是數值(數值才可以+,-,*,/)=> Val(T1.text ) • 如何清除預設值 ? 將textbox的text屬性內容砍掉 • 小心 : Text容易打成test (text:文字,test:測試) • 語法: 方塊三=方塊一 + 方塊二 人類語言大戰電腦語言 結果? Text3.text = Text1.text + Text2.text Val( 資料 ) 用來將字串轉換成數值 舉一反三 : 將 - , *, / 功能都做出來

  8. 密碼檢查 單線式 If A=“哈熊” then msgbox “很好,帳號輸入正確” End If 雙線式 If A=“哈熊” then msgbox “很好,帳號輸入正確” Else msgbox “亂來伊通” Endif

  9. 條件判斷IF 二、兩種選擇流程控制:If…Then…Else…End If 一、單一選擇流程控制:If…Then 假如我考及格, 媽媽買玩具給我(A) 不及格則什麼事都沒發生 假如我考及格,媽媽會買玩具给我(A) 但是若不及格,零用錢全部沒收(B)

  10. 語法: If <條件式> Then • <敘述> • End If • 說明:如果<條件式>成立,就執行 • Then後面的<敘述>;否則繼續執行下一行。 • 範例:成績 • If x > 60 Then • MsgBox “歐爺,有玩具了” • EndIf If心法Part2 If心法Part1 語法: If <條件式> Then <敘述1> ‘條件成立 Else <敘述2> ‘條件不成立 End If 說明:如果<條件式>成立,就執行 Then 後面的<敘述1>; 否則執行<敘述2>。 If x > 60 Then MsgBox “歐爺,有玩具了”‘條件成立 Else MsgBox “賣擱打我啦,我不敢啦~嗚嗚” ‘條件不成立 End If

  11. 三、巢狀If/Then敘述 假如我考及格,媽媽就不會打我屁屁,若不及格就會…,假如我及格而且成績大於等於80,就可以買無敵鐵金剛,只有落於60~80(不含80),媽媽會請我吃冰

  12. 四、直線式多重選擇 語法: If <條件式1> Then 判斷條件1 <敘述1> ‘條件成立1 ,執行敘述1 Elseif <條件式2> Then‘敘述1不成立,判斷條件2 <敘述2> ‘條件2成立,執行敘述2 Elseif <條件式3> Then ‘敘述1,2都不成立,判斷條件3 <敘述3> ‘條件3成立,執行敘述3 Elseif <條件式4> Then ‘敘述1,2,3都不成立,判斷條件3 <敘述4> ‘條件4成立,執行敘述4 Else <敘述5> ‘以上全都不成立,執行敘述5 End If

  13. 電腦的邏輯觀念 • A > 5 and A <=10 請問若A=5成立嗎? A=7成立嗎? A=12成立嗎? • 若改成A > 5 or A <=10呢? • “東中想要合併” 而且(And) “東女想要合併”=>才可合併 • 女生追求 And 男生點頭 => 才有交往機會 • “預先請假” 或者(Or) “當天打電話給教官”=>不被記曠課 • 全班翹課 Or 老師翹班 =>無法上課

  14. 龜兔賽跑 • Image物件的使用,圖片的X座標即Image1.left, Y座標即Image1.top • 何謂抵達終點? • 想要採用亂數跑的方式: - Randomize Timer (利用時間來當隨機亂數) - Image1.left = Image1.left + Rnd*300 - Rnd是亂數的種子範圍>=0,<1的小數點區間,所以*300則範圍加大到>=0, <300

  15. 如何請程式幫我們執行重複動作n次? • 迴圈結構 For 迴圈變數 = 初始值 to 終止值 step 變量 程式區塊 Next • 印出20個Hello For i=1 to 20 step 1 msgbox (“hello”) Next 設計出程式可以從1+2+3+4+5….+100 ?或1+3+5+…99 ? 或 1*2*3*4*…*10 Sum = 0 For i = 1 To 10 Step 2 Sum = Sum + I Next Print Sum

  16. 多重條件選擇(12星座) If Text2 = 0 Then m = 0 End If Select Case m Case 1: Image13 = Image1 Case 2: Image13 = Image2 Case 3: Image13 = Image3 Case 4: Image13 = Image4 Case 5: Image13 = Image5 Case 6: Image13 = Image6 Case 7: Image13 = Image7 Case 8: Image13 = Image8 Case 9: Image13 = Image9 Case 10: Image13 = Image10 Case 11: Image13 = Image11 Case 12: Image13 = Image12 Case Else: Label4.Visible = True End Select End Sub Dim m As Integer Dim d As Integer Private Sub Command1_Click() Select Case Text1 Case 1, 3, 5, 7, 8, 10, 12: d = 31 Case 4, 6, 9, 11: d = 30 Case 2: d = 29 Case Else: m = 0 End Select If Text2 > 20 Then m = Val(Text1) + 1 If m = 13 Then m = 1 End If Else m = Text1 End If

  17. 各位東女童鞋,恭喜妳們通過初級考驗

More Related