电子政务就业方向:急死我了 请Visual Basic编程高手指教

来源:百度文库 编辑:高校问答 时间:2024/05/05 19:02:30
我现在正编一个输入随机单词,然后按开头字母升序排列,可是到最后还原不过来了,请有高手指教。下面是我写的代码,还没有完成。最后还要把排好序的单词在窗体上打印出来:
Private Sub Form_Click()
Dim this(1 To 5) As Integer
Dim that(1 To 5) As String
For i = 1 To 5
that(i) = InputBox("请输入单词")
this(i) = Asc(that(i))
Next i
For j = 5 To 2 Step -1
For k = 1 To j - 1
If this(k) > this(k + 1) Then
n = this(k)
this(k) = this(k + 1)
this(k + 1) = n
End If
Next k
Next j
For p = 1 To 5
Print this(p)
Print that(p)
Next p
对啊,这么简单我都没有想起来,真厉害!谢谢啊。
但是我还要问“该隐_堕 - 助理 二级”一下,为什么“Asc(that(j + 1)) < Asc(that(j))不对.直接字符串比较that(j + 1) < that(j) ”还有,我想编一个统计程序:输入一个字符串,然后输出其中大写字母、小写字母和数字的数目。高手请帮帮忙。谢谢!

没那么麻烦,看看我的代码:
Private Sub Form_Click()

Dim that(1 To 5) As String
Dim temp As String

For i = 1 To 5
that(i) = InputBox("请输入单词:")

Next i

For i = 1 To 5
For j = 1 To 4
If Asc(that(j + 1)) < Asc(that(j)) Then
temp = that(j)
that(j) = that(j + 1)
that(j + 1) = temp
End If
Next
Next

For p = 1 To 5

Print that(p)
Next p
End Sub

学了两天VB,可你这个我看不懂
嘿嘿

Asc(that(j + 1)) < Asc(that(j))只比较第一个字符
这是你第二个程序
Private Sub Form_Click()

Dim word As String
Dim capitalletter(1 To 26) As Integer
Dim smallletter(1 To 26) As Integer
word = InputBox("请输入单词:")

Dim l As Integer
l = Len(word)

For i = 1 To l
If Asc(Left$(word, i)) >= 65 And Asc(Left$(word, i)) <= 90 Then
capitalletter(Asc(Left$(word, i)) - 64) = capitalletter(Asc(Left$(word, i)) - 64) + 1
End If
If Asc(Left$(word, i)) >= 97 And Asc(Left$(word, i)) <= 122 Then
smallletter(Asc(Left$(word, i)) - 96) = smallletter(Asc(Left$(word, i)) - 96) + 1
End If
Next
For i = 1 To 26
Print Chr$(i + 96); smallletter(i)
Next i
Print
For i = 1 To 26
Print Chr$(i + 64); capitalletter(i)
Next i
Print
End Sub