2016年10月15日 星期六

單元:ch03.

單元:ch03.

1. 視窗應用程式用到的輸出訊息盒 msgbox 語法是: msgbox " "

2. 視窗應用程式用到的輸入輸入盒 inputbox 語法是: 宣告數 = inputbox( , , , )





3. 可以用來加減乘除的叫數值,數值可分為整數和浮點數。如果你需要讓使用者可以輸入

整數,要寫出那 2 條指令?



4. 同上。如果你需要讓使用者可以輸入浮點數,要寫出那 2 條指令?






5. 字串會用雙引號””框住,通常不會拿來+-*/,例如:姓名、電話、學號等。如果你需要讓

使用者可以輸入字串,要寫出那 2 條指令?






6. 我會使用 If...then...。例如:判断整數 A 是正數則印出「正數」



7. 我會使用 If...then...else。例如:判断整數 A 是正數則印出「正數」否則印出「負數」

作法 1:

作法 2:


8. 「成績等第判斷」使用巢狀 If...then...else...來完成。
 Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim g As Single 'g=成績
        Dim ans As String
        g = InputBox("成績", "成績等第", 0)

        If g > 89 Then
            ans = "優"
        ElseIf g > 79 Then
            ans = "甲"
        ElseIf g > 69 Then
            ans = "乙"
        ElseIf g > 59 Then
            ans = "丙"
        Else
            ans = "丁"
        End If

        Me.TextBox6.Text = ans

    End Sub



9. 「成績等第判斷」使用 Select...case....來完成。
Dim g As Single 'g=成績
        Dim ans As String
        g = InputBox("成績", "成績等第", 0)

         Select g
            Case 90 To 100
                ans = "優"
            Case 80 To 89
                ans = "甲"
            Case 70 To 79
                ans = "乙"
            Case 60 To 69
                ans = "丙"
            Case Else
                ans = "丁"

        End Select

        Me.TextBox7.Text = ans

    End Sub



10. 輸入 A、B、C 三個數,輸出最大值。想出三種不同的結構來完成。

作法 1:


作法 2:


作法 3:

2016年10月6日 星期四

單元:ch01. 第一個程式、ch02. 資料的基本概念

1. 主控台應用程式用到的輸出方法有: write , writeline

2. 主控台應用程式用到的輸入方法有:read  , readline

3. 寫出 VB 運算子的優先順序(由上到下代表高到低)

算術運算 > 關係運算 > 邏輯運算
先算出值,才能比大小,比出真假才能判断且或 ^  - 負號  *  /  \  Mod  +  -
1.算術運算子的優先順序
2.關係運算子的優先順序 優先順序相同,由左而右計算
3.邏輯運算子的優先順序 Not And AndAlso Or OrElse Xor



4. 只用一條程式碼,印出上機練習題 1 的結果。(字串串接及程式碼換行排版練習)
Console.WriteLine("====Console.WriteLine練習====") : Console.WriteLine("班級:資應一甲") : Console.WriteLine("學號:1110534026") : Console.WriteLine("姓名:林泫亨") : Console.WriteLine("=============================")




5. 不恰當的資料型態宣告,會影響到結果的正確性。請參考 [ch02.資料的基本概念投影片]
    pp. 15-16 試寫一程式來印出各數值型別之表示範圍,並和課本比較是否有異。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim ans As String = "" '答案字串
        ans = "型態" & vbTab & "byte" & vbTab & "範圍" & vbNewLine
        ans &= "SByte" & vbTab & "1" & vbTab & SByte.MinValue & "~" & SByte.MaxValue & vbNewLine
        ans &= "Byte" & vbTab & "1" & vbTab & Byte.MinValue & "~" & Byte.MaxValue & vbNewLine
        ans &= "Short" & vbTab & "2" & vbTab & Short.MinValue & "~" & Short.MaxValue & vbNewLine
        ans &= "Ushort" & vbTab & "2" & vbTab & UShort.MinValue & "~" & UShort.MaxValue & vbNewLine
        ans &= "Integer" & vbTab & "4" & vbTab & Integer.MinValue & "~" & Integer.MaxValue & vbNewLine
        ans &= "Uinteger" & vbTab & "4" & vbTab & UInteger.MinValue & "~" & UInteger.MaxValue & vbNewLine
        ans &= "Long" & vbTab & "8" & vbTab & Long.MinValue & "~" & Long.MaxValue & vbNewLine
        ans &= "Ulong" & vbTab & "8" & vbTab & ULong.MinValue & "~" & ULong.MaxValue & vbNewLine
        ans &= "Single" & vbTab & "4" & vbTab & Single.MinValue & "~" & Single.MaxValue & vbNewLine
        ans &= "Double" & vbTab & "8" & vbTab & Double.MinValue & "~" & Double.MaxValue & vbNewLine
        ans &= "Decimal" & vbTab & "12" & vbTab & Decimal.MinValue & "~" & Decimal.MaxValue & vbNewLine

MsgBox(ans)




6. 請各位寫一個文字模式的程式,導引使用者輸入數值 x,數值 y,展示此二數的各項算 術運
算 ^ * / \ mod + - 結果(專案檔名: ch03-ConsoleIO-xxxxxxx)





7. 輸入半徑 r , 印出此圓之「圓周長」及「圓面積」。 (專案檔名: ch03-ConsoleCircle-xxxxxxx-prj, 請用常數來定義圓周率 pi=3.14159265)

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button3.Click
        '輸入半徑 r , 印出此圓之「圓周長」及「圓面積」
        '輸入半徑 r
        Dim ANS As String = ""
        Dim r As Single
        r = InputBox("半徑r =", "輸入半徑 r , 印出此圓之「圓周長」及「圓面積」", "結果")
        Const pi = 3.14159265 'pi數值
        '印出此圓之「圓周長」及「圓面積」
        ANS &= ("圓周長=" & r * 2 * pi) & vbNewLine
        ANS &= ("圓面積=" & r ^ 2 * pi) & vbNewLine

        MsgBox(ANS, , "結果")