1) 分析并显示控件的值中含有几个字母“a”。
2) 若英文句子用“.”号结束,英文单词间用空格字符和逗号字符作为分隔字符,分析显示TextBox控件的Text值中含有几个英文单词。
3) 把找到的单词按从小到大的次序排序后显示到另一个TextBox控件的文本框中。
VB程序、、编写应用程序,要求在TextBox控件的文本框中输入一个英文句子后完成如下操作:
答案:5 悬赏:20 手机版
解决时间 2021-03-03 23:03
- 提问者网友:wodetian
- 2021-03-03 19:57
最佳答案
- 五星知识达人网友:猎心人
- 2021-03-03 21:36
请用以下代码要求一个list1 用来排序单词 请将sorted属性设置为true 。
Private Sub Command1_Click()
Dim ano
For i = 1 To Len(Text1.Text)
If Mid(Text1.Text, i, 1) = "a" Then
ano = ano + 1
End If
Next
MsgBox ano & "个a"
End Sub
Private Sub Command2_Click()
Dim Cmdarr() As String, cno As Long, mdarr() As String
Cmdarr = Split(Text1.Text, " ")
For i = LBound(Cmdarr) To UBound(Cmdarr) '分析有几个单词
mdarr = Split(Cmdarr(i), ",")
For c = LBound(mdarr) To UBound(mdarr) ' 为单词排序到list1
List1.AddItem mdarr(c)
Next
cno = cno + UBound(mdarr)
Next
For d = 0 To List1.ListCount - 1 '将排序好的单词输出到text2
Text2.SelText = List1.List(d) & " "
Next
MsgBox cno + UBound(Cmdarr) + 1 & "个单词"
End Sub
Private Sub Command1_Click()
Dim ano
For i = 1 To Len(Text1.Text)
If Mid(Text1.Text, i, 1) = "a" Then
ano = ano + 1
End If
Next
MsgBox ano & "个a"
End Sub
Private Sub Command2_Click()
Dim Cmdarr() As String, cno As Long, mdarr() As String
Cmdarr = Split(Text1.Text, " ")
For i = LBound(Cmdarr) To UBound(Cmdarr) '分析有几个单词
mdarr = Split(Cmdarr(i), ",")
For c = LBound(mdarr) To UBound(mdarr) ' 为单词排序到list1
List1.AddItem mdarr(c)
Next
cno = cno + UBound(mdarr)
Next
For d = 0 To List1.ListCount - 1 '将排序好的单词输出到text2
Text2.SelText = List1.List(d) & " "
Next
MsgBox cno + UBound(Cmdarr) + 1 & "个单词"
End Sub
全部回答
- 1楼网友:行雁书
- 2021-03-04 00:40
这个不难。好好看教材例程,结合几个相关的例子。
- 2楼网友:山有枢
- 2021-03-04 00:30
建议画个草图
或者按步骤说明
- 3楼网友:白昼之月
- 2021-03-03 23:03
private sub command1_click()
dim a as textbox
dim i as integer
for i = 0 to 9
set a = form1.controls.add("vb.textbox", "text" & i)
a.visible = true
a.move i * 500, i * 400, 1000, 300
a.backcolor = rgb(255, 255, 255)
a.text = "text" & i
next
lab.caption = "动态添加控件成功"
end sub
- 4楼网友:青尢
- 2021-03-03 22:02
Private Sub Command1_Click()
'字母a的数量
Dim i As Integer, j As Integer
For i = 0 To Len(Text1.Text) - 1
If Mid(Text1.Text, i + 1, 1) = "a" Then
j = j + 1
End If
Next i
MsgBox "字母a的数量为" & j
'英文单词数量
Dim y, m As Integer
y = Split(Text1.Text, ".", -1, 1)
m = UBound(y)
MsgBox "英文单词数量为" & m + 1
'单词排序,并输入到text2中
Dim temp, r As Integer, n As Integer, z As Integer
Text2.Text = ""
For n = m To 1 Step -1
For z = 1 To n
If Len(y(z - 1)) > Len(y(z)) Then
tem = y(z)
y(z) = y(z - 1)
y(z - 1) = tem
End If
Next z
Next n
For r = 0 To m
Text2.Text = Text2.Text + " " + y(r)
Next
End Sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