Results 1 to 11 of 11

Thread: add +1 value to textbox

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2014
    Posts
    50

    Angry add +1 value to textbox

    i wana add +1 value to textbox in vb6 every time i hit button
    format = 0000
    i wana when i click it show 0001
    then again i click it show 0002
    and so on
    i tried
    text1.text = text1.text +1
    but it give me 1, 2 , 3
    thats not format i need
    so plz help me guyz

  2. #2
    Addicted Member masoudk1990's Avatar
    Join Date
    Nov 2013
    Location
    Persia
    Posts
    172

    Re: add +1 value to textbox

    Text1.Text = Format(Val(Text1.Text + 1), "0000")
    Computer Enterprise Masoud Keshavarz
    For more information contact [email protected]

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2014
    Posts
    50

    Re: add +1 value to textbox

    Quote Originally Posted by masoudk1990 View Post
    Text1.Text = Format(Val(Text1.Text + 1), "0000")
    thanx work like charm

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2014
    Posts
    50

    Re: add +1 value to textbox

    how i set textbox limit to 9999

  5. #5
    Addicted Member masoudk1990's Avatar
    Join Date
    Nov 2013
    Location
    Persia
    Posts
    172

    Re: add +1 value to textbox

    Quote Originally Posted by vbnoob00 View Post
    how i set textbox limit to 9999
    Code:
    Private Sub Form_Load()
        Text1.MaxLength = 4
    End Sub
    
    Private Sub Command1_Click()
        If (Val(Text1.Text) < 1000) Then
            Text1.Text = Format(Val(Text1.Text + 1), "0000")
        End If
    End Sub
    If you wish user only be able to write numbers in textbox write this code in keypress event of textbox

    Code:
        If (KeyAscii < 48 And KeyAscii <> 8) Or (KeyAscii > 57) Then 'numbers and backspace only :)
            KeyAscii = 0
        End If
    Last edited by masoudk1990; Oct 27th, 2015 at 04:46 AM.
    Computer Enterprise Masoud Keshavarz
    For more information contact [email protected]

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2014
    Posts
    50

    Re: add +1 value to textbox

    Quote Originally Posted by masoudk1990 View Post
    Private Sub Form_Load()
    Text1.MaxLength = 4
    End Sub
    if it go over i wana display msg box error

  7. #7
    Addicted Member masoudk1990's Avatar
    Join Date
    Nov 2013
    Location
    Persia
    Posts
    172

    Re: add +1 value to textbox

    Quote Originally Posted by vbnoob00 View Post
    if it go over i wana display msg box error
    Code:
        If Val(Text1.Text < 1000) Then
            Text1.Text = Format(Val(Text1.Text + 1), "0000")
        Else
            MsgBox "Overflow!", vbCritical, "Error!"
        End If
    Computer Enterprise Masoud Keshavarz
    For more information contact [email protected]

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2014
    Posts
    50

    Re: add +1 value to textbox

    genius thanxxxx
    Quote Originally Posted by masoudk1990 View Post
    Code:
        If Val(Text1.Text < 1000) Then
            Text1.Text = Format(Val(Text1.Text + 1), "0000")
        Else
            MsgBox "Overflow!", vbCritical, "Error!"
        End If

  9. #9
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: add +1 value to textbox

    Quote Originally Posted by vbnoob00 View Post
    if it go over i wana display msg box error
    If you set the maxlength to 4, one CANNOT type in anything larger than 4 characters...so no msgbox would be needed anyway.....

  10. #10

    Thread Starter
    Member
    Join Date
    Dec 2014
    Posts
    50

    Re: add +1 value to textbox

    Quote Originally Posted by vbnoob00 View Post
    genius thanxxxx
    i keep getting that msgbox even on 0001

  11. #11
    Addicted Member masoudk1990's Avatar
    Join Date
    Nov 2013
    Location
    Persia
    Posts
    172

    Re: add +1 value to textbox

    Quote Originally Posted by vbnoob00 View Post
    i keep getting that msgbox even on 0001
    Sorry

    Code:
        If (Val(Text1.Text) < 9999) Then
            Text1.Text = Format(Val(Text1.Text + 1), "0000")
        Else
            MsgBox "Overflow!", vbCritical, "Error!"
        End If
    Last edited by masoudk1990; Oct 28th, 2015 at 03:10 AM.
    Computer Enterprise Masoud Keshavarz
    For more information contact [email protected]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width