|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Results differ between Windows App and Console App. Why???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 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 Hexman wrote:
Show quoteHide quote > Oops! The second block of code is "NOT working in Console App". So this is the part that's not working in the 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: > > Dim iMonth As Integer When I do this I get "06/2006" in CurrMonthYear. How are you displaying> > Dim iYear As Integer > > Dim CurrMonthYear as String > > iMonth = Month(Now) > > iYear = Year(Now) > > CurrMonthYear = Format(iMonth, "00") & "/" & iYear.ToString CurrMonthYear? > > I get the same thing as with Format.> >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 -- Larry Lard Replies to group please When starting a new topic, please mention which version of VB you are using Answers in text.
Show quoteHide quote On 28 Jun 2006 02:40:10 -0700, "Larry Lard" <larryl***@hotmail.com> wrote: I have used debug.print and msgbox(CurrMonthYear).> >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 don't. Maybe I was halucinating. I'll double check.>> > >> >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. Hexman wrote:
> Code working in Windows App: I can't answer as to the apparent discrepancy between the windows app> Dim iMonth As Integer > Dim iYear As Integer > iMonth = Month(Now) > iYear = Year(Now) > tbCurrMonthYear.Text = Format(iMonth, "00") & "/" & iYear.ToString 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
Show quote
Hide quote
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;>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") > >? 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 Hexman wrote:
> On 28 Jun 2006 06:24:07 -0700, "Chris Dunaway" <dunaw***@gmail.com> wrote: Dim dtNextMonth As DateTime = DateTime.Now.AddMonths(1)> > 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 dtLastMonth As DateTime = DateTime.Now.AddMonths(-1) 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)
same sub, multiple control click events
same sub, multiple control click events OpenFileDialog how to search a datatable-can I use sql on a vb2005 datatable? Navigate through a dataset best starting point for complete newbies? Reference to a control error. Toolstrip Unicode Application Question Default MessageBox Title Delegates: String or Integer |
|||||||||||||||||||||||