Author |
Message |
bhale

|
Posted: Tue Jul 06 09:12:17 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
Is there any way to force a variable in the immediate window to be of
a particular type (integer, byte, double, date, etc.)?
It looks like all variables defined (implicitly) in the immediate
window are type Variant. Is that correct?
Thanks
--
Running MS VB 6.0 Pro (SP5) on Win2K-SR2
For email, use Usenet-20031220 at spamex.com
Visual Studio330
|
|
|
|
 |
Bob

|
Posted: Tue Jul 06 09:12:17 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
> Is there any way to force a variable in the immediate window to be of
> a particular type (integer, byte, double, date, etc.)?
No
> It looks like all variables defined (implicitly) in the immediate
> window are type Variant. Is that correct?
Yes; the closest you can come is specifying the type in the assignment:
x=CDbl(42)
y=42!
Why is this a problem? If you elaborate on why it is an issue maybe a
better solution can be found.
--
Reply to the group so all can participate
VB.Net... just say "No"
|
|
|
|
 |
Ralph

|
Posted: Tue Jul 06 09:29:36 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
> Is there any way to force a variable in the immediate window to be of
> a particular type (integer, byte, double, date, etc.)?
>
> It looks like all variables defined (implicitly) in the immediate
> window are type Variant. Is that correct?
>
> Thanks
>
Use the postscript datatype operators...
$ := String
% := Integer
& := Long
! := Single
# := Double
@ := Currency
|
|
|
|
 |
Top

|
Posted: Tue Jul 06 09:38:05 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
>> Is there any way to force a variable in the immediate window to be of
>> a particular type (integer, byte, double, date, etc.)?
>
>No
>
>> It looks like all variables defined (implicitly) in the immediate
>> window are type Variant. Is that correct?
>
>Yes; the closest you can come is specifying the type in the assignment:
>x=CDbl(42)
>y=42!
>
>Why is this a problem? If you elaborate on why it is an issue maybe a
>better solution can be found.
It's not much of a problem. I was just trying to use the immediate
window to test some data type conversions. I was getting odd results
that were different from what happens in running code. I deduced that
all immediate window variables are type Variant, which makes testing
data type conversions difficult.
I don't have a specific example right now. The next time one occurs,
I'll post something.
Thanks
--
Running MS VB 6.0 Pro (SP5) on Win2K-SR2
For email, use Usenet-20031220 at spamex.com
|
|
|
|
 |
Bob

|
Posted: Tue Jul 06 09:42:03 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
>> Is there any way to force a variable in the immediate window to be of
>> a particular type (integer, byte, double, date, etc.)?
>>
>> It looks like all variables defined (implicitly) in the immediate
>> window are type Variant. Is that correct?
>>
>> Thanks
>>
>
> Use the postscript datatype operators...
Learn something new even after all this time! I never tried using those
archaic, ugly postfix characters in the immediate window!
--
Reply to the group so all can participate
VB.Net... just say "No"
|
|
|
|
 |
Ralph

|
Posted: Tue Jul 06 09:43:35 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
My example was truncated - you need colons (or continuation operator) to
separate declarations from statements and will look like this...
Type in Intermediate Window:
a# = 3: b& = 5: ? a# * b&
Will print: 15
There is one "Gotcha" - once you declare a variable as a particular type in
the intermediate window, you can't change it, e.g., the following 3rd line
will produce an error....
a# = 3: b& = 5: ? a# * b&
15
Sometimes you can merely 'restart' the debug, but often you have to
'restart' the IDE to get an ancient declaration out of its system. <g>
-ralph
>
> > Is there any way to force a variable in the immediate window to be of
> > a particular type (integer, byte, double, date, etc.)?
> >
> > It looks like all variables defined (implicitly) in the immediate
> > window are type Variant. Is that correct?
> >
> > Thanks
> >
>
> Use the postscript datatype operators...
> $ := String
> % := Integer
> & := Long
> ! := Single
> # := Double
>
>
>
>
>
|
|
|
|
 |
Bob

