先谢谢各位,有点急~~所以~~被除数,除数,商都是1-12的整数,也就是说被除数一定能被除数整除,就像4除以2等于2,12除以6等于2

解决方案 »

  1.   


    '运行程序,连续单击按钮,观查结果Option Explicit
    '三个数不可重复
    Private Sub Command1_Click()
      Dim a, b, c
      Do
         a = Int(Rnd * 12) + 1
         b = Int(Rnd * 12) + 1
         c = Int(Rnd * 12) + 1
         If a / b = c And a <> b And b <> c And a <> c Then
            Debug.Print a; "÷"; b; "="; c
            Exit Do
         End If
      LoopEnd Sub
    '三个数可重复
    Private Sub Command2_Click()
      Dim a, b, c
      Do
         a = Int(Rnd * 12) + 1
         b = Int(Rnd * 12) + 1
         c = Int(Rnd * 12) + 1
         If a / b = c Then
            Debug.Print a; "÷"; b; "="; c
            Exit Do
         End If
      LoopEnd Sub
      

  2.   

    如果想在每次启动程序后,随机数不同,请用 Randomize timer 初始化随机数。Private Sub Form_Load()
        Randomize Timer
    End Sub
      

  3.   

    Private Sub Form_Load()
    Dim a(1)
    Dim b()
    Dim i As Integer, j As Integer, k As Integer, s
    For i = 1 To 12
    For j = 1 To 12
    If i Mod j = 0 Then
    a(0) = i: a(1) = j
    s = s & i & "÷" & j & "=" & i / j & vbCrLf
    ReDim Preserve b(k)
    b(k) = a
    End If
    Next
    Next
    MsgBox s
    End Sub
      

  4.   

    修改一下:Private Sub Command1_Click()
    Randomize
    k = UBound(b)
    i = Int((k * Rnd))
    MsgBox b(i)(0) & "÷" & b(i)(1) & "=" & b(i)(0) / b(i)(1)
    End SubPrivate Sub Form_Load()
    Dim a(1)
    Dim i As Integer, j As Integer, k As Integer, s
    For i = 1 To 12
    For j = 1 To 12
    If i Mod j = 0 Then
    a(0) = i: a(1) = j
    s = s & i & "÷" & j & "=" & i / j & vbCrLf
    ReDim Preserve b(k)
    b(k) = a
    k = k + 1
    End If
    Next
    Next
    MsgBox s
    End Sub
      

  5.   

    修改一下:Private Sub Command1_Click()
    Randomize
    k = UBound(b)
    i = Int((k * Rnd))
    MsgBox b(i)(0) & "÷" & b(i)(1) & "=" & b(i)(0) / b(i)(1)
    End SubPrivate Sub Form_Load()
    Dim a(1)
    Dim i As Integer, j As Integer, k As Integer, s
    For i = 1 To 12
    For j = 1 To 12
    If i Mod j = 0 Then
    a(0) = i: a(1) = j
    s = s & i & "÷" & j & "=" & i / j & vbCrLf
    ReDim Preserve b(k)
    b(k) = a
    k = k + 1
    End If
    Next
    Next
    MsgBox s
    End Sub
      

  6.   

    大侠些~怎么好多CODE下面都有错误线提示啊~~我的是VB2008哦  谢谢  能使用吗?
      

  7.   

    这是VB 6.0的代码,VB2008有个升级转换功能,转换一下.
      

  8.   

    猴哥  你那个Debug.Print a; "÷"; b; "="; c中的 a; 子VB2008里下面有错误线提示
    还有那个 Randomize Timer 中的Timer也有,谢谢帮忙~~~
      

  9.   

    基于老张的代码修改的Public Class Form1    Private Structure a
            Dim n1 As Byte
            Dim n2 As Byte
        End Structure    Private b() As a    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim i As Integer, j As Integer, k As Integer
            For i = 1 To 12
                For j = 1 To 12
                    If i Mod j = 0 Then
                        ReDim Preserve b(k)
                        b(k).n1 = i
                        b(k).n2 = j
                        k = k + 1
                    End If
                Next
            Next
        End Sub    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim i As Integer, k As Integer
            Randomize(Microsoft.VisualBasic.Timer)
            k = UBound(b)
            i = Int((k * Rnd()))
            MsgBox(b(i).n1 & "÷" & b(i).n2 & "=" & b(i).n1 / b(i).n2)
        End SubEnd Class