Private?Sub?Form_Load()
網(wǎng)站的建設(shè)成都創(chuàng)新互聯(lián)公司專(zhuān)注網(wǎng)站定制,經(jīng)驗(yàn)豐富,不做模板,主營(yíng)網(wǎng)站定制開(kāi)發(fā).小程序定制開(kāi)發(fā),H5頁(yè)面制作!給你煥然一新的設(shè)計(jì)體驗(yàn)!已為成都玻璃貼膜等企業(yè)提供專(zhuān)業(yè)服務(wù)。
Command1.Enabled?=?False????????'使Command1不可用
Label2.Visible?=?False??????????'使Label2、...、Label7不可見(jiàn)
Label3.Visible?=?False
Label4.Visible?=?False:?Label5.Visible?=?False
Label6.Visible?=?False:?Label7.Visible?=?False
Label8.Visible?=?False:?Label9.Visible?=?False
'Text1.TabIndex?=?0??????????????'使文本框獲得輸入焦點(diǎn)
End?Sub
Private?Sub?Text1_KeyPress(KeyAscii?As?Integer)
If?KeyAscii?=?13?Then?Command1.Enabled?=?True????'輸入結(jié)束,使Command1可用
End?Sub
Private?Sub?Command1_Click()??????'單擊Command1完成統(tǒng)計(jì)
Dim?s?As?String,?length?As?Integer,?s1?As?String
Dim?n1?As?Integer,?n2?As?Integer,?n3?As?Integer,?wt?As?Boolean,?n4?As?Integer
s?=?Text1.Text
length?=?Len(s)
n1?=?0:?n2?=?0:?n3?=?0
For?i%?=?1?To?length
s1?=?Mid(s,?i%,?1)
If?s1?=?"a"?And?s1?=?"z"?Or?s1?=?"A"?And?s1?=?"Z"?Then
n1?=?n1?+?1????????????????????????????????'字母字符
ElseIf?s1?=?"0"?And?s1?=?"9"?Then
n2?=?n2?+?1????????????????????????????????'數(shù)字字符
Else
n3?=?n3?+?1????????????????????????????????'其它字符
End?If
Next?i%
Label5.Caption?=?n1:?Label6.Caption?=?n2
Label7.Caption?=?n3:?Label2.Visible?=?True??????'顯示標(biāo)簽
Label3.Visible?=?True:?Label4.Visible?=?True
Label5.Visible?=?True:?Label6.Visible?=?True
Label7.Visible?=?True
For?i%?=?1?To?length???????????'這個(gè)循環(huán)找到第一個(gè)單詞的字母
s1?=?Mid(s,?i%,?1)
If?s1?=?"a"?And?s1?=?"z"?Or?s1?=?"A"?And?s1?=?"Z"?Then?Exit?For
Next?i%
wt?=?False
For?j%?=?i?To?length?????????'從第一個(gè)單詞的字母開(kāi)始統(tǒng)計(jì)
s1?=?Mid(s,?j%,?1)
If?s1?=?"a"?And?s1?=?"z"?Or?s1?=?"A"?And?s1?=?"Z"?Then
If?wt?=?False?Then
n4?=?n4?+?1
wt?=?True
End?If
Else
wt?=?False
End?If
Next?j%
Label8.Visible?=?True:?Label9.Visible?=?True
Label9.Caption?=?n4
End?Sub
要改成這樣;
for i = 1 to Len(s)
j = Mid(s,i,1)
select case j
case "a" to "z","A" to "Z"
C = C + 1
CASE "0" TO "9"
D = D + 1
CASE ELSE
M= M+1
END SELECT
NEXT
統(tǒng)計(jì)某個(gè)字符的代碼如下:
private
sub
command1_click()
dim
i
as
integer,
ccount
as
integer
for
i
=
1
to
len(text1)
if
mid(text1,
i,
1)
=
"你所需要統(tǒng)計(jì)的字符"
then
ccount
=
ccount
+
1
next
i
msgbox
"共有"
count
"個(gè)e"
end
sub
Private Sub Command1_Click()
Dim n As Integer
Dim i As Integer
Dim one As Integer
n = 0
For i = 1 To Len(Text1.Text)
one = Asc(Mid(Text1.Text, i, 1))
If (one = 65 And one = 90) Or (one = 97 And one = 122) Then n = n + 1
Next i
MsgBox "共有" n "個(gè)字母。"
End Sub
在“通用聲明”代碼區(qū)聲明(窗體)模塊級(jí)變量
Option Explicit
Dim letters As Integer '聲明模塊級(jí)變量,此變量計(jì)算字母?jìng)€(gè)數(shù)
Dim space As Integer '空格個(gè)數(shù)
Dim digit As Integer '數(shù)字個(gè)數(shù)
Dim others As Integer '其他字符個(gè)數(shù)
輸入cmdStat_Click()事件過(guò)程代碼
Private Sub cmdStat_Click()
Dim InputStr As String '局部變量,此變量存儲(chǔ)輸入的字符串
Dim i As Integer '循環(huán)控制變量,整型
Dim CaseStr As String '此變量保存儲(chǔ)所截取的字符
letters = 0 '初始化為0
space = 0
digit = 0
others = 0
InputStr = txtInput.Text '取得輸入的字符串
For i = 1 To Len(InputStr) '開(kāi)始分別統(tǒng)計(jì)個(gè)數(shù)
CaseStr = Mid(InputStr, i, 1) '取得某個(gè)字符
Select Case CaseStr
Case "a" To "z", "A" To "Z" '如果字符是英文字母
letters = letters + 1
Case " " '如果字符是空格
space = space + 1
Case 0 To 9 '如果字符是數(shù)字
digit = digit + 1
Case Else '如果字符是其他字母
others = others + 1
End Select
Next
'以下代碼用來(lái)顯示統(tǒng)計(jì)出的結(jié)果值
txtResult1.Text = letters
txtResult2.Text = space
txtResult3.Text = digit
txtResult4.Text = others
txtResult5.Text = Len(InputStr)
End Sub
兩個(gè)文本框,一個(gè)command按鈕
Private Sub Command1_Click()
Dim i As Long
Dim CharNum As Long
CharNum = 0
For i = 1 To Len(Text1.Text)
If (Asc(Mid$(Text1.Text, i, 1)) = 65 And Asc(Mid$(Text1.Text, i, 1)) = 90) Or (Asc(Mid$(Text1.Text, i, 1)) = 97 And Asc(Mid$(Text1.Text, i, 1)) = 122) Then
CharNum = CharNum + 1
End If
Next
Text2.Text = "字母出現(xiàn)次數(shù):" CharNum
End Sub
private
sub
command1_click()
n
=
m
=
k
=
l
=
aa
=
bb
=
text1
do
until
len(bb)
=
aa
=
asc(bb)
bb
=
right(bb,
len(bb)
-
1)
aa
if
97
=
aa
and
aa
=
122
then
n
=
n
+
1
else
if
65
=
aa
and
aa
=
90
then
m
=
m
+
1
else
if
48
=
aa
and
aa
=
57
then
k
=
k
+
1
else
l
=
l
+
1
end
if
end
if
end
if
loop
picture1.print
"小寫(xiě)字母為";
n;
"個(gè)"
picture1.print
"大寫(xiě)字母為";
m;
"個(gè)"
picture1.print
"數(shù)字為";
k;
"個(gè)"
picture1.print
"特殊符號(hào)為";
l;
"個(gè)"
end
sub
你再調(diào)調(diào)