请问这道VB题该怎么做??万分感谢!!!!!
在一有序序列中插入任何数使原序列仍有序。要求,在文本框1内输入序列,文本框2内输入要插入的数。点击按钮后,在窗体上或在文本框1中显示新序列是逗号...
在一有序序列中插入任何数使原序列仍有序。要求,在文本框1内输入序列,文本框2内输入要插入的数。点击按钮后,在窗体上或在文本框1中显示新序列
是逗号 展开
是逗号 展开
2个回答
展开全部
'好了,代码如下,有不明白的发消息问我。
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then
Exit Sub
End If
'读取数据
tmp = Split(Trim(Text1.Text), ",")
ReDim arr(UBound(tmp) + 1) As Integer
For i = 0 To UBound(arr) - 1
arr(i) = CInt(tmp(i))
Next
arr(UBound(arr)) = CInt(Text2.Text)
'排序数据
For i = 0 To UBound(arr)
For j = 0 To UBound(arr)
If arr(j) > arr(i) Then
x = arr(j)
arr(j) = arr(i)
arr(i) = x
End If
Next
Next
'生成新数据
For i = 0 To UBound(arr)
If i = 0 Then
Text1.Text = CStr(arr(i))
Else
Text1.Text = Text1.Text + "," + CStr(arr(i))
End If
Next
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then
Exit Sub
End If
'读取数据
tmp = Split(Trim(Text1.Text), ",")
ReDim arr(UBound(tmp) + 1) As Integer
For i = 0 To UBound(arr) - 1
arr(i) = CInt(tmp(i))
Next
arr(UBound(arr)) = CInt(Text2.Text)
'排序数据
For i = 0 To UBound(arr)
For j = 0 To UBound(arr)
If arr(j) > arr(i) Then
x = arr(j)
arr(j) = arr(i)
arr(i) = x
End If
Next
Next
'生成新数据
For i = 0 To UBound(arr)
If i = 0 Then
Text1.Text = CStr(arr(i))
Else
Text1.Text = Text1.Text + "," + CStr(arr(i))
End If
Next
End Sub
展开全部
Private Sub Command1_Click()
tmp = Split(Trim(Text1.Text), ",")
n = UBound(tmp)
Dim arr() As Integer
ReDim arr(n + 1)
For i = 0 To n
arr(i) = CInt(tmp(i))
Next
arr(n + 1) = CInt(Text2.Text)
For i = n To 0 Step -1
If arr(i) > arr(i + 1) Then
t = arr(i + 1): arr(i + 1) = arr(i): arr(i) = t
End If
s = "," & arr(i + 1) & s
Next i
Text1.Text = arr(0) & s
End Sub
或_____________________________________
Private Sub Command1_Click()
Dim arr
arr = Split(Trim(Text1.Text), ",")
n = UBound(arr)
ReDim Preserve arr(n + 1)
i = n
x = CInt(Text2.Text)
Do While CInt(arr(i)) > x
arr(i + 1) = arr(i)
i = i - 1
If i = -1 Then Exit Do
Loop
arr(i + 1) = x
Text1.Text = Join(arr, ",")
End Sub
tmp = Split(Trim(Text1.Text), ",")
n = UBound(tmp)
Dim arr() As Integer
ReDim arr(n + 1)
For i = 0 To n
arr(i) = CInt(tmp(i))
Next
arr(n + 1) = CInt(Text2.Text)
For i = n To 0 Step -1
If arr(i) > arr(i + 1) Then
t = arr(i + 1): arr(i + 1) = arr(i): arr(i) = t
End If
s = "," & arr(i + 1) & s
Next i
Text1.Text = arr(0) & s
End Sub
或_____________________________________
Private Sub Command1_Click()
Dim arr
arr = Split(Trim(Text1.Text), ",")
n = UBound(arr)
ReDim Preserve arr(n + 1)
i = n
x = CInt(Text2.Text)
Do While CInt(arr(i)) > x
arr(i + 1) = arr(i)
i = i - 1
If i = -1 Then Exit Do
Loop
arr(i + 1) = x
Text1.Text = Join(arr, ",")
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询