私なら、以下の様に処理します。
(1)入力文字を半角に変換
(2)数値に変換可能か判定し、数値変数に値をセットする
趣旨と違うかもしれませんが・・
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strInputValue As String
Dim n As Integer
Try
'空白除去後に半角に変換
strInputValue = StrConv(TextBox1.Text.Trim, VbStrConv.Narrow)
'「.」の位置を確認(LastIndexOfは最後の位置確認)
n = strInputValue.IndexOf(".")
If n = 0 Then
TextBox1.Focus()
Call MessageBox.Show("「.」が先頭にあります。")
ElseIf n = strInputValue.Length Then
TextBox1.Focus()
Call MessageBox.Show("「.」が最後尾にあります。")
ElseIf n < 0 Then
Call MessageBox.Show("「.」は使用していません。")
Else
Call MessageBox.Show("「.」は中間位置にあります。")
End If
'別ですが、
'数値扱いの確認
If IsNumeric(strInputValue) Then
Call MessageBox.Show("数値扱いです", "数値○")
Dim decValue As Decimal
decValue = Decimal.Parse(strInputValue)
Else
TextBox1.Focus()
Call MessageBox.Show("数値を入力して下さい。", "数値×", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch ex As Exception
Call MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
お礼
回答ありがとうございます。自分が今作ってるものにうまく合わせると実行出来ました。