Reputation: 3214
Module Module1
Public cccounter = 9
End Module
Public Class frmNim
Private Sub btnSelect_Click(sender As System.Object, e As System.EventArgs) Handles btnSelect.Click
MsgBox(cccounter)
End Sub
End Class
Why does this generate errors? I can't figure out any other way to make a simple counter go up by clicking on a button. This is frustrating me to no end. Is there something very simple that I'm obviously missing?
Upvotes: 1
Views: 2836
Reputation: 2571
Use MessageBox.Show(ccounter)
I think you're using the old VB6 coding. This won't work in VB.NET.
If you need your counter to go up, you do need an extra line of code:
ccounter += 1
EDIT:
Missed the declaration in the module (VB.Net bit rusty now a days)
You should declare the ccounter as a variable as mentioned by @Eddie Paz) I've made a quick sample that adds 1 at every click on the button.
Module Module1
Public ccounter As Integer = 9
End Module
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ccounter += 1
MessageBox.Show(ccounter)
End Sub
End Class
Upvotes: 5
Reputation: 2241
You're declaring cccounter as a variant in Module1. You should specify the type such as integer. In the btnSelect:
cccounter = cccounter + 1
MessageBox.Show(cccounter)
I think MsgBox still works in VB.Net, but I don't remember. I try to use the .NET way now.
Upvotes: 0