Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim barcode As String = $"{TextBox2.Text}{TextBox3.Text}{TextBox4.Text}{TextBox5.Text}{TextBox6.Text}" Dim PictureBox As PictureBox = Nothing Dim maxheight As Integer = 40 Dim barcode39 As Code39BarcodeDraw = BarcodeDrawFactory.Code39WithoutChecksum Dim img As Image = barcode39.Draw(barcode, maxheight) If barcode.Length = 15 Then 'バーコードに反映させる文字数確認15文字なら If ComboBox1.SelectedItem = 1 Then 'コンボボックスで1が選ばれてたら PictureBox = PictureBox1 'それぞれのブロック内で PictureBox をセット If TextBox2.TextLength > 0 Then 'TextBox2に何か値が入っていたら PictureBox.Image = img 'PictureBoxにimgをセット LabelVal1.Text = barcode End If ElseIf ComboBox1.SelectedItem = 2 Then PictureBox = PictureBox2 If TextBox2.TextLength > 0 Then PictureBox.Image = img LabelVal2.Text = barcode End If ElseIf ComboBox1.SelectedItem = 3 Then PictureBox = PictureBox3 If TextBox2.TextLength > 0 Then PictureBox.Image = img LabelVal3.Text = barcode End If ElseIf ComboBox1.SelectedItem = 4 Then PictureBox = PictureBox4 If TextBox2.TextLength > 0 Then PictureBox.Image = img LabelVal4.Text = barcode End If End If Else MsgBox("全15文字で入力してください") End If If PictureBox IsNot Nothing Then MsgBox("ないです><") PictureBox.Image = img ' a が Nothing では無かった場合は画像を差し替え End If End Sub