大纲31的介绍32简单程式列印列文字33增加一整数

上传人:xmg****18 文档编号:120078339 上传时间:2020-02-02 格式:PPT 页数:38 大小:1.12MB
返回 下载 相关 举报
大纲31的介绍32简单程式列印列文字33增加一整数_第1页
第1页 / 共38页
大纲31的介绍32简单程式列印列文字33增加一整数_第2页
第2页 / 共38页
大纲31的介绍32简单程式列印列文字33增加一整数_第3页
第3页 / 共38页
大纲31的介绍32简单程式列印列文字33增加一整数_第4页
第4页 / 共38页
大纲31的介绍32简单程式列印列文字33增加一整数_第5页
第5页 / 共38页
点击查看更多>>
资源描述

《大纲31的介绍32简单程式列印列文字33增加一整数》由会员分享,可在线阅读,更多相关《大纲31的介绍32简单程式列印列文字33增加一整数(38页珍藏版)》请在金锄头文库上搜索。

1、Visual basic net 講義 1 大綱 3 1介紹 3 2簡單程式 列印列文字 3 3增加一整數程式 3 4記憶體使用概念 3 5數學 3 6決策訂定 指定及關係運算子 3 7使用對話框顯示訊息 第三章 Visual 的介紹 Visual basic net 講義 2 3 1介紹 本章介紹 控制台應用程式 文字形式的應用程式 輸出顯示在命令列下的應用程式 介紹基本的程式基本語法及觀念 Visual basic net 講義 3 3 2 列印列文字 hello world 簡單程式 列印列文字 程式執行時 輸出顯示在命令列視窗 顯示 的基本語法特徵 註解使用 控制台應用程式使用一般模組

2、 module Sub 程序 Chiang ho 大綱 4 helloworld vb 程式輸出 1 helloworld vb 2 Simple console program 3 4 Module helloworld 5 main 6 Sub Main 7 Console Write hello world 8 End Sub 9 10 End Module modFirstWelcome hellowworld 單引號使用於註解 Visual Basic net控制台應用程 式呼叫一般模組 module sub Main 程序為程式執行的進 入點 控制台應用程式敘述顯示文字輸出 程式特

3、徵 註解 程式說明 一般模組 控制台應用程式起始 mod 模組 程序 程式執行的基本單位描述statement主體 Visual basic net 講義 5 3 2 單步執行以 hello world為例 V 的單步執行的產生及執行 執行的 shortcut a alt f5 執行 b f5 執行 c f10 除錯執行 step into d f11 除錯執行 step over 除錯視窗 a auto 視窗 b stack視窗 Visual basic net 講義 6 3 2單步執行以 hello world為例 1 產生 選擇 File New Project 左邊窗格 選擇 Visu

4、al Basic Projects 右邊窗格 選擇 Console Application 命名 hello world 設定路徑 2 檔案重新命名 於專案視窗快點module1 vb 於屬性視窗改變檔案名稱 name 屬性 為helloworld Visual basic net 講義 7 3 2列印列文字 hello world Fig 3 2產生控制台應用程式對話框 左邊窗格右邊窗格 計畫檔名稱 檔案位置 Helloworld Visual basic net 講義 8 3 2列印列文字 hello world Fig 3 3控制台應用程式的整合發展環境 程式碼輯視窗 包含程式碼 Vis

5、ual basic net 講義 9 3 2列印列文字 hello world Fig 3 4重新命名 專案視窗 名稱 Name屬性 快點 Module1 vb 顯 示屬性 屬性視窗 Visual basic net 講義 10 3 2列印列文字 hello world 3 改變module 一般模組名稱 在程式碼編輯視窗中修正模組名稱 以hellowworld 取代 4 編碼 在 Sub Main and End Sub之間編碼 編輯類別名稱及點運算子 後 IntelliSense 的功能顯示 顯 示類別的成員 編輯呼叫程序時參數的資訊自動會顯示 Visual basic net 講義 11

6、 3 2列印列文字 hello world 5 執行程式 編譯 選擇 Build Build Solution 產生新的執行檔於專案目錄下 命名 hellowworld exe 直接執行 Start Without Debugging 單部除錯執行 step over step into Visual basic net 講義 12 3 2列印列文字 hello world Fig 3 5 ide IntelliSense特徵 Partially typed member成員列表 成員描述 highlight Visual basic net 講義 13 3 2列印列文字 hello worl

7、d Fig 3 6參數資訊視窗參數列表清單 向上箭頭向下箭頭 參數列表清單 參數資訊視窗 Visual basic net 講義 14 3 2列印列文字 hello world Fig 3 7執行程式 命令列視窗使用者按下任一鑑程式結 束 Visual basic net 講義 15 3 2列印列文字 hello world Fig 3 8IDE 指出錯誤 省略小括弧 文法錯誤 藍色底線字代表 文法錯誤 任務列表清單 錯誤描述 Chiang ho 大綱 16 Welcome2 vb Program Output 1 Fig 3 9 helloworld vb 2 Writing line of

