
急啊!麻烦各位高手帮我设计下计算机VB 代码 谢谢啦! 高分悬赏!!
程序功能要求如下:1、单击“产生”按钮,产生10个50以内的整数,显示在列表框中。2、单击“排序”按钮,将列表框中数据项升序排列。3、在文本框中输入一个数据,单击“删除”...
程序功能要求如下:
1、单击“产生”按钮,产生10个50以内的整数,显示在列表框中。
2、单击“排序”按钮,将列表框中数据项升序排列。
3、在文本框中输入一个数据,单击“删除”按钮,
将列表框中该数据删除。
4、单击“插入”按钮,将文本框中的数据插入到列表框中。
5、程序要考虑按钮之间的有效性 展开
1、单击“产生”按钮,产生10个50以内的整数,显示在列表框中。
2、单击“排序”按钮,将列表框中数据项升序排列。
3、在文本框中输入一个数据,单击“删除”按钮,
将列表框中该数据删除。
4、单击“插入”按钮,将文本框中的数据插入到列表框中。
5、程序要考虑按钮之间的有效性 展开
1个回答
展开全部
Private Sub Command1_Click()
'产生
Randomize
For i = 1 To 50
List1.AddItem Int(Rnd * 50 + 1)
Next i
Command2.Enabled = True
Command3.Enabled = True
End Sub
Private Sub Command2_Click()
'排序
Dim a() As Integer
Dim intZongNum As Integer
intZongNum = List1.ListCount
ReDim a(intZongNum - 1)
For i = 0 To intZongNum - 1
a(i) = List1.List(i)
Next
For i = 0 To intZongNum - 2
For j = i + 1 To intZongNum - 1
If a(i) > a(j) Then
k = a(i)
a(i) = a(j)
a(j) = k
End If
Next j
Next i
List1.Clear
For i = 0 To intZongNum - 1
List1.AddItem a(i)
Next i
End Sub
Private Sub Command3_Click()
'删除
Dim x As Integer
Dim y As Integer
If List1.ListCount = 0 Then
Command3.Enabled = False
Exit Sub
End If
y = 0
x = Val(Text1.Text)
For i = List1.ListCount - 1 To 0 Step -1
If Val(List1.List(i)) = x Then
List1.RemoveItem i
y = y + 1
End If
Next i
If y = 0 Then
MsgBox "列表中没有找到项:" & x
End If
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub Command4_Click()
'插入
Dim x As Integer
x = Val(Text1.Text)
List1.AddItem x
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub Form_Load()
Text1.Text = ""
List1.Clear
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
End Sub
Private Sub Text1_Change()
If IsNumeric(Text1.Text) Then
Command4.Enabled = True
Else
Command4.Enabled = False
End If
End Sub
'产生
Randomize
For i = 1 To 50
List1.AddItem Int(Rnd * 50 + 1)
Next i
Command2.Enabled = True
Command3.Enabled = True
End Sub
Private Sub Command2_Click()
'排序
Dim a() As Integer
Dim intZongNum As Integer
intZongNum = List1.ListCount
ReDim a(intZongNum - 1)
For i = 0 To intZongNum - 1
a(i) = List1.List(i)
Next
For i = 0 To intZongNum - 2
For j = i + 1 To intZongNum - 1
If a(i) > a(j) Then
k = a(i)
a(i) = a(j)
a(j) = k
End If
Next j
Next i
List1.Clear
For i = 0 To intZongNum - 1
List1.AddItem a(i)
Next i
End Sub
Private Sub Command3_Click()
'删除
Dim x As Integer
Dim y As Integer
If List1.ListCount = 0 Then
Command3.Enabled = False
Exit Sub
End If
y = 0
x = Val(Text1.Text)
For i = List1.ListCount - 1 To 0 Step -1
If Val(List1.List(i)) = x Then
List1.RemoveItem i
y = y + 1
End If
Next i
If y = 0 Then
MsgBox "列表中没有找到项:" & x
End If
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub Command4_Click()
'插入
Dim x As Integer
x = Val(Text1.Text)
List1.AddItem x
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub Form_Load()
Text1.Text = ""
List1.Clear
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
End Sub
Private Sub Text1_Change()
If IsNumeric(Text1.Text) Then
Command4.Enabled = True
Else
Command4.Enabled = False
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询