I am creating a custom name for a form. An example of the name is: PR-00S-0208-4593. The PR stand for purchase request, the 00S refers to type of purchase request, 0208 refers to month and year request was made, and the 4593 is a random generated number. I got all the parts figured out and successfully got it to generate the number to PR-00S-022008-4593.
I am needing to convert the 4 digit year to a 2 digit year. Any suggestions? I coded everything within visual studio 2005 using vb and it worked flawless. I started copying over to infopath and I get an error when formatting the year to two digits. Below is my code:
Public
strMonth As String = System.DateTime.Now.MonthPublic strMonthNumber As String
Public datYear As Date = System.DateTime.NowPublic strFormatted As String = Format(datYear, datYear, "yy")
Dim objRandom As New System.Random(CType(System.DateTime.Now.Ticks Mod System.Int32.MaxValue, Integer))
Public Function GetRandomNumber(Optional ByVal Low As Integer = 1, Optional ByVal High As Integer = 100) As Integer
' Returns a random number,
' between the optional Low and High parametersReturn objRandom.Next(Low, High + 1)
End Function
Then on the load event handler, i have this code:
Dim
intRandom As Integer
intRandom = GetRandomNumber(1001, 9999)
thisXDocument.DOM.selectSingleNode(
"/dfs:myFields/my:PRNUMBER").text = "PR-00S-" & strMonthNumber & datYear & "-" & intRandom.ToString
The error I get is: Value of type 'Date' cannot be converted to 'System.Type' from when I try to format the year to 2 digits.
Any suggestions? Thanks.