各位高手,小弟有两个非常简单的问题请教:(1)利用vb制作计算器,能实现加。减。乘。除。等于功能,按钮用控件数组,计算不考虑优先级,但能连续+。-。*。/;(2)利用vb制作体育彩票“七星彩”,在vb中输入7个数,点开奖按钮随机产生7位书,然后与输入的7位数进行比较,一致则中奖,否则就没有。

解决方案 »

  1.   

    我给你写,有意给我发电子邮件  [email protected]
      

  2.   


    Dim p1, p2, p3 As Double
    Dim n As Integer
    Dim f1, f2, f3 As String
    Dim q, p As Boolean
    Private Sub Command1_Click(Index As Integer)
      If q = True Then
        If Index = 10 Then
         Text1.Text = "0."
        ElseIf Index = 11 Then
         Text1.Text = "-"
        Else
         Text1.Text = Command1(Index).Caption
        End If
        q = False
      Else
         If Index = 11 Then
           Text1.Text = -1 * Val(Text1.Text)
         Else
           Text1.Text = Text1.Text + Command1(Index).Caption
         End If
      End If
      p = False
    End SubPrivate Sub Command2_Click(Index As Integer)
      If n = 0 Then
        p1 = Val(Text1.Text)
        f1 = Command2(Index).Caption
        If p = False Then
          n = n + 1
          p = True
        End If
      ElseIf n = 1 Then
       p2 = Val(Text1.Text)
       f2 = Command2(Index).Caption
       If p = False Then
        n = n + 1
        p = True
       End If
      Else
        p3 = Val(Text1.Text)
        f3 = Command2(Index).Caption
        n = n + 1
      End If
      If f1 = "+" And n > 2 Then
        If f2 = "+" Or f2 = "-" Then
         p1 = p1 + p2
         p2 = p3
         f1 = f2
         f2 = f3
        End If
        If f2 = "*" Then
         p2 = p2 * p3
         f2 = f3
        End If
        If f2 = "/" Then
         If p3 = 0 Then
           Text1.Text = "ERROR"
         Else
          p2 = p2 / p3
          f2 = f3
         End If
        End If
      End If
      If f1 = "-" And n > 2 Then
        If f2 = "+" Or f2 = "-" Then
          p1 = p1 - p2
          p2 = p3
          f1 = f2
          f2 = f3
        End If
        If f2 = "*" Then
          p2 = p2 * p3
          f2 = f3
        End If
        If f2 = "/" Then
         If p3 = 0 Then
           Text1.Text = "ERROR"
         Else
          p2 = p2 / p3
          f2 = f3
         End If
        End If
      End If