1 / 9

Visual Basic 6.0 程式設計

Visual Basic 6.0 程式設計. 程式範例:四則運算. 徐雪玲. 題目:四則運算. 內容:設計一程式,在表單視窗可以輸入兩個變數,並且有四個按鈕分別為加、減、乘、除,可做四則運算,並顯示運算結果。. 所需的物件. Val( ) 函數. 功用: Val( ) 函數可以將文字型態的資料轉換成數字型態。 使用時機:輸入 Text1 、 Text2 的變數一、變數二等資料皆為文字型態,所以要進行算術運算前,必先用 Val( ) 作轉換。. If~Then~Else~EndIf 的用法. 使用時機:用於選擇條件判斷。 If 條件式 Then 成立敘述

Download Presentation

Visual Basic 6.0 程式設計

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 6.0程式設計 程式範例:四則運算 徐雪玲

  2. 題目:四則運算 • 內容:設計一程式,在表單視窗可以輸入兩個變數,並且有四個按鈕分別為加、減、乘、除,可做四則運算,並顯示運算結果。

  3. 所需的物件

  4. Val( )函數 • 功用:Val( )函數可以將文字型態的資料轉換成數字型態。 • 使用時機:輸入Text1、Text2的變數一、變數二等資料皆為文字型態,所以要進行算術運算前,必先用Val( )作轉換。

  5. If~Then~Else~EndIf的用法 • 使用時機:用於選擇條件判斷。 • If 條件式 Then 成立敘述 Else 不成立敘述 Endif

  6. Val(Text2) <> 0 MsgBox “分母不可為零唷!!" Text3 = Val(Text1) / Val(Text2) 下一個敘述 程式流程圖 成立 不成立

  7. 總結 • 同學透過這個範例,可以寫出運算式。 • 在往後的程式的範例中,會很常用到If~Then~Else~Endif 的判斷語法,可加強學習的印象。

  8. MsgBox指令的用法 • 使用時機:可以出現提示訊息。 • 指令語法:MsgBox 訊息字串

  9. 運算式的寫法 • Text3=Val(Text1)+Val(Text2) • Text3=Val(Text1)-Val(Text2) • Text3=Val(Text1)*Val(Text2) • Text3=Val(Text1)/Val(Text2) • 注意:運算結果要放在運算式的前面。

More Related