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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hexman

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

    Hello All,

    Writing my first console app I came across a difference in results. I want the "CurrMonthY ear" (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
  • Hexman

    #2
    Re: Results differ between Windows App and Console App. Why???

    Oops! The second block of code is "NOT working in Console App".

    On Tue, 27 Jun 2006 14:12:39 -0700, Hexman <Hexman@binary. com> wrote:
    [color=blue]
    >Hello All,
    >
    >Writing my first console app I came across a difference in results. I want the "CurrMonthY ear" (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[/color]

    Comment

    • Larry Lard

      #3
      Re: Results differ between Windows App and Console App. Why???


      Hexman wrote:[color=blue]
      > Oops! The second block of code is "NOT working in Console App".
      >
      > On Tue, 27 Jun 2006 14:12:39 -0700, Hexman <Hexman@binary. com> wrote:
      >[color=green]
      > >Hello All,
      > >
      > >Writing my first console app I came across a difference in results. I want the "CurrMonthY ear" (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:[/color][/color]

      So this is the part that's not working in the console app?
      [color=blue][color=green]
      > > Dim iMonth As Integer
      > > Dim iYear As Integer
      > > Dim CurrMonthYear as String
      > > iMonth = Month(Now)
      > > iYear = Year(Now)
      > > CurrMonthYear = Format(iMonth, "00") & "/" & iYear.ToString[/color][/color]

      When I do this I get "06/2006" in CurrMonthYear. How are you displaying
      CurrMonthYear?
      [color=blue][color=green]
      > >
      > >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[/color][/color]

      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

      Comment

      • Chris Dunaway

        #4
        Re: Results differ between Windows App and Console App. Why???

        Hexman wrote:
        [color=blue]
        > 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[/color]

        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.To String("MM/yyyy")

        ?


        Chris

        Comment

        • Hexman

          #5
          Re: Results differ between Windows App and Console App. Why???

          Answers in text.

          On 28 Jun 2006 02:40:10 -0700, "Larry Lard" <larrylard@hotm ail.com> wrote:
          [color=blue]
          >
          >Hexman wrote:[color=green]
          >> Oops! The second block of code is "NOT working in Console App".
          >>
          >> On Tue, 27 Jun 2006 14:12:39 -0700, Hexman <Hexman@binary. com> wrote:
          >>[color=darkred]
          >> >Hello All,
          >> >
          >> >Writing my first console app I came across a difference in results. I want the "CurrMonthY ear" (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:[/color][/color]
          >
          >So this is the part that's not working in the console app?[/color]
          yes, below.[color=blue]
          >[color=green][color=darkred]
          >> > Dim iMonth As Integer
          >> > Dim iYear As Integer
          >> > Dim CurrMonthYear as String
          >> > iMonth = Month(Now)
          >> > iYear = Year(Now)
          >> > CurrMonthYear = Format(iMonth, "00") & "/" & iYear.ToString[/color][/color]
          >
          >When I do this I get "06/2006" in CurrMonthYear. How are you displaying
          >CurrMonthYea r?[/color]
          I have used debug.print and msgbox(CurrMont hYear).[color=blue]
          >[color=green][color=darkred]
          >> >
          >> >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[/color][/color]
          >
          >I get the same thing as with Format.[/color]
          I don't. Maybe I was halucinating. I'll double check.

          Comment

          • Hexman

            #6
            Re: Results differ between Windows App and Console App. Why???

            On 28 Jun 2006 06:24:07 -0700, "Chris Dunaway" <dunawayc@gmail .com> wrote:
            [color=blue]
            >Hexman wrote:
            >[color=green]
            >> 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[/color]
            >
            >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:
            >
            >tbCurrMonthYea r.Text = DateTime.Now.To String("MM/yyyy")
            >
            >?[/color]

            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

            [color=blue]
            >
            >
            >Chris[/color]

            Comment

            • Chris Dunaway

              #7
              Re: Results differ between Windows App and Console App. Why???

              Hexman wrote:[color=blue]
              > On 28 Jun 2006 06:24:07 -0700, "Chris Dunaway" <dunawayc@gmail .com> wrote:
              >[/color]
              [color=blue]
              > 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.
              >[/color]

              Dim dtNextMonth As DateTime = DateTime.Now.Ad dMonths(1)
              Dim dtLastMonth As DateTime = DateTime.Now.Ad dMonths(-1)

              Comment

              • Hexman

                #8
                Re: Results differ between Windows App and Console App. Why???

                Thanks Chris.

                On 29 Jun 2006 06:43:39 -0700, "Chris Dunaway" <dunawayc@gmail .com> wrote:
                [color=blue]
                >Hexman wrote:[color=green]
                >> On 28 Jun 2006 06:24:07 -0700, "Chris Dunaway" <dunawayc@gmail .com> wrote:
                >>[/color]
                >[color=green]
                >> 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.
                >>[/color]
                >
                >Dim dtNextMonth As DateTime = DateTime.Now.Ad dMonths(1)
                >Dim dtLastMonth As DateTime = DateTime.Now.Ad dMonths(-1)[/color]

                Comment

                Working...