VB 编程求解
本程序实现如下功能:首先,单击“生成”按钮,生成一个由10个随机大写字母组成的字符串,并在文本框中显示。然后,单击“排序”按钮,将此随机字符串中的各个字母按递增顺序添加到列表框中。
[程序]
As String
Private Sub get_Click()
Dim i As Integer
Randomize
For i = 1 To 10
str1 = Trim(str1) & Chr(Int( ___(1) Int(Rnd * 26) + 65 ___ ))
Next
Text1.Text = str1
End Sub
Private Sub sort_Click()
Dim i As Integer
Dim j As Integer
For i = 1 To 26
j = ___(2)___
Do While j > 0
___(3)___
j = j - 1
Loop
Next
End Sub
Private Function search(str1 As String, str2 As String) As Integer
Dim int1 As Integer, int2 As Integer
int1 = 1
Do
int1 = ___(4)___
If int1 = 0 Then Exit Do
int2 = int2 + 1
int1 = int1 + 1
Loop
search = ___(5)___ End Function
请给出后4空的答案,正确的一定给分!
答案:我帮你解决了。我VB6上调试运行通过了!你的第一行跟最后一行是不是抄错了。整个程序应该是这样的:(空怎么填一看就知道了)
Dim str1 As String
Private Sub Command1_Click()
Dim i As Integer
Randomize
For i = 1 To 10
str1 = Trim(str1) & Chr(Int(Int(Rnd * 26) + 65))
Next
Text1.Text = str1
End Sub
Private Sub Command2_Click()
Dim i As Integer
Dim j As Integer
For i = 1 To 26
j = search(str1, Chr(64 + i))
Do While j > 0
List1.AddItem (Chr(64 + i))
j = j - 1
Loop
Next
End Sub
Private Function search(str1 As String, str2 As String) As Integer
Dim int1 As Integer, int2 As Integer
int1 = 1
Do
int1 = InStr(int1, str1, str2)
If int1 = 0 Then Exit Do
int2 = int2 + 1
int1 = int1 + 1
Loop
search = int2
End Function
上一个:vb编程 急~~!
下一个:VB编程问题