急需,求代码?
求详细代码,急需啊,越快越好!
Public Class Form1
''' <summary>
''' 生成一个题,分在一个字符串数组内
''' </summary>
''' <returns>一个数组</returns>
''' <remarks></remarks>
Function getSum(Optional maxa As Integer = 10, Optional maxb As Integer = 10) As String()
Dim a As Integer, b As Integer
Randomize()
a = Int(Rnd() * maxa)
b = Int(Rnd() * maxb)
Select Case Int(Rnd() * 4)
Case 0
Return New String() {a, "+", b, a + b} ' a & "+" & b & "="
Case 1
Return New String() {a, "-", b, a - b}
Case 2
Return New String() {a, "*", b, a * b}
Case Else
Try
If a < b Then
Dim t As Integer
t = b
b = a
a = t
End If
If b = 0 Then b = Int(Rnd() * (a - 1)) + 1
If a Mod b <> 0 Then
If a \ b = 0 Then
b = 1
Else
b = a / (a \ b)
End If
End If
Return New String() {a, "÷", b, a / b} ' a & "÷" & b & "="
Catch ex As Exception
Return New String() {ex.Message}
End Try
End Select
End Function
''' <summary>
''' 得到指定个数 不重复的题
''' </summary>
''' <param name="len">请不要填写的太大10以内容的 最多也只有300多个</param>
''' <returns></returns>
''' <remarks></remarks>
Function getLenQ(Optional len As Integer = 20) As List(Of String())
Dim t As New List(Of String())
Do While t.Count < len
Dim tem() As String = getSum()
If tem.Length = 4 Then
Dim f As Boolean
For Each i As String() In t
Dim o As Integer = 0
f = True
For Each j As String In i
If j <> tem(o) Then
f = False
Exit For
End If
o += 1
Next
If f Then Exit For
Next
If f = False Then
t.Add(tem)
End If
End If
Loop
Return t
End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
For Each t As String() In getLenQ()
ListBox1.Items.Add(t(0) & t(1) & t(2))
Next
End Sub
End Class追问
''' <summary>
''' 生成一个题,分在一个字符串数组内
''' </summary>
''' <returns>一个数组</returns>
''' <remarks></remarks>
Function getSum(Optional maxa As Integer = 10, Optional maxb As Integer = 10) As String()
Dim a As Integer, b As Integer
Randomize()
a = Int(Rnd() * maxa)
b = Int(Rnd() * maxb)
Select Case Int(Rnd() * 4)
Case 0
Return New String() {a, "+", b, a + b} ' a & "+" & b & "="
Case 1
Return New String() {a, "-", b, a - b}
Case 2
Return New String() {a, "*", b, a * b}
Case Else
Try
If a < b Then
Dim t As Integer
t = b
b = a
a = t
End If
If b = 0 Then b = Int(Rnd() * (a - 1)) + 1
If a Mod b <> 0 Then
If a \ b = 0 Then
b = 1
Else
b = a / (a \ b)
End If
End If
Return New String() {a, "÷", b, a / b} ' a & "÷" & b & "="
Catch ex As Exception
Return New String() {ex.Message}
End Try
End Select
End Function
''' <summary>
''' 得到指定个数 不重复的题
''' </summary>
''' <param name="len">请不要填写的太大10以内容的 最多也只有300多个</param>
''' <returns></returns>
''' <remarks></remarks>
Function getLenQ(Optional len As Integer = 20) As List(Of String())
Dim t As New List(Of String())
Do While t.Count < len
Dim tem() As String = getSum()
If tem.Length = 4 Then
Dim f As Boolean
For Each i As String() In t
Dim o As Integer = 0
f = True
For Each j As String In i
If j <> tem(o) Then
f = False
Exit For
End If
o += 1
Next
If f Then Exit For
Next
If f = False Then
t.Add(tem)
End If
End If
Loop
Return t
End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
For Each t As String() In getLenQ()
ListBox1.Items.Add(t(0) & t(1) & t(2))
Next
End Sub
End Class追问
如果需要每道题后面有一个listbox填答案,并且能判断正误,该怎么写呢?
追答如果要录入答案 那就要改动一下了!
下面为改动后的代码.
首先 加上二个控件 Panel1 Button2
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
字数有限 上传文本了.自己看下 全部代码
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
温馨提示:答案为网友推荐,仅供参考
第1个回答 2013-12-11
Private Sub Form_Load()
Dim a(9) As Integer, i As Integer, j As Integer
Randomize
Show
For i = 0 To 9
a(i) = Rnd * 10
For j = 0 To i
If i <> j And a(i) = a(j) Then i = i - 1
Next
Next
For i = 0 To 9
Print Chr(97 + i) & "=" & a(i)
Next
End Sub(希望能帮到你,麻烦在我回答的下面点击 “好评”,谢谢你啦^_^)追问
Dim a(9) As Integer, i As Integer, j As Integer
Randomize
Show
For i = 0 To 9
a(i) = Rnd * 10
For j = 0 To i
If i <> j And a(i) = a(j) Then i = i - 1
Next
Next
For i = 0 To 9
Print Chr(97 + i) & "=" & a(i)
Next
End Sub(希望能帮到你,麻烦在我回答的下面点击 “好评”,谢谢你啦^_^)追问
请不要复制以前的答案好吗!!