0

So here, i am building a clicker game, i have tried again 3 times now. I have moved from C# to VB.NET recently, and it's been good, until now. So i declared a variable for CoinsPerClick, and the problem is when i click the button to get coins, instead of 0, 1, 2, 3, it does 0, 01, 011, 0111, 01111, 011111. How do i do 1, 2, 3 instead of 011111111?

Declared Variable:

' Public Class Frm_MainForm (ignore this, StackOverflow did not want to show the Public Class Frm_MainForm)
' Declare Important Variables
Dim CoinsPerClick As String = 1

Private Sub But_Click_Click(sender As Object, e As EventArgs) Handles But_Click.Click
' Add CoinsPerClick To Tb_Coins.Text
Tb_Coins.Text += CoinsPerClick
End Sub
End Class


ridhomblr
  • 47
  • 1
  • 9
  • 1
    You need to declare the `CoinsPerClick` variable as `Integer` and you need to [parse](https://stackoverflow.com/a/17247701/13485806) the `.Text` to Integer as well. Then, and only then, you can add them together. On a related note, I strongly suggest that you use `Option Strict On` in all your VB projects ([here's how](https://stackoverflow.com/q/5076851/13485806)). – ICloneable Oct 31 '20 at 04:57
  • 1
    You can't do math with strings. Use integers. – Ken White Oct 31 '20 at 05:00
  • Thanks! It works flawlessly with no errors! Thanks, ICloneAble and Ken White! – ridhomblr Oct 31 '20 at 05:04
  • 1
    If you would turn on Option Strict in Project Properties -> Compile Tab, you would have known immediately that 1 is not a String. – Mary Oct 31 '20 at 05:04
  • Sorry, im a noob in VB.net, C# gives so many errors, and dim does not work, and, i used to develop in batch. – ridhomblr Oct 31 '20 at 05:06
  • 2
    @Mary I would also turn it on in Visual Studio's settings so that it's on by default for future projects. – ICloneable Oct 31 '20 at 05:08

0 Answers0