|
-
Oct 27th, 2015, 03:22 AM
#1
Thread Starter
Member
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
-
Oct 27th, 2015, 04:04 AM
#2
Addicted Member
Re: add +1 value to textbox
Text1.Text = Format(Val(Text1.Text + 1), "0000")
-
Oct 27th, 2015, 04:07 AM
#3
Thread Starter
Member
Re: add +1 value to textbox
 Originally Posted by masoudk1990
Text1.Text = Format(Val(Text1.Text + 1), "0000")
thanx work like charm
-
Oct 27th, 2015, 04:20 AM
#4
Thread Starter
Member
Re: add +1 value to textbox
how i set textbox limit to 9999
-
Oct 27th, 2015, 04:39 AM
#5
Addicted Member
Re: add +1 value to textbox
 Originally Posted by vbnoob00
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.
-
Oct 27th, 2015, 04:40 AM
#6
Thread Starter
Member
Re: add +1 value to textbox
 Originally Posted by masoudk1990
Private Sub Form_Load()
Text1.MaxLength = 4
End Sub
if it go over i wana display msg box error
-
Oct 27th, 2015, 04:48 AM
#7
Addicted Member
Re: add +1 value to textbox
 Originally Posted by vbnoob00
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
-
Oct 27th, 2015, 04:49 AM
#8
Thread Starter
Member
Re: add +1 value to textbox
genius thanxxxx
 Originally Posted by masoudk1990
Code:
If Val(Text1.Text < 1000) Then
Text1.Text = Format(Val(Text1.Text + 1), "0000")
Else
MsgBox "Overflow!", vbCritical, "Error!"
End If
-
Oct 27th, 2015, 06:17 AM
#9
Re: add +1 value to textbox
 Originally Posted by vbnoob00
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.....
-
Oct 27th, 2015, 06:23 PM
#10
Thread Starter
Member
Re: add +1 value to textbox
 Originally Posted by vbnoob00
genius thanxxxx
i keep getting that msgbox even on 0001
-
Oct 28th, 2015, 01:20 AM
#11
Addicted Member
Re: add +1 value to textbox
 Originally Posted by vbnoob00
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|