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.
簡易輸入輸出2 Option Explicit Dim S1, S2, S3 As String Dim A, B, SUM As Integer Private Sub Form_Activate() S1 = InputBox("輸入第一個?", "兩數相加", "0") S2 = InputBox("輸入第二個?", "兩數相加", "0") A = Val(S1) B = Val(S2) SUM = A + B Print "兩數之和= "; SUM End Sub
輸入一數求絕對值 (-3 3) Option Explicit Dim S1 As String Dim A As Integer Private Sub Form_Activate() S1 = InputBox("輸入一個數?", "求絕對值", "0") A = Val(S1) If A < 0 Then A = -A End If Print "絕對值="; A End Sub
輸入二數求最大數 (-50,10 10) Option Explicit Dim S1, S2 As String Dim A, B, SUM As Integer Private Sub Form_Activate() S1 = InputBox("輸入第一個?", "兩數相加", "0") S2 = InputBox("輸入第二個?", "兩數相加", "0") A = Val(S1) B = Val(S2) If A > B Then Print "最大數="; A Else Print "最大數="; B End If End Sub
SELECT CASE敘述 SELECT CASE資料或運算式 CASE 條件1 敘述1 CASE 條件2 敘述2 CASE 條件3 敘述3 CASE ELSE 敘述4 END SELECT
SELECT CASE範例 A=8 : B=2 OP = "*" SELELCT CASE OP CASE "+" : C=A+B CASE "-" : C=A-B CASE "*" : C=A*B CASE ELSE C=-1 END SELECT
SELECT CASE範例2 Option Explicit Dim S1, S2, OP As String Dim A, B, C As Integer Private Sub Form_Activate() S1 = InputBox("輸入第一個?", "求絕對值", "0") S2 = InputBox("輸入第一個?", "求絕對值", "0") A = Val(S1) : B = Val(S2) OP = "+" Select Case OP Case "+" : C = A + B Case "-" : C = A - B Case "*" : C = A * B Case Else : C = -1 End Select Print "結果="; C End Sub
SELECT CASE範例3 Option Explicit Dim SCORE As Integer Dim S As String Private Sub Form_Activate() S = InputBox("輸入分數") SCORE = Val(S) Select Case SCORE Case 90 To 100 : Print "甲等" Case 80 To 89 : Print "乙等" Case 70 To 79 : Print "丙等" Case 60 To 69 : Print "丁等" Case Else : Print "不及格" End Select End Sub
S=1+2+...+N≦100 Option Explicit Dim N, S, I As Integer Private Sub Form_Activate() S = 0 For I = 1 To 100 If (S + I) < 100 Then S = S + I Else Exit For End If Next I Print "N="; I - 1, "S="; S End Sub
巢狀FOR S=0 FOR I =1 TO 10 FOR J =1 TO 10 S=S+1 NEXT J NEXT I PRINT S
巢狀FOR2 S=0 FOR I =1 TO 10 STEP 2 FOR J =1 TO 10 S=S+1 NEXT J NEXT I PRINT S
巢狀FOR3 S=0 FOR I =1 TO 10 FOR J =1 TO 10 IF (I >5) THEN EXIT FOR S=S+1 NEXT J NEXT I PRINT S
巢狀FOR4 S=0 FOR I =1 TO 10 IF (I MOD 2=) THEN FOR J =1 TO 10 IF (I >5) THEN EXIT FOR S=S+1 NEXT J ENDIF NEXT I PRINT S
陣列(Array) • 一群相同型別、固定大小的資料,共用一變數名稱,每一元素用註標來存取 • 註標須整數 • 有一維、二維、N維 • 宣告方式 • dim a(10) as integer • dim b(3,4) as single • dim name(10) as string
設定陣列初值 Option Explicit Dim a(10) As Integer Dim i, j As Integer Private Sub Form_Activate() For i = 1 To 10 a(i) = i '陣列放 1,2,3, ...,10 Next i For i = 1 To 10 Print a(i); Next i End Sub
設定陣列初值(費氐係數) Option Explicit Dim a(10) As Integer Dim i, j As Integer Private Sub Form_Activate() a(0)=0 : a(1)=1 For i = 2 To 10 a(i) = a(i-1)+a(i-2) Next i For i = 0 To 10 Print a(i); Next i End Sub
設定陣列初值 Option Explicit Dim b(3, 4) As Single Dim i, j As Integer Private Sub Form_Activate() For i = 1 To 3 For j = 1 To 4 b(i, j) =( i + j)/10 Next j Next i For i = 1 To 3 For j = 1 To 4 Print b(i, j); Next j Print Next i End Sub
產生10亂數 Option Explicit Dim a(10) As Single Dim i, j As Integer Private Sub Form_Activate() For i = 1 To 10 a(i) = Rnd Next i For i = 1 To 10 Print a(i) Next i End Sub