|
Posted: Tue Jul 06 09:43:16 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
>
>>> Is there any way to force a variable in the immediate window to be
>>> of a particular type (integer, byte, double, date, etc.)?
>>
>> No
>>
>>> It looks like all variables defined (implicitly) in the immediate
>>> window are type Variant. Is that correct?
>>
>> Yes; the closest you can come is specifying the type in the
>> assignment: x=CDbl(42)
>> y=42!
>>
>> Why is this a problem? If you elaborate on why it is an issue maybe
>> a better solution can be found.
>
> It's not much of a problem. I was just trying to use the immediate
> window to test some data type conversions. I was getting odd results
> that were different from what happens in running code. I deduced that
> all immediate window variables are type Variant, which makes testing
> data type conversions difficult.
As another posted apparently using the type characters works. You can also
just use a conversion function to do explicitly what VB would do implicitly:
x=CLng(y)
--
Reply to the group so all can participate
VB.Net... just say "No"
|
|
|
|
 |
Larry

|
Posted: Tue Jul 06 11:18:59 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
> > Use the postscript datatype operators...
>
> Learn something new even after all this time! I never tried using those
> archaic, ugly postfix characters in the immediate window!
That's an odd statement seeing that you made use of them in your
earlier post, about a half hour before Ralph mentioned them....
???
LFS
|
|
|
|
 |
Jeff

|
Posted: Tue Jul 06 13:13:50 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
> > > Use the postscript datatype operators...
> >
> > Learn something new even after all this time! I never tried using those
> > archaic, ugly postfix characters in the immediate window!
>
> That's an odd statement seeing that you made use of them in your
> earlier post, about a half hour before Ralph mentioned them....
>
> ???
> LFS
Yeah, Bob. Age kicking in?
|
|
|
|
 |
Bob

|
Posted: Tue Jul 06 13:37:42 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
>
>>>> Use the postscript datatype operators...
>>>
>>> Learn something new even after all this time! I never tried using
>>> those archaic, ugly postfix characters in the immediate window!
>>
>> That's an odd statement seeing that you made use of them in your
>> earlier post, about a half hour before Ralph mentioned them....
>>
>> ???
>> LFS
>
> Yeah, Bob. Age kicking in?
In this thread? Are you sure you aren't just seeing messages out of synch?
I wouldn't be surprised if I did (it's been a senior morning all right) but
I definitely don't remember ever trying using a variable with a type suffix
before seeing Ralph's post. I did post something shortly afterwards using
that technique so maybe things just got out of order.
--
Reply to the group so all can participate
VB.Net... just say "No"
|
|
|
|
 |
Gale

|
Posted: Tue Jul 06 13:42:48 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
> In this thread? Are you sure you aren't just seeing messages out of synch?
> I wouldn't be surprised if I did (it's been a senior morning all right) but
> I definitely don't remember ever trying using a variable with a type suffix
> before seeing Ralph's post. I did post something shortly afterwards using
> that technique so maybe things just got out of order.
Your first post in this thread <g>:
Yes; the closest you can come is specifying the type in the
assignment:
x=CDbl(42)
y=42!
Gale.
|
|
|
|
 |
Rick

|
Posted: Tue Jul 06 13:50:22 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
> > In this thread? Are you sure you aren't just seeing messages out of
synch?
> > I wouldn't be surprised if I did (it's been a senior morning all
right) but
> > I definitely don't remember ever trying using a variable with a type
suffix
> > before seeing Ralph's post. I did post something shortly afterwards
using
> > that technique so maybe things just got out of order.
>
> Your first post in this thread <g>:
>
> Yes; the closest you can come is specifying the type in the
> assignment:
> x=CDbl(42)
> y=42!
Maybe he was just really emphasizing the 42 by following it with an
exclamation mark?<g>
Rick
|
|
|
|
 |
Jeff

|
Posted: Tue Jul 06 14:08:51 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
> > Your first post in this thread <g>:
> >
> > Yes; the closest you can come is specifying the type in the
> > assignment:
> > x=CDbl(42)
> > y=42!
>
> Maybe he was just really emphasizing the 42 by following it with an
> exclamation mark?<g>
Or maybe he forgot what language he was using and was trying to do a
factorial! Yeah, that's the ticket....
|
|
|
|
 |
Gale

|
Posted: Tue Jul 06 14:10:14 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
On Tue, 6 Jul 2004 14:50:22 -0400, "Rick Rothstein"
> > Your first post in this thread <g>:
> >
> > Yes; the closest you can come is specifying the type in the
> > assignment:
> > x=CDbl(42)
> > y=42!
>
> Maybe he was just really emphasizing the 42 by following it with an
> exclamation mark?<g>
Well, that could be the answer (to Life, The Universe, and Everything)
<g>.
Oops, have you had Hitch-hiker's Guide to the Galaxy that side of the
pond?
Gale.
|
|
|
|
 |
