dポイントプレゼントキャンペーン実施中!

お世話になります。
あるTextBox内の例えば"a"の数を数える場合は、どの様にしたら良いでしょうか?

よろしくお願いします。

A 回答 (6件)

Dim d() As String


d = Split(Text1.Text, "a")
Debug.Print UBound(d)

をお試し下さい。
    • good
    • 0

Private Sub Command1_Click()


Dim aaa As String
Dim sp As Integer
Dim cnt As Integer

aaa = Text1.Text
cnt = 0
sp = 0
Do
sp = InStr(sp + 1, aaa, "a")
If sp > 0 Then
cnt = cnt + 1
End If
Loop While (sp > 0)
MsgBox cnt
End Sub
    • good
    • 0

Private Sub CommandButton1_Click()


  Dim I    As Integer
  Dim L    As Integer
  Dim N    As Integer
  Dim strText As String
  
  strText = "abcabcabc"
  L = Len(strText)
  For I = 1 To L
    N = N - (Mid$(strText, I, 1) = "a")
  Next I
  MsgBox N
End Sub
    • good
    • 0

Dim s As String


Dim cnt As Integer

s = textBox1.Text
cnt = 0

For I=0 To Len(s)
If Mid(s, I, 1) = "a" Then
cnt = cnt + 1
End If
Next I


変数 cnt の中身には、"a"の件数が格納されています。
    • good
    • 0

A = text1.text


CNT = 0
do until instr(A,"a") = 0
A = mid(instr(A,"a") + 1,len(A))
CNT = CNT + 1
loop

で最終的にCNTに数が入ってきませんか?
    • good
    • 0

=Len(元の文字列)-Len(Replace(元の文字列, "a", ""))



とか。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!