View Full Version : How can I increment a number in a Public Shared sub?

03-21-2007, 05:10 PM
Hi, Iím trying to increment a number each time the user click on a button. My code happens to be in a button that is a Public Shared sub. Because it is a public shared, I canít access the query string in the usual manner like this:

Dim num As String = Request.QueryString("question")

So I canít use the Query String to increment my number.

The other trick I tried is to create a public class and set the number in that class. I then retrieve the number back from the class and try to increment it but each time I click on the button, the number resets to the original and does not increment. Hereís what the code looks like.

objNewNumber.QuestionChanged = newNumber
newNumber = newNumber + 1
qDetails = QuestionCatalog.GetQuestion(newNumber)
TheQuestion.lblTheQuestion.Text = qDetails.Question

That last piece of code may be a bit confusing but in short, all I want to do is to increment a number each time a user click on my button that is a Public Shared sub.

03-21-2007, 11:34 PM
If you want the new value saved, you need to set the member to the new value, not assign to a variable and increment the variable.

Try this.
(VB doesn't support ++ increment operator, I assume?)

objNewNumber.QuestionChanged = objNewNumber.QuestionChanged + 1
qDetails = QuestionCatalog.GetQuestion(objNewNumber.QuestionChanged)
TheQuestion.lblTheQuestion.Text = qDetails.Question