Question

I am trying to create a program that has a button and a text box. Everytime the button is pushed I want it to add one to the text box. I keep getting this error:

Overload resolution failed because no accessible 'Int' accepts this number of arguments

Also I am a huge n00b. Here is where I am at so far, thanks in advance.

Option Strict On

Public Class Form1

  Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click
    Dim i As Integer = Int.Parse(txtAdd.Text)
    i += 1
    txtAdd.Text = i.ToString()
  End Sub
End Class
Was it helpful?

Solution

Using the TryParse method will mean that the code does not throw a Format exception if the input cannot be parsed to an integer

Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim i as Integer
    If Integer.TryParse(txtAdd.Text, i) Then
        i += 1
        txtAdd.Text = i.ToString()
    End If

End Sub

OTHER TIPS

Dim i As Integer = Int32.Parse(txtAdd.Text)

or

Dim i As Integer = Integer.Parse(txtAdd.Text)

There's no class called "Int."

Looks like you meant to do: Integer.Parse(txtAdd.Text)

Also, I'd suggest making Integer i a member variable (field) of Form1. That way you wouldn't have to Parse it from string to int.

Public Class Form1

    Dim i As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        i += 1
        Me.TextBox1.Text = i.ToString()
    End Sub
End Class

Try Calling Convert.ToInt32(txtAdd.Text)

Dim i As Integer = Convert.ToInt32(txtAdd.Text)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top