Re: [VB6 ] 計算機
續上次做到一半的計算機:
在Stop之前都可以正常運作
之後是因為宣告二維陣列出問題嗎
出現了錯誤消息:
---------------------
Run-time error'9'
Script out of range
---------------------
++++
程式草稿:
http://0rz.net/2d0qK
++++
Dim A() As Double
Dim B() As String
Dim GS() As Double
Dim C()
Dim D()
Dim Accumulation()
Dim GA() As Double
Dim X, Y, Z
Private Sub Command1_Click(Index As Integer)
    Text1.Text = Text1.Text & Index
    Text5.Text = Text5.Text & Index
End Sub
Private Sub Command2_Click(Index As Integer)
    Text1.Text = Text1.Text & Command2(Index).Caption
    Text5.Text = Text5.Text & Command2(Index).Caption
End Sub
Private Sub Command3_Click()
    X = Val(Text2.Text)
    Y = Val(Text3.Text)
    Z = Val(Text4.Text)
    H = Text1.Text
    N = 0
    Do
        ReDim Preserve A(N)
        ReDim Preserve B(N)
        O = InStr(1, H, "+")
        P = InStr(1, H, "-")
        If O > 0 And P > 0 Then
            If O < P Then
                A(N) = O
            Else
                A(N) = P
            End If
        ElseIf O > 0 Then
            A(N) = O
        Else
            A(N) = P
        End If
        If A(N) = 0 Then B(N) = H: Exit Do
        B(N) = Left(H, (A(N) - 1))
        H = Mid(H, A(N) + 1)
        N = N + 1
    Loop
Stop
    For I = 1 To N
       Do
          ReDim Preserve C(I, M)
          ReDim Preserve D(I, M)
          Q = InStr(1, B(I), "*")
          R = InStr(1, B(I), "/")
          If Q > 0 And R > 0 Then
             If Q < R Then
                C(I, M) = Q
             Else
                C(I, M) = R
             End If
          ElseIf Q > 0 Then
             C(I, M) = Q
          Else
             C(I, M) = R
          End If
          If C(I, M) = 0 Then D(I, M) = B(I): Exit Do
          D(I, M) = Left(B(I), (C(I, M) - 1))
          B(I) = Mid(B(I), C(I, M) + 1)
          M = M + 1
       Loop
    Next I
Stop
    ReDim Preserve GA(I, J)
    For I = 0 To N
       For J = 0 To M
        GA(I, J) = Val(D(I, J))
       Next J
    Next I
    For I = 0 To N
       For J = 0 To (N - 1)
       C(I, J + 1) = C(I, J + 1) + C(I, J)
           If Mid(B(I), C(I, J), 1) = "*" Then
               GA(I, J + 1) = Val(GA(I, J + 1))
           Else
               GA(I, J + 1) = 1 / Val(GA(I, J + 1))
           End If
       Next J
    Next I
    Accumulation(I) = 1
    For I = 0 To N
       For J = 0 To M
        Accumulation(I) = Accumulation(I) * GA(I, M)
       Next J
    Next I
    H = Text1.Text
    ReDim Preserve GS(N)
    For I = 0 To N
        GS(I) = Val(Accumulation(I))
    Next I
    For I = 0 To (N - 1)
    A(I + 1) = A(I + 1) + A(I)
        If Mid(H, A(I), 1) = "+" Then
            GS(I + 1) = Val(GS(I + 1))
        Else
            GS(I + 1) = -Val(GS(I + 1))
        End If
    Next I
    Sum = 0
    For I = 0 To N
        Sum = Sum + GS(I)
    Next I
    Label1.Caption = Sum
End Sub
Private Sub Command4_Click()
    Text1.Text = ""
    Text5.Text = ""
    Label1.Caption = ""
End Sub
Private Sub Command5_Click()
   End
End Sub
Private Sub Command6_Click()
    Text1.Text = Text1.Text + Text2.Text
    Text5.Text = Text5.Text + "X"
End Sub
Private Sub Command7_Click()
    Text1.Text = Text1.Text + Text3.Text
    Text5.Text = Text5.Text + "Y"
End Sub
Private Sub Command8_Click()
    Text1.Text = Text1.Text + Text4.Text
    Text5.Text = Text5.Text + "Z"
End Sub
Private Sub Command9_Click()
    Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
    Text5.Text = Left(Text5.Text, Len(Text5.Text) - 1)
End Sub
--
少年讀書,如隙中窺月;
中年讀書,如庭中望月;
老年讀書,如臺上玩月。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.141.159.236
※ 編輯: TrueFeeling     來自: 220.141.159.236      (06/11 20:43)
※ 編輯: TrueFeeling     來自: 220.141.159.236      (06/11 20:45)
※ 編輯: TrueFeeling     來自: 220.141.159.236      (06/11 20:48)
※ 編輯: TrueFeeling     來自: 220.141.159.236      (06/11 20:48)
※ 編輯: TrueFeeling     來自: 220.141.159.236      (06/11 20:55)
推
210.58.156.43 06/11, , 1F
210.58.156.43 06/11, 1F
推
210.58.156.43 06/11, , 2F
210.58.156.43 06/11, 2F
→
210.58.156.43 06/11, , 3F
210.58.156.43 06/11, 3F
討論串 (同標題文章)
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章