Bob

|
Posted: Tue Jul 06 14:18:28 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
<cut>
> Your first post in this thread <g>:
>
> Yes; the closest you can come is specifying the type in the
> assignment:
> x=CDbl(42)
> y=42!
That explains the confusion; my wording on the later post was not good. I
only meant that I never use the characters on variable names. If I wanted a
Single t would never have occurred to me to do
y!=42
|
|
|
|
 |
Jeff

|
Posted: Tue Jul 06 14:19:09 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
> > Maybe he was just really emphasizing the 42 by following it with an
> > exclamation mark?<g>
>
> Well, that could be the answer (to Life, The Universe, and Everything)
> <g>.
>
> Oops, have you had Hitch-hiker's Guide to the Galaxy that side of the
> pond?
Other than Benny Hill, that may be one of the best-known British TV shows in
America. At least for my generation....
Now run, before you get ****ed.
|
|
|
|
 |
Bob

|
Posted: Tue Jul 06 14:19:51 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
<cut>
> Oops, have you had Hitch-hiker's Guide to the Galaxy that side of the
> pond?
Yes and I've read it many times. That's why almost every example I post
with a numeric value uses 42.
|
|
|
|
 |
Bob

|
Posted: Tue Jul 06 14:43:25 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
> Other than Benny Hill, that may be one of the best-known British TV
> shows in America. At least for my generation....
didn't know it was a TV show; it's a great set of books
|
|
|
|
 |
Gale

|
Posted: Tue Jul 06 14:49:43 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
> > Other than Benny Hill, that may be one of the best-known British TV
> > shows in America. At least for my generation....
>
> didn't know it was a TV show; it's a great set of books
Yes, the TV series actually followed the book quite closely for a
change.
Now be quiet, or I will read you some of my poetry! <g>
Gale.
|
|
|
|
 |
Ralph

|
Posted: Tue Jul 06 15:09:52 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
>
> > > Other than Benny Hill, that may be one of the best-known British TV
> > > shows in America. At least for my generation....
> >
> > didn't know it was a TV show; it's a great set of books
>
> Yes, the TV series actually followed the book quite closely for a
> change.
>
> Now be quiet, or I will read you some of my poetry! <g>
>
> Gale.
>
Ha. If we are going to get picky ... It was first a Radio Show, then a TV
Show, then the books.
-ralph
|
|
|
|
 |
Top

|
Posted: Tue Jul 06 20:36:21 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
On Tue, 6 Jul 2004 09:45:05 -0500, "Ralph"
>My example was truncated - you need colons (or continuation operator) to
>separate declarations from statements and will look like this...
>
>Type in Intermediate Window:
> a# = 3: b& = 5: ? a# * b&
>Will print: 15
>
>There is one "Gotcha" - once you declare a variable as a particular type in
>the intermediate window, you can't change it, e.g., the following 3rd line
>will produce an error....
>
> a# = 3: b& = 5: ? a# * b&
>15
>
>Sometimes you can merely 'restart' the debug, but often you have to
>'restart' the IDE to get an ancient declaration out of its system. <g>
So is
a%=3
in the immediate window exactly equal to:
Dim a as integer
a=3
in regular code?
That is very helpful.
--
Running MS VB 6.0 Pro (SP5) on Win2K-SR2
For email, use Usenet-20031220 at spamex.com
|
|
|
|
 |
Top

|
Posted: Tue Jul 06 20:42:03 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
>> It's not much of a problem. I was just trying to use the immediate
>> window to test some data type conversions. I was getting odd results
>> that were different from what happens in running code. I deduced that
>> all immediate window variables are type Variant, which makes testing
>> data type conversions difficult.
>
>As another posted apparently using the type characters works. You can also
>just use a conversion function to do explicitly what VB would do implicitly:
>
>x=CLng(y)
I don't think this equivalent to x#=y.
Compare this:
j%=3 'define an integer variable
?j
3
j=3.3
?j
3 'value was truncated as it should be
j#=3.3 'compiler error, type mismatch
j%=5 'OK to reassign as same type
?5
5
with this:
k=cint(3) 'define a variant
?k
3
k=3.3
?k
3.3 'not truncated, hence not type integer
k%=3 'compiler error, type mismatch, not integer
Thanks
--
Running MS VB 6.0 Pro (SP5) on Win2K-SR2
For email, use Usenet-20031220 at spamex.com
|
|
|
|
 |
