VB 2005, immediate window

  • Thread starter Thread starter Armin Zingler
  • Start date Start date
A

Armin Zingler

Hi,

I feel fooled.. In the immediate window, if I enter

? DateTime.Now.Kind

I get "Unspecified {0}". The result - I expected "local" - lead to some time
consuming deliberations. Today, I execute

MsgBox(DateTime.Now.Kind)
MsgBox(DateTime.Now.Kind.ToString)

as part of the source code, and I get "2" and "local" (where 2 = local, so
this is consistent).

Why does the immediate window lie? There, If I execute

?DateTime.Now.Kind.ToString

I even get the message "Run-time exception thrown :
System.ArgumentException - Cannot find the method on the object instance."

What? Did I overlook anything?


Armin
 
Armin Zingler said:
Hi,

I feel fooled.. In the immediate window, if I enter

? DateTime.Now.Kind

I get "Unspecified {0}". The result - I expected "local" - lead to some
time
consuming deliberations. Today, I execute

MsgBox(DateTime.Now.Kind)
MsgBox(DateTime.Now.Kind.ToString)

as part of the source code, and I get "2" and "local" (where 2 = local, so
this is consistent).

Why does the immediate window lie? There, If I execute

?DateTime.Now.Kind.ToString

I even get the message "Run-time exception thrown :
System.ArgumentException - Cannot find the method on the object instance."

What? Did I overlook anything?

The fact that you cannot issue that statement like that, because it needs an
object to work with to complete the statement.

dim strhldkind as string

strhldkind = datetime.now.kind.tostring

Now, after executing that statement in code, the *strhldkind* is now an
*object* and in the immediate window you can enter this.

?strhldkind

It will show *local*

or you could have done this in code

dim strhldkind as string = datetime.now.kind.tostring
 
Mr. Arnold said:
The fact that you cannot issue that statement like that, because it
needs an object to work with to complete the statement.

It is a complete statement. The result of the ToString method *is* an
object, it's a String. The "?" (aka print) command prints strings like they
are. It can take any expression as an argument, be it one simple variable
like strhldkind or be it a more complex expression. It does work with
"?datetime.now.kind", so why shouldn't it work with one more ".tostring"?
Just because it's one more dot? This doesn't make sense.

Or, why does, for example,
"?System.Windows.Forms.Screen.PrimaryScreen.BitsPerPixel" work as well as
"?System.Windows.Forms.Screen.PrimaryScreen.BitsPerPixel.ToString"?
without an exception?
dim strhldkind as string

strhldkind = datetime.now.kind.tostring

Now, after executing that statement in code, the *strhldkind* is now
an *object* and in the immediate window you can enter this.

?strhldkind

It will show *local*

or you could have done this in code

dim strhldkind as string = datetime.now.kind.tostring


Well, the problem is that it should also work like I explained before.

In addition, it is still wrong that it outputs "unspecified" in the
immediate window whereas I get "local" in the code.


Armin
 
It is a complete statement. The result of the ToString method *is* an
object, it's a String. The "?" (aka print) command prints strings like they
are. It can take any expression as an argument, be it one simple variable
like strhldkind or be it a more complex expression. It does work with
"?datetime.now.kind", so why shouldn't it work with one more ".tostring"?
Just because it's one more dot? This doesn't make sense.

Or, why does, for example,
"?System.Windows.Forms.Screen.PrimaryScreen.BitsPerPixel" work as well as
"?System.Windows.Forms.Screen.PrimaryScreen.BitsPerPixel.ToString"?
without an exception?






Well, the problem is that it should also work like I explained before.

In addition, it is still wrong that it outputs "unspecified" in the
immediate window whereas I get "local" in the code.

Armin

I'm inclined to believe it is a bug. Because it displays properly in
the Immediate window when using C#, but I get the same results you do
when using VB.

Chris
 
Back
Top