none
procedures in textbox RRS feed

  • Question

  • How do i get a number to count up in a textbox just have no clue on this lol its been a while

    Tuesday, July 23, 2019 8:06 PM

All replies

  • Hello,

    Use a NumericUpDown control or if using a TextBox increment the value via a button click.

    Private Sub IncrementButton_Click(sender As Object, e As EventArgs) _
        Handles IncrementButton.Click
    
        Dim value As Integer = 0
        If Integer.TryParse(TextBox1.Text, value) Then
            TextBox1.Text = (value + 1).ToString()
        End If
    
    End Sub

    Or even the leave event

    Private Sub TextBox1_Leave(sender As Object, e As EventArgs) _
        Handles TextBox1.Leave
    
        Dim value As Integer = 0
        If Integer.TryParse(TextBox1.Text, value) Then
            TextBox1.Text = (value + 1).ToString()
        End If
    
    End Sub


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, July 23, 2019 8:30 PM
    Moderator
  • Hi JACarley,

    If you want it counting up say by 1 every second then add
    a TextBox and a Timer to a Form and try this code please.
    >>

    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            TextBox1.Text = 1.ToString
            Timer1.Interval = 1000
            Timer1.Start()
    
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    
            Dim num As Integer = 0
            Try
                num = CType(TextBox1.Text, Integer)
                num += 1
                TextBox1.Text = num.ToString
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
        End Sub
    
    End Class

    Regards,

    John.


    Regards,

    profile for John Anthony Oliver at Stack Overflow, Q&A for professional and enthusiast programmers

    Click this link to see the NEW way of how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    App Hub for Windows Phone & XBOX 360 developers.

    Tuesday, July 30, 2019 3:03 AM