0

I am trying to write a code which will combine these values and format it in the following format to be used as control/validation ID. I have written a line of code that will merge these values together into a long string but I can't get the zeros to fill in. For month, I get 4 instead of 04 and for numeric value I get 1 digit number instead of having numbers with 0 padding to the left.
Can anyone help me put these in order?

'IN' + Year(YYYY) + Month(MM) + Numeric(0000)
Example:
Control 1 for April 2011
IN2011040001
Control 2 for April 2011
IN2011040002
Control 1 for May 2011
IN2011050001

Dim TestMonth As String = Format(Month(Now), "MM")
        Dim TestYear As String = Format(Year(Now), "YYYY")
        Dim TestNum As Integer

txtTest1.Text = "IN" & TestYear & TestMonth & ToString(TestNum+1)
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by bluehangook629
1

This will do the trick:

Dim TestNum As Integer 
txtTest1.Text = "IN" & Format(Now.Year,"0000") & Format(Now.Month,"00") & Format(TestNum+1,"0000")

Edited by dxider: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.