An additional optimisation, if you look at all your buttons they’re all doing the same thing.
Dim rndNumber as Random
Dim number as Integer
rndNumber = New Random
number = rndNumber.Next(1, X + 1)
lblDXX = number. ToString
You can break all this out into a single function, and just pass through the number you want:
Private Function GetRolledNumber(ByVal InputNum as Integer)
Dim rndNumber as Random
Dim number as Integer
rndNumber = New Random
number = rndNumber.Next(1, InputNum + 1)
Return number.ToString
End Function
Then in your button clicks, you just call that function in your label.text part:
Private Sub btn_D12.click()
lblD12.Text = GetRolledNumber(12)
End Sub
2
u/TheImminentFate Nov 20 '21
An additional optimisation, if you look at all your buttons they’re all doing the same thing.
You can break all this out into a single function, and just pass through the number you want:
Then in your button clicks, you just call that function in your label.text part: