I making the game 2048 but as an extra I wanted the users to let them change the height of the square if they wanted to. If the users click on the 'btnSquare' button a inputbox will show up where they can fill in the height of the square. Their input will then be shown at the 'txtSquare' textbox right under the button which is already filled in with 4. The height of the square will then change to the text in that textbox. Now when I try to run this I get an System.Nullreference.Exception but I have no idea why since the textbox is initially filled with a 4. Debugger says this: Object reference not set to an instance of an object.
And also I am a very newbie at Visual Basic so I know that this method of mine might not work. If someone could help me and tell me what method is best to implement a height changer of the board to the game, I would be very thankful. PS: I'm Dutch so I'm sorry for the different language in the code.
Public Class Form1
Public square As Integer = (Convert.ToInt32(txtSquare.Text) - 1)
Dim rooster(square, square) As Label
Dim oldrooster(square, square) As Label
Public clickEnabled As Boolean = False
Public Sub btnOrde_Click(sender As Object, e As EventArgs) Handles btnSquare.Click
Dim message, title As String
Dim defaultValue As Integer
Dim userInput As Object
' Set prompt.
message = "Geef de hoogte van je spelbord in. (vb. 4 voor een 4x4 vierkant)"
' Set title.
title = "Initialisatie spelbord"
defaultValue = 4 ' Set default value.
' Display message, title, and default value.
userInput = InputBox(message, title, defaultValue)
' If user has clicked Cancel, set myValue to defaultValue
If userInput = "" Then userInput = defaultValue
If Not userInput > 1 Then userInput = defaultValue
square = (Convert.ToInt32(userInput) - 1)
txtSquare.Text = Convert.ToInt32(userInput)
End Sub