プロが教えるわが家の防犯対策術!

イメージとしてはフォームにテキストボックスを作って、その中に数字を入れます。
ボタンを押すとメッセージボックスが出てきて数字がカンマ付きで表示させたいのですが、どうしても普通の数字になってしまいます。

ヒントだけでも教えていただけないでしょうか。
お願いいたします。

A 回答 (2件)

>その中に数字を入れます。


どんな風に?
>てきて数字がカンマ付きで表示させたいのですが
数字1桁ごとか
何かデリミタ(区切り)があるのか?
書式設定置のようなことを考えているのか。
一旦数値化してVB6ならFormat関数で
Sub test02()
a = "1234567" 'TextBoxの値
n = Val(a)
m = Format(n, "#,###")
MsgBox m
End Sub
>どうしても普通の数字になってしまいます
入力した通りのことか?
>になってしまいます。
プログラムコードはどうしている?
ーー
VB6かVB.NET系か?
上記のようなことは質問文から判りますか。
自分の文章を読み直してください。
    • good
    • 0

Option Explicit On


Option Strict On
Option Compare Binary
Option Infer Off 'VB2008以上

Class Q4271249A
Inherits System.Windows.Forms.Form
Private TextBox1 As System.Windows.Forms.TextBox
Private Button1 As System.Windows.Forms.Button

Public Sub New()
TextBox1 = New System.Windows.Forms.TextBox()
Button1 = New System.Windows.Forms.Button()
Me.Width = 800
Me.Height = 600

TextBox1.Width = 500
TextBox1.Top = 200

Button1.Width = 500
Button1.Top = 300
Button1.Text = "表示"
AddHandler Button1.Click, AddressOf Button1_Click

Me.Controls.Add(TextBox1)
Me.Controls.Add(Button1)


End Sub

Private Sub Button1_Click(Sender As Object,e As System.EventArgs)
Try
Dim NumberFormatInfo As System.Globalization.NumberFormatInfo = New System.Globalization.NumberFormatInfo()
'一応Doubleで読んでいる。Integerにするかは好きにしてくれ。

Dim Input As Double = Double.Parse(TextBox1.Text)
System.Windows.Forms.MessageBox.Show(Input.ToString("N", NumberFormatInfo))

Catch err As System.FormatException

System.Windows.Forms.MessageBox.Show(err.ToString())

End Try
End Sub


Public Shared Sub Main()
Dim Form1 As Q4271249A
Form1 = New Q4271249A()
Form1.ShowDialog()

End Sub

End Class
    • good
    • 0

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