Please help me with addition to variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jiexian
    New Member
    • May 2009
    • 2

    Please help me with addition to variable

    Please teach me how to do this the right way in vb6 or vb08. (preferbably vb6)

    What i want is to increase the value of Text1.text by 1 every time i click it. But with this code, Text1.text remains as 1 so matter how many times i click it.

    Code:
    Private Sub Form_Load()
     Dim cap As Integer
    cap = Val(Text1.Text)
    End Sub
    Code:
    Private Sub Command1_Click()
    cap = cap + 1
    Text1.Text = cap
    End Sub
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    try using Static instead of Dim.

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      Hi,

      In Command1_Click, just change the code to :


      [code=vb]
      Private Sub Command1_Click( )
      Text1.Text = Val(Text1.Text) +1
      End Sub
      [/code]

      Remove code from Form_Load

      Regards
      Veena

      Comment

      Working...