2个回答
展开全部
5.1 界面图:
设置文本框Text1的:MultiLine 属性为 TRUE,ScrollBars属性为 2
代码:
Option Explicit
Private Sub Command1_Click()
Dim d(26) As Integer
Dim i As Integer
Dim j As Integer
Dim s As String
Dim c As String
For i = 1 To 26
d(i) = 0
Next i
s = Text1.Text
For i = 1 To Len(s)
c = Mid(s, i, 1)
For j = 1 To 26
If c = Chr(j + 64) Or c = Chr(j + 96) Then
d(j) = d(j) + 1
Exit For
End If
Next j
Next i
s = ""
j = 0
For i = 1 To 26
If d(i) <> 0 Then
s = s & Chr(i + 64) & "= " & d(i) & " "
j = j + 1
If j Mod 6 = 0 Then s = s & vbCrLf '每行输出6个字母的统计值
End If
Next i
Picture1.Cls
Picture1.Print s
End Sub
Private Sub Form_Load()
Me.Caption = "统计字符个数"
Label1.Caption = "请输入字符串:"
End Sub
5.2 界面图:
右边按钮从上到下:Command1--Command6
代码:
Option Explicit
Private Sub Command1_Click()
Dim i As Integer
Text1.Text = Trim(Text1.Text)
If Text1.Text = "" Then
MsgBox "请输入单词!", , "输入提示"
Exit Sub
End If
For i = 0 To List1.ListCount - 1
If List1.List(i) = Text1.Text Then
MsgBox "单词已经存在!", , "添加提示"
Exit Sub
End If
Next i
List1.AddItem Text1.Text
Text1.Text = ""
End Sub
Private Sub Command2_Click()
Dim i As Integer
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
List1.RemoveItem i
Exit For
End If
Next i
MsgBox "请选中要删除的单词!", , "删除提示"
End Sub
Private Sub Command3_Click()
List1.Clear
End Sub
Private Sub Command4_Click()
Dim Od As String
Dim i As Integer
If Text1.Text = "" Then
MsgBox "请在文本框里输入正确的单词!", , "修改提示"
Exit Sub
End If
If List1.SelCount = 0 Then
MsgBox "请选中欲修改的单词!", , "修改提示"
Exit Sub
End If
For i = 0 To List1.ListCount - 1
If List1.List(i) = Text1.Text Then
MsgBox "单词已经存在!", , "修改提示"
Exit Sub
End If
Next i
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = True
End Sub
Private Sub Command5_Click()
Dim Od As String
Dim i As Integer
Dim Msg, Style, Title, Response
Msg = "是否确认修改?" ' 定义信息。
Style = vbYesNo + vbQuestion + vbDefaultButton2 ' 定义按钮。
Title = "修改确认提示" ' 定义标题。
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' 用户按下“是”。
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
Od = List1.List(i)
List1.RemoveItem i
List1.AddItem Text1.Text, i
MsgBox "完成将 " & Od & " 修改成: " & Text1.Text, , "修改成功!"
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = False
Text1.Text = ""
Exit For
End If
Next i
End If
End Sub
Private Sub Form_Load()
Form1.Caption = "单词列表管理"
Command1.Caption = "添加单词"
Command2.Caption = "删除单词"
Command3.Caption = "全部删除"
Command4.Caption = "修改单词"
Command5.Caption = "修改确认"
Command6.Caption = "退出"
Command5.Enabled = False
End Sub
追问
知道了谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询