8、 text with WriteLine的方法從下一行開始 multiple statements 3 4 Module helloworld 5 6 Sub Main 7 Console Write hello 8 Console WriteLine world 9 End Sub Main 11 12 End Module modSecondWelcome helloworld Write的方法從下一字元開始列印 WriteLine的方法從下一行開始列印 Visual basic net 講義 17 3 3 如何新增一整數 使用者輸入兩個整數 程式計算總合 顯示結果 Chiang ho 大

9、綱 18 Addition vb 1 Fig 3 10 Addition vb 2 相加 program 3 4 Module modAddition 5 6 Sub Main 7 8 variables for storing user input 9 Dim firstNumber secondNumber As String 10 11 variables used in addition calculation 12 Dim number1 number2 sumOfNumbers As Integer 13 14 read first number from user 15 Cons

10、ole Write Please enter the first integer 16 firstNumber Console ReadLine 17 18 read second number from user 19 Console Write Please enter the second integer 20 secondNumber Console ReadLine 21 22 convert input values to Integers 23 number1 firstNumber 24 number2 secondNumber 25 26 sumOfNumbers numbe

11、r1 number2 add numbers 27 28 display results 29 Console WriteLine The sum is 0 sumOfNumbers 30 31 End Sub Main 32 33 End Module modAddition 變數宣告使用Dim開始 字串變數 整數變數 使用者第一個輸入的整數值 ReadLine 程式暫停 使用者輸入 隱含轉換字串 整數 將加總整數值只給sumOfNumbers 將參數格式化輸出 Chiang ho 大綱 19 Addition vb Please enter the first integer 1 Plea

12、se enter the second integer 2 The sum is 3 Visual basic net 講義 20 3 3 addition 加總程式 Fig 3 11執行期錯誤的對話框 假如使用者輸入非數值資料如 chiang 則執行錯誤產生 Visual basic net 講義 21 3 4 Memory Concepts 變數 變數在記憶體所在空間的位址 變數特徵 名稱 name 資料型態 Type 大小 Size 值 value 指定一新值給一變數時會把一變數原有值取代 就值會被摧毀 讀取一變數內容時舊值不會被影響 Visual basic net 講義 22 3 4

13、 記憶體的觀念 Fig 3 12記憶體以變數名稱參照記億體 Memory location 存取 Fig 3 13變數number1 number2輸入指定初值後 45number1 45 45 number1 number2 Visual basic net 講義 23 3 5算術運算子 Arithmetic operators 算術 Visual Basic 使用特殊符號 星字號 關鍵字 Mod等等 二元運算子 使用兩個運算元的運算子 sum number 單元運算子 運算子處理一個運算元 9 19 Visual basic net 講義 24 3 5算術運算子 Fig 3 14 執行加法

14、運算之後的記憶體 45 45 number1 number2 sumOfNumbers 90 Visual basic net 講義 25 3 5算術運算子 整除 使用倒斜線 1 2 evaluates to 0 浮點數除法 使用斜線 7 4 evaluates to 1 75 Modulus operator Mod 整除之後保留餘數 7 Mod 4 yields 3 Visual basic net 講義 26 3 5 算數運算子 Fig 3 14算數運算子 Visual basic net 講義 27 3 5算術運算子 Fig 3 15算數運算優先權 Visual basic net 講

15、義 28 3 5算術運算子 Fig 3 16 算數優先權 Step 1 Step 2 Step 5 Step 3 Step 4 Step 6 y 1 5 5 3 5 7 1 5 is 5 最左相成 y 5 5 3 5 7 5 5 is 50 最左相成 eftmost multiplication y 25 3 5 7 3 5 is 15 加法之前相成 y 25 15 7 25 15 is 40 最左相加 y 40 7 40 7 is 47 最後相加 y 47 指定運算 72 into y Visual basic net 講義 29 3 6 全等及關係運算子 If Then 結構 程式中基於真

16、假值控制程式的流程並作決策 條件式 在if then end if 的表示式中 假如if 的條件是為真執行其主體 條件是可以是 全等運算子 關係運算子 Visual basic net 講義 30 3 6決策製作 全等及關係運算子 Fig 3 17Equality and relational operators Chiang ho 大綱 31 Comparison vb 1 Fig 3 19 Comparison vb 2 Using equality and relational operators 3 4 Module modComparison 5 6 Sub Main 7 8 declare Integer variables for user input 9 Dim number1 number2 As Integer 10 11 read first number from user 12 Console Write Please enter first integer 13 number1 Console ReadLine 14 15 read second numbe

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号