Home All Groups Group Topic Archive Search About

Results differ between Windows App and Console App. Why???

Author
27 Jun 2006 9:12 PM
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

Author
27 Jun 2006 9:15 PM
Hexman
Oops!  The second block of code is "NOT working in Console App".

On Tue, 27 Jun 2006 14:12:39 -0700, Hexman <Hex***@binary.com> wrote:

Show quoteHide quote
>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
Author
28 Jun 2006 9:40 AM
Larry Lard
Hexman wrote:
Show quoteHide quote
> Oops!  The second block of code is "NOT working in Console App".
>
> On Tue, 27 Jun 2006 14:12:39 -0700, Hexman <Hex***@binary.com> wrote:
>
> >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:

So this is the part that's not working in the console 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

When I do this I get "06/2006" in CurrMonthYear. How are you displaying
CurrMonthYear?

> >
> >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

I get the same thing as with Format.

--
Larry Lard
Replies to group please
When starting a new topic, please mention which version of VB you are
using
Author
28 Jun 2006 9:06 PM
Hexman
Answers in text.

Show quoteHide quote
On 28 Jun 2006 02:40:10 -0700, "Larry Lard" <larryl***@hotmail.com> wrote:

>
>Hexman wrote:
>> Oops!  The second block of code is "NOT working in Console App".
>>
>> On Tue, 27 Jun 2006 14:12:39 -0700, Hexman <Hex***@binary.com> wrote:
>>
>> >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:
>
>So this is the part that's not working in the console app?
yes, below.
>
>> >        Dim iMonth As Integer
>> >        Dim iYear As Integer
>> >        Dim CurrMonthYear  as String
>> >        iMonth = Month(Now)
>> >        iYear = Year(Now)
>> >        CurrMonthYear = Format(iMonth, "00") & "/" & iYear.ToString
>
>When I do this I get "06/2006" in CurrMonthYear. How are you displaying
>CurrMonthYear?
I have used debug.print and msgbox(CurrMonthYear).
>
>> >
>> >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
>
>I get the same thing as with Format.
I don't.  Maybe I was halucinating.  I'll double check.
Author
28 Jun 2006 1:24 PM
Chris Dunaway
Hexman wrote:

> 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

I can't answer as to the apparent discrepancy between the windows app
and the console.  But do you need the iMonth and iYear variables?  Why
don't you just use:

tbCurrMonthYear.Text = DateTime.Now.ToString("MM/yyyy")

?


Chris
Author
28 Jun 2006 9:16 PM
Hexman
Show quote Hide quote
On 28 Jun 2006 06:24:07 -0700, "Chris Dunaway" <dunaw***@gmail.com> wrote:

>Hexman wrote:
>
>> 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
>
>I can't answer as to the apparent discrepancy between the windows app
>and the console.  But do you need the iMonth and iYear variables?  Why
>don't you just use:
>
>tbCurrMonthYear.Text = DateTime.Now.ToString("MM/yyyy")
>
>?

Because I calculate a series of dates (both forward and back).  eg;
04/2006, 05/2006, 06/2006, 07/2006, 08/2006, etc.

Now that I think about it I could do something *like*:

tbNextMonthYear = (DateTimeNow  + 1 month).ToString("MM/yyyy"), that is as soon as I figure out how to add/subtract ONE MONTH to the date.

Thanks for stimulating thought,

Hexman


Show quoteHide quote
>
>
>Chris
Author
29 Jun 2006 1:43 PM
Chris Dunaway
Hexman wrote:
> On 28 Jun 2006 06:24:07 -0700, "Chris Dunaway" <dunaw***@gmail.com> wrote:
>

> Because I calculate a series of dates (both forward and back).  eg;
> 04/2006, 05/2006, 06/2006, 07/2006, 08/2006, etc.
>
> Now that I think about it I could do something *like*:
>
> tbNextMonthYear = (DateTimeNow  + 1 month).ToString("MM/yyyy"), that is as soon as I figure out how to add/subtract ONE MONTH to the date.
>

Dim dtNextMonth As DateTime = DateTime.Now.AddMonths(1)
Dim dtLastMonth As DateTime = DateTime.Now.AddMonths(-1)
Author
29 Jun 2006 3:39 PM
Hexman
Thanks Chris.

Show quoteHide quote
On 29 Jun 2006 06:43:39 -0700, "Chris Dunaway" <dunaw***@gmail.com> wrote:

>Hexman wrote:
>> On 28 Jun 2006 06:24:07 -0700, "Chris Dunaway" <dunaw***@gmail.com> wrote:
>>
>
>> Because I calculate a series of dates (both forward and back).  eg;
>> 04/2006, 05/2006, 06/2006, 07/2006, 08/2006, etc.
>>
>> Now that I think about it I could do something *like*:
>>
>> tbNextMonthYear = (DateTimeNow  + 1 month).ToString("MM/yyyy"), that is as soon as I figure out how to add/subtract ONE MONTH to the date.
>>
>
>Dim dtNextMonth As DateTime = DateTime.Now.AddMonths(1)
>Dim dtLastMonth As DateTime = DateTime.Now.AddMonths(-1)