user3793009
user3793009

Reputation:

Change Variable Value on Each Click

I have a variable "row" and i want on each btnClick to change its value like this: {1,1,1,1,2,3,4,4,4,5,4..etc}

My solution is not working for each mouse click as i would like:

Dim row As Integer

Private Sub incrementVariable1(ByVal x As Integer)
    row= 1
End Sub
Private Sub incrementVariable2(ByVal x As Integer)
    row= 1
End Sub
Private Sub incrementVariable3(ByVal x As Integer)
    row= 2
End Sub

Private Sub btnUpdate_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdScore.Click

  incrementVariable1(row)
  incrementVariable2(row)
  incrementVariable3(row)

End Sub

Upvotes: 1

Views: 500

Answers (2)

Grim
Grim

Reputation: 672

I find it quite worrying that no-one seems to be able to understand the question...! Try this;

Dim RowData() As Integer = {1, 1, 1, 1, 2, 3, 4, 4, 4, 5, 4}
Dim Index As Integer
Dim row As Integer

Private Sub IncrementIndex(ByVal x As Integer)
    row = RowData(Index)
    Index += 1
    If Index = RowData.Length Then Index = 0
End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdScore.Click
    IncrementIndex(row)
End Sub

Upvotes: 1

Suji
Suji

Reputation: 1326

I am totally confused about the counting {1,1,2,3,4..etc}, i thought it was a typing mistake, but as a programmer i have to do this, take a look through my code : it gives the expected result

 Dim rows As Integer = 0
 Dim i As Integer = 2
 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
   rows += 1 ' Inrement rows by 1 in each click
   If i AndAlso rows = 2 Then ' true only if both i and rows are having 2
   ListBox1.Items.Add(rows - 1) ' display the result in the listbox in each click
   i = 0 ' 0 is assigned to i for make the condetion faulse for the next time
   rows -= 1 ' in this case rows is decreased by 1
   Else
   ListBox1.Items.Add(rows) ' display the result in the listbox in each click
   End If    
End Sub 

Upvotes: 0

Related Questions