H
Hexman
Hello All,
Writing my first console app I came across a difference in results. I want the "CurrMonthYear" (string) to appear as "06/2006". In the Windows App
thie following code works (it is placed in a textbox). In the Console App using the same code (except being placed in a string variable) the result
is "6/2006" (no leading zero). It appears that the Format functionworks differently between Windows and Console Apps. I got it to work by using a
format string in the ToString method. Just would like to know why.
Any ideas or reasoning? When to use Format over ToString or vice versa?
Thanks,
Hexman
Code working in Windows App:
Dim iMonth As Integer
Dim iYear As Integer
iMonth = Month(Now)
iYear = Year(Now)
tbCurrMonthYear.Text = Format(iMonth, "00") & "/" & iYear.ToString
Code NOT working in Windows App:
Dim iMonth As Integer
Dim iYear As Integer
Dim CurrMonthYear as String
iMonth = Month(Now)
iYear = Year(Now)
CurrMonthYear = Format(iMonth, "00") & "/" & iYear.ToString
Code rewritten to produce same result in Console App:
Dim iMonth As Integer
Dim iYear As Integer
Dim CurrMonthYear as String
iMonth = Month(Now)
iYear = Year(Now)
CurrMonthYear = iMonth.ToString("00") & "/" & iYear.ToString
Writing my first console app I came across a difference in results. I want the "CurrMonthYear" (string) to appear as "06/2006". In the Windows App
thie following code works (it is placed in a textbox). In the Console App using the same code (except being placed in a string variable) the result
is "6/2006" (no leading zero). It appears that the Format functionworks differently between Windows and Console Apps. I got it to work by using a
format string in the ToString method. Just would like to know why.
Any ideas or reasoning? When to use Format over ToString or vice versa?
Thanks,
Hexman
Code working in Windows App:
Dim iMonth As Integer
Dim iYear As Integer
iMonth = Month(Now)
iYear = Year(Now)
tbCurrMonthYear.Text = Format(iMonth, "00") & "/" & iYear.ToString
Code NOT working in Windows App:
Dim iMonth As Integer
Dim iYear As Integer
Dim CurrMonthYear as String
iMonth = Month(Now)
iYear = Year(Now)
CurrMonthYear = Format(iMonth, "00") & "/" & iYear.ToString
Code rewritten to produce same result in Console App:
Dim iMonth As Integer
Dim iYear As Integer
Dim CurrMonthYear as String
iMonth = Month(Now)
iYear = Year(Now)
CurrMonthYear = iMonth.ToString("00") & "/" & iYear.ToString