views:

325

answers:

4

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
+4  A: 
Dim i As Integer = Int32.Parse(txtAdd.Text)

or

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

There's no class called "Int."

Jekke
+1  A: 

Try Calling Convert.ToInt32(txtAdd.Text)

Dim i As Integer = Convert.ToInt32(txtAdd.Text)
VBNight
+2  A: 

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
foson
+1  A: 

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
Russ Cam
This doesnt crash the program but it doesn't add one to the text box. Im not familiar with Int32, what does it do?
Davey
Int32 is the .NET type for the VB.NET Integer type (or the C# int type). In your language of choice, it is interchangable with the native type.
Russ Cam
I've updated my answer to better show the example. Try it with a random text string, then try it with an integer... then try your original code in the same way :)
Russ Cam
This has been a great help. It is greatly appreciated.
Davey