文字列の長さの長さを返す。
構文
len(文字列)
ちなみに空白も文字として数えてしまいます。
ソース
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim str As String = “String”
TextBox1.Text = Len(str)
End Sub
End Clas
実行結果は6
この場合はTextBoxから変数の文字列の数を調べてますが
TextBoxの文字数を取りたいなら他にも方法があります。
ソース
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim str As String = “String”
TextBox1.Text = Len(str)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = TextBox1.TextLength
End Sub
End Class
実行結果は
TextBox入力されている数が表示されます。
構文
テキストボックス名.TextLength