彼ら!最終プロジェクトの自動販売機アプリを作成していますが、小さな問題が発生しました。実行しようとすると、次のエラーが表示されます。フォームの作成中にエラーが発生しました。詳細については、Exception.InnerException を参照してください。エラー: オブジェクト参照がオブジェクトのインスタンスに設定されていません。問題が発生したのは、私が double に変換した label.text と関係があると思います。誰かが私に回避策を提供できれば、それは大歓迎です!
Public Class VendingMachine
Dim balance As Double = CDbl(balanceLabel.Text)
'Dim intbalance As String = balanceLabel.Text
'Dim balance As Double = Convert.ToDouble(intbalance)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles depositButton.Click
If nickleButton.Checked = True Then
balance = +0.05
balanceLabel.Text = String.Format("{0:C}", balance)
End If
If dimeButton.Checked = True Then
balance = +0.1
balanceLabel.Text = String.Format("{0:C}", balance)
End If
If quarterButton.Checked = True Then
balance = +0.25
balanceLabel.Text = String.Format("{0:C}", balance)
End If
If dollarButton.Checked = True Then
balance = +1.0
balanceLabel.Text = String.Format("{0:C}", balance)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles refundButton.Click
balance = 0.0
balanceLabel.Text = String.Format("{0:C}", balance)
MsgBox("Money Refunded")
End Sub
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles starburstPicture.Click
If balance >= 1.25 Then
balance = balance - 1.25
Else
MsgBox("You do not have enough money to purchace that item.")
End If
End Sub
Private Sub jollyrancherPicture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jollyrancherPicture.Click
If balance >= 1.0 Then
balance = balance - 1.0
Else
MsgBox("You do not have enough money to purchace that item.")
End If
End Sub
Private Sub gummyPicture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gummyPicture.Click
If balance >= 0.75 Then
balance = balance - 0.75
Else
MsgBox("You do not have enough money to purchace that item.")
End If
End Sub
Private Sub peppermintPicture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles peppermintPicture.Click
If balance >= 0.75 Then
balance = balance - 0.75
Else
MsgBox("You do not have enough money to purchace that item.")
End If
End Sub
Private Sub VendingMachine_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
クラス終了