1 / 10

程式語言與邏輯 ( Ⅱ )

程式語言與邏輯 ( Ⅱ ). Visual Basic 常用函數. InputBox ( 輸入 ) 傳回值 = InputBox( 提示訊息,標題,預設值, X 位置, Y 位置) 例如: a = InputBox("Please input a", "This is a test", 300, 10, 10) MsgBox ( 輸出 ) 傳回值 = MsgBox( 提示訊息,格式碼,標題) 格式碼 是用來指定輸出方塊的格式,表列如下: 按鈕顯示組:. Visual Basic 常用函數. 圖示組:

daxia
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. 程式語言與邏輯(Ⅱ)

  2. Visual Basic 常用函數 • InputBox (輸入) 傳回值 = InputBox(提示訊息,標題,預設值,X位置,Y位置) 例如: a = InputBox("Please input a", "This is a test", 300, 10, 10) • MsgBox (輸出) 傳回值 = MsgBox(提示訊息,格式碼,標題) 格式碼是用來指定輸出方塊的格式,表列如下: 按鈕顯示組:

  3. Visual Basic 常用函數 圖示組: 傳回值:MsgBox傳回的值即代表使用者所按下的按鈕,可能的值為:

  4. Visual Basic 常用函數 • 常用的數學函數:

  5. Visual Basic 常用函數 • 常用的數學函數:

  6. Visual Basic 常用函數 • 轉換函數 Asc, Chr, and Hex Asc函數可將引數中字串的第一個字元轉換為 ASCII 碼。使用方法:a = Asc(string) Chr 函數是 Asc 函數的反函數,可將一 0~127(或 0~256) 之整數所對應的字元傳回來 Hex函數可將一十進位整數換算成 16 進位碼,如 Hex(10) 可得到 A,Hex(255) 可得到 FF 等。

  7. Visual Basic 常用函數 • 字串函數 Len, Left, Right, Mid Len(string): 計算字串長度,傳回一整數 Left(string, length): 將字串由左而右數來長度 = length 的部分切割下來,傳回此部分字串 Right(string, length): 將字串由右而左數來長度 = length 的部分切割下來,傳回此部分字串 Mid(string, start_position, length): 將字串從左而右數過來第 start_position 的字元開始,往右擷取長度為 length 的部分切割下來,傳回此部分字串

  8. 範例(樂透號碼產生模擬器) • 設計一個程式,可模擬產生樂透號碼,數字範圍在1-42之間,每組中之六個數字不得重複,執行範例如下:

  9. 開始 輸出結果 參數宣告 i,j,tmp,a(6),rst 結束 產生1-42間 之ㄧ個亂數 清空輸出變數 是否與前面產 生之數值相同? 是 6個數字 產生完畢? 是 否 紀錄數值 否 程式流程圖(樂透號碼產生模擬器)

  10. 程式碼(樂透號碼產生模擬器) Dim rst As String Dim i, j, tmp, a(6) As Integer rst = "" For i = 1 To 6 re: Randomize() tmp = Int(Rnd() * 42) + 1 If i > 1 Then For j = 1 To i - 1 If tmp = a(j) Then GoTo re End If Next a(i) = tmp rst = rst & tmp & " “ Else a(i) = tmp rst = rst & tmp & " " End If Next L1.Text = rst

More Related