My current assignment involves creating a game in Visual Basic, and I have chosen a basic Idle Game
I'm trying to have the program create a new button every time the total amount of Bits (the unit I'm using as the "currency") is a multiple of 2, without it creating the same button twice, however despite it registering 0 errors the moment the Bit counter hits 2 the program crashes
I'm not very well versed in Visual Basic, as my typical programming language is Python 3.
Code is below, and all named variables have been defined.
Private Sub btnSendBit_Click(sender As Object, e As EventArgs) Handles btnSendBit.Click lblBitAmount.Text = BitTotal + (1 * ClickMult) BitTotal += (1 * ClickMult) If BitTotal Mod 2 = 0 Then Dim btn As Button = New Button btn.Location = New Point(128 + (ButtonAmount * 30), 32) btn.Name = btnUpgrade(ButtonAmount) btn.Text = ButtonAmount & "bits" Me.Controls.Add(btn) AddHandler btn.Click, AddressOf BuyUpgrade End If End Sub Sub BuyUpgrade() BitGain += ButtonAmount End Sub Private ReadOnly Property btnUpgrade(buttonAmount As Integer) As String Get Throw New NotImplementedException() End Get End Property Edit: I read the current comments, and I have to reiterate that I am a total novice with VB. The code I used for the dynamic button generation was copied from elsewhere since I couldn't find any documentation on it in my (admittedly brief) search. I barely understand what each part is supposed to do aside from the explicit stuff like defining the new button and where its located. If someone could explain a fix as though talking to someone with barely any knowledge of the subject it would be very helpful. Thank you to the people that gave suggestions and pointed out the exception.
https://stackoverflow.com/questions/65728587/infinite-dynamic-button-creation January 15, 2021 at 07:54AM
没有评论:
发表评论