
visual stadio 2022 visual basicについての質問です。
windows Form アプリケーションを使用しています。
listboxにて
商品名1 x1 ¥100
商品名2 x1 ¥200
・
・
のようなものを表示させるプログラムを作成しました。最後に合計金額を求めたいのですが、¥より後ろの数字を抜き出して合計金額を求める方法はありますか?
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Connectcontrols() Connectevents() PictureBox1.Tag = "商品名1" PictureBox1.Image = Image.FromFile("test.bmp") PictureBox2.Tag = "商品名2" PictureBox2.Image = Image.FromFile("test.bmp") PictureBox3.Tag = "商品名3" PictureBox3.Image = Image.FromFile("test.bmp") End Sub Private mypicturebox() As System.Windows.Forms.PictureBox Private Sub Connectcontrols() mypicturebox = New System.Windows.Forms.PictureBox(3) {} mypicturebox(1) = PictureBox1 mypicturebox(2) = PictureBox2 mypicturebox(3) = PictureBox3 End Sub Private Sub Connectevents() For i As Integer = 1 To 3 AddHandler mypicturebox(i).Click, AddressOf mypicturebox_Click Next End Sub Private Sub Mypicturebox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim index As Integer = Array.IndexOf(mypicturebox, sender) If index = 1 Then Dim pbox As PictureBox = DirectCast(sender, PictureBox) Using child As New Form2() If child.ShowDialog() = DialogResult.OK Then ListBox1.Items.Add(pbox.Tag & child.StockCount & " ¥100") End If End Using End If 以下 index=3 まで行う Public Class Form2 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click _StockCount = NumericUpDown1.Value DialogResult = DialogResult.OK End Sub Private _StockCount As Decimal Public ReadOnly Property StockCount As Decimal Get Return _StockCount End Get End Property End Class
ここでは商品数3までですが実際は60まで作成しました。また最終的な合計はButtonを押すとTextBoxに表示される仕組みで考えています。修正完了しましたよろしくお願いします。
こちらの質問が複数のユーザーから「調査したこと・試したことが記載されていない質問」という指摘を受けました。





回答1件
あなたの回答
tips
プレビュー