Randy

|
Posted: Tue Jul 06 20:51:59 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
Yes.
--
Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
: So is
: a%=3
: in the immediate window exactly equal to:
: Dim a as integer
: a=3
: in regular code?
|
|
|
|
 |
Randy

|
Posted: Tue Jul 06 20:54:28 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
Variants morph into whatever data type best suits the data at a given
moment. In k=cint(3) it is integer; at k=3.3 it morphs to single. Similarly
k="3.3" morphs it to a string. This is one reason variants can be
dangerous -- the infamous "evil type casting". If you use variants you have
to understand what they can do to your data.
--
Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
:
: >> It's not much of a problem. I was just trying to use the immediate
: >> window to test some data type conversions. I was getting odd results
: >> that were different from what happens in running code. I deduced that
: >> all immediate window variables are type Variant, which makes testing
: >> data type conversions difficult.
: >
: >As another posted apparently using the type characters works. You can
also
: >just use a conversion function to do explicitly what VB would do
implicitly:
: >
: >x=CLng(y)
:
: I don't think this equivalent to x#=y.
:
: Compare this:
:
: j%=3 'define an integer variable
: ?j
: 3
: j=3.3
: ?j
: 3 'value was truncated as it should be
: j#=3.3 'compiler error, type mismatch
: j%=5 'OK to reassign as same type
: ?5
: 5
:
: with this:
:
: k=cint(3) 'define a variant
: ?k
: 3
: k=3.3
: ?k
: 3.3 'not truncated, hence not type integer
: k%=3 'compiler error, type mismatch, not integer
:
: Thanks
:
: --
: Running MS VB 6.0 Pro (SP5) on Win2K-SR2
: For email, use Usenet-20031220 at spamex.com
|
|
|
|
 |
Duane

|
Posted: Tue Jul 06 21:50:39 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
>
> > Is there any way to force a variable in the immediate window to be of
> > a particular type (integer, byte, double, date, etc.)?
>
> No
>
> > It looks like all variables defined (implicitly) in the immediate
> > window are type Variant. Is that correct?
>
> Yes; the closest you can come is specifying the type in the assignment:
> x=CDbl(42)
> y=42!
This isn't <quite> correct...you can specify the type by using the
trailing type identifiers %, &, !, # for the basic Integer, Long, Single
and Double. There aren't specifiers for Byte, Date, etc., so those are
limited.
|
|
|
|
 |
NickHK

|
Posted: Wed Jul 07 01:14:40 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
Now the radio again:
http://www.bbc.co.uk/cult/hitchhikers/
NickHK
>
> >
> > > > Other than Benny Hill, that may be one of the best-known British TV
> > > > shows in America. At least for my generation....
> > >
> > > didn't know it was a TV show; it's a great set of books
> >
> > Yes, the TV series actually followed the book quite closely for a
> > change.
> >
> > Now be quiet, or I will read you some of my poetry! <g>
> >
> > Gale.
> >
>
> Ha. If we are going to get picky ... It was first a Radio Show, then a TV
> Show, then the books.
>
> -ralph
>
>
|
|
|
|
 |
Bob

|
Posted: Wed Jul 07 08:00:03 CDT 2004 |
Top |
Visual Basic >> Data types in immediate window
>
>>> It's not much of a problem. I was just trying to use the immediate
>>> window to test some data type conversions. I was getting odd results
>>> that were different from what happens in running code. I deduced
>>> that all immediate window variables are type Variant, which makes
>>> testing data type conversions difficult.
>>
>> As another posted apparently using the type characters works. You
>> can also just use a conversion function to do explicitly what VB
>> would do implicitly:
>>
>> x=CLng(y)
>
> I don't think this equivalent to x#=y.
I was not claiming it was equivalent; only that it'd do the same type
conversion so you can use it to debug the conversions that were giving you
trouble.
--
Reply to the group so all can participate
VB.Net... just say "No"
|
|
|
|
 |
|