By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

increment 4 digit number automatically...its urgent

P: 64
how to increment 4 digit number automatically in vb.net windows appln

for example:

dc0001-----this is first userid
next time i click new button the user id automatically increased to dc0002
likewise

anybody to help me
Mar 27 '07 #1
Share this Question
Share on Google+
2 Replies


P: 4
use padright for your numeric varaible and cocant with your alphabet variable

eg

Dim IntNumber as integer
Dim StrCode as String


'eg
'IntNumber = 1
'strcode = dc

intnumber = intnumber.Tostring.PadRight("0",4)
strcode = strcode & intnumber

i hope it will help you
Mar 27 '07 #2

prabunewindia
100+
P: 199
how to increment 4 digit number automatically in vb.net windows appln

for example:

dc0001-----this is first userid
next time i click new button the user id automatically increased to dc0002
likewise

anybody to help me

Dim id As String = TextBox1.Text 'the last id no is in textbox1. you can get it
from database

Dim number As Integer = id.Substring(2, 4)
If (number < 9) Then
TextBox1.Text = id.Insert(5, (number + 1).ToString()).Remove(6)

ElseIf (number < 99) Then
TextBox1.Text = id.Insert(4, (number + 1).ToString()).Remove(6)
ElseIf (number < 999) Then
TextBox1.Text = id.Insert(3, (number + 1).ToString()).Remove(6)
ElseIf (number < 9999) Then
TextBox1.Text = id.Insert(2, (number + 1).ToString()).Remove(6)

End If

it will work untill the no goes dc9999
all the best
Mar 29 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.