473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 "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
Jun 27 '06 #1
7 963
Oops! The second block of code is "NOT working in Console App".

On Tue, 27 Jun 2006 14:12:39 -0700, Hexman <He****@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
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

Jun 27 '06 #2

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

On Tue, 27 Jun 2006 14:12:39 -0700, Hexman <He****@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

Jun 28 '06 #3
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

Jun 28 '06 #4
Answers in text.

On 28 Jun 2006 02:40:10 -0700, "Larry Lard" <la*******@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 <He****@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.
Jun 28 '06 #5
On 28 Jun 2006 06:24:07 -0700, "Chris Dunaway" <du******@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



Chris

Jun 28 '06 #6
Hexman wrote:
On 28 Jun 2006 06:24:07 -0700, "Chris Dunaway" <du******@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)

Jun 29 '06 #7
Thanks Chris.

On 29 Jun 2006 06:43:39 -0700, "Chris Dunaway" <du******@gmail.com> wrote:
Hexman wrote:
On 28 Jun 2006 06:24:07 -0700, "Chris Dunaway" <du******@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)

Jun 29 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: gregpinero | last post by:
Hey everyone, I'm trying to call a system command "svnlook log \arms" from within python and process the results. However I'm having trouble getting the results of the command back into python....
4
by: Anonymous | last post by:
I have written a series of applications in different languages to compare them. In my first one, I am testing console output. On my first test OS (Mandrake Linux), C++ came in second, just behind...
4
by: Steve - DND | last post by:
We're currently working on a project with v1.0 of the .Net Framework, and are experiencing some issues with System.Uri. We have two Uri objects: Uri uriBase = new...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
1
by: Don | last post by:
I am new to Indexing Services, have been researching the MS Site as well as web articles on DevHood, etc. I have set up a seperate catalog ("KnowledgeBase") on Win XP with a number of files. I am...
8
by: Mythran | last post by:
Here is some code the provides some really interesting results! First, read over the two methods in class 'A' and compare. Just by looking at them, both results appear to return the EXACT same...
2
by: Martijn Mulder | last post by:
/* GraphicsPath.IsVisible() gives unexpected results. I fill a System.Drawing.Drawing2D.GraphicsPath-object with PointF-structures that define the unit-square (0,0), (1,0), (1,1) and (0,1). Then I...
12
by: Daniel Earwicker | last post by:
I wrote two trivial test programs that do a billion iterations of a virtual method call, first in C# (Visual Studio 2005): Thing t = new DerivedThing(); for (System.Int64 n = 0; n < 10000000000;...
1
by: sunshine19992 | last post by:
Not sure if others have come acrossed this bit I have a program for a C# class I am taking and during my troubleshooting I have found that if I turn on a breakpoint and then press F5 to continue...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.