Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #11916 > unrolled thread

Variable type questions

Started byJJ <jj4public@vfemail.net>
First post2018-04-27 02:16 +0700
Last post2018-04-29 19:54 +0200
Articles 8 — 4 participants

Back to article view | Back to microsoft.public.scripting.vbscript


Contents

  Variable type questions JJ <jj4public@vfemail.net> - 2018-04-27 02:16 +0700
    Re: Variable type questions "Mayayana" <mayayana@invalid.nospam> - 2018-04-26 17:17 -0400
      Re: Variable type questions JJ <jj4public@vfemail.net> - 2018-04-28 02:44 +0700
    Re: Variable type questions "R.Wieser" <address@not.available> - 2018-04-27 09:38 +0200
      Re: Variable type questions JJ <jj4public@vfemail.net> - 2018-04-28 02:56 +0700
    Re: Variable type questions "Roger Roesler" <worm.composter@nospam.arcornews.de> - 2018-04-29 11:35 +0200
      Re: Variable type questions JJ <jj4public@vfemail.net> - 2018-04-29 22:51 +0700
        Re: Variable type questions "Roger Roesler" <worm.composter@nospam.arcornews.de> - 2018-04-29 19:54 +0200

#11916 — Variable type questions

FromJJ <jj4public@vfemail.net>
Date2018-04-27 02:16 +0700
SubjectVariable type questions
Message-ID<swdf41oi1p7r$.1s7t32djqg8xd.dlg@40tude.net>
In MSDN's "VarType()" document, it states:

"For example, the value returned for an array of integers is calculated as 2
+ 8192, or 8194."

However, the value is 8204 instead of 8194, when I test it using below code.

  dim a(0)
  a(0) = 1
  wscript.echo vartype(a) 'shows 8204

8204 in hexadecimal is 0x200C, which is a combination of vbArray and
vbVariant. Meaning that it's an array of variants, instead of an array of
integer. So, which one is correct?

To add into the confusion, the contents of the array doesn't really matter.
i.e.

  dim a(0)
  a(0) = true
  wscript.echo vartype(a) 'still shows 8204
  a(0) = "abc"
  wscript.echo vartype(a) 'still shows 8204
  dim b(0)
  a(0) = b
  wscript.echo vartype(a) 'still shows 8204

Also, for research purpose, there are two types that I'm unable to produce:
vbError and vbDataObject. For vbError, I immediately thought of the Error
object. But its type is actually vbObject. So, what class/component produces
such types?

[toc] | [next] | [standalone]


#11917

From"Mayayana" <mayayana@invalid.nospam>
Date2018-04-26 17:17 -0400
Message-ID<pbtfmu$agg$1@dont-email.me>
In reply to#11916
"JJ" <jj4public@vfemail.net> wrote

| 8204 in hexadecimal is 0x200C, which is a combination of vbArray and
| vbVariant. Meaning that it's an array of variants, instead of an array of
| integer. So, which one is correct?
|

   The whole thing seems kind of hokey to me.
An array is a variant and it's an array of variants,
so returning 8204 makes sense to me. But returning
2 for a number or 8 for "apple" is misleading, since
that's only the current subtype and the functional
type is still variant.


[toc] | [prev] | [next] | [standalone]


#11923

FromJJ <jj4public@vfemail.net>
Date2018-04-28 02:44 +0700
Message-ID<rw3crexpc254.139x44gcdw5dj$.dlg@40tude.net>
In reply to#11917
On Thu, 26 Apr 2018 17:17:42 -0400, Mayayana wrote:
> "JJ" <jj4public@vfemail.net> wrote
> 
>| 8204 in hexadecimal is 0x200C, which is a combination of vbArray and
>| vbVariant. Meaning that it's an array of variants, instead of an array of
>| integer. So, which one is correct?
>|
> 
>    The whole thing seems kind of hokey to me.
> An array is a variant and it's an array of variants,
> so returning 8204 makes sense to me. But returning
> 2 for a number or 8 for "apple" is misleading, since
> that's only the current subtype and the functional
> type is still variant.

All VB/VBScript variables are indeed variant type. VarType() returns the
variant subtype for the variable. It doesn't return the actual type of the
variable (which would always be vbVariant). However, the result conflicts
with the documentation when it comes to array.

The TypeName() function result is also the same as VarType() when it comes
to array. It returns "Variant()". With the "()" suffix, denoting an array.

[toc] | [prev] | [next] | [standalone]


#11918

From"R.Wieser" <address@not.available>
Date2018-04-27 09:38 +0200
Message-ID<pbuk16$9oj$1@gioia.aioe.org>
In reply to#11916
JJ,

> 8204 in hexadecimal is 0x200C, which is a combination of vbArray
> and vbVariant. Meaning that it's an array of variants, instead of an
> array of integer. So, which one is correct?

The first one.

Question: If you fill a(0) with 1234 and a(1) with "world", what type would 
the array "a" than need to be and return ?   (for fun, imagine some more 
data types in that array: objects, booleans, floats, dates, etc. :-) )

No, the *array* is of type variant, which each *element* being of type 
variant too.   Each of those variant elements can than ofcourse contain any 
type of data you please (the strong point of using variants - and ofcourse 
its weak point too).

By the way, its posible to actually create a variant array of ints, strings 
or whatever, just not in VBScript* - as it only knows variants.

*It can manage/move them around just fine (accepting them from and providing 
them to a function), it just cannot access them.

> To add into the confusion, the contents of the array doesn't really 
> matter.
> i.e.
>  wscript.echo vartype(a) 'still shows 8204

Have you also tried "vartype( a(0) )" ?  What did you get ?

In other words, this is what it looks like in VBScript:

variant array (1) -> variant element (2) -> contents (3)

while you are (probably) *thinking* of this :

variant array -> contents

You are asking what the array (at #1) is, and what its contents are.   That 
means you are getting a result which is a combination of it (1) and its 
"child" (2).   Nothing more, nothing less.

If you want to know something about the type of the contents (at 3), you 
have to inquire its "parent", the variant element (at 2).

And by the way, a "variant element" (as I named it in the above) is the very 
same thing as a "variant variable" (or "variable" for short).

Hope that helps.

> Also, for research purpose, there are two types that I'm unable to
> produce: vbError and vbDataObject.

Can't help you with that I'm afraid.

Regards,
Rudy Wieser

[toc] | [prev] | [next] | [standalone]


#11924

FromJJ <jj4public@vfemail.net>
Date2018-04-28 02:56 +0700
Message-ID<zhktzpv2y8yy$.us1zkb85j74s.dlg@40tude.net>
In reply to#11918
On Fri, 27 Apr 2018 09:38:05 +0200, R.Wieser wrote:
> JJ,
> 
>> 8204 in hexadecimal is 0x200C, which is a combination of vbArray
>> and vbVariant. Meaning that it's an array of variants, instead of an
>> array of integer. So, which one is correct?
> 
> The first one.

My hunch tells me that too. Considering that it's pretty common for MSDN to
have incorrect information.

> Question: If you fill a(0) with 1234 and a(1) with "world", what type would 
> the array "a" than need to be and return ?   (for fun, imagine some more 
> data types in that array: objects, booleans, floats, dates, etc. :-) )
> 
> No, the *array* is of type variant, which each *element* being of type 
> variant too.   Each of those variant elements can than ofcourse contain any 
> type of data you please (the strong point of using variants - and ofcourse 
> its weak point too).
> 
> By the way, its posible to actually create a variant array of ints, strings 
> or whatever, just not in VBScript* - as it only knows variants.
> 
> *It can manage/move them around just fine (accepting them from and providing 
> them to a function), it just cannot access them.

Couldn't agree more.

>> Also, for research purpose, there are two types that I'm unable to
>> produce: vbError and vbDataObject.
> 
> Can't help you with that I'm afraid.

Aw, bummer.

[toc] | [prev] | [next] | [standalone]


#11926

From"Roger Roesler" <worm.composter@nospam.arcornews.de>
Date2018-04-29 11:35 +0200
Message-ID<fkli1dF1gifU1@mid.individual.net>
In reply to#11916
JJ <jj4public@vfemail.net> typed:

> In MSDN's "VarType()" document, it states:
>
> "For example, the value returned for an array of integers is
> calculated as 2 + 8192, or 8194."
>
> However, the value is 8204 instead of 8194, when I test it using
> below code.
>
>  dim a(0)
>  a(0) = 1
>  wscript.echo vartype(a) 'shows 8204
>
> 8204 in hexadecimal is 0x200C, which is a combination of vbArray and
> vbVariant. Meaning that it's an array of variants, instead of an
> array of integer. So, which one is correct?
>
> To add into the confusion, the contents of the array doesn't really
> matter. i.e.
>
>  dim a(0)
>  a(0) = true
>  wscript.echo vartype(a) 'still shows 8204
>  a(0) = "abc"
>  wscript.echo vartype(a) 'still shows 8204
>  dim b(0)
>  a(0) = b
>  wscript.echo vartype(a) 'still shows 8204
>
> Also, for research purpose, there are two types that I'm unable to
> produce: vbError and vbDataObject. For vbError, I immediately thought
> of the Error object. But its type is actually vbObject. So, what
> class/component produces such types?

This script performs logical conjunctions on two expressions:

'######################################################################
  Dim a(0), out

  a(0) = 1
  WScript.Echo "VarType(a)               = " & VarType(a)
  WScript.Echo "TypeName(a(0))           = " & TypeName(a(0))
  WScript.Echo "VarType(a) And vbArray   = " & _
                                        CInt(VarType(a) And vbArray)
  WScript.Echo "VarType(a) Xor vbVariant = " & _
                                        CInt(VarType(a) Xor vbVariant)
  Set out = WScript.StdOut
  out.WriteLine "VarType(out) And vbObject: " & _
                                        CBool(VarType(out) And vbObject)
  out.WriteLine "VarType(out)             : " & VarType(out)

  On Error Resume Next  ' raise an error
  out.WriteLine "VarType(a) And vbArray   = " & VarType(a) And vbArray
  If Err Then
    Set out = WScript.StdErr
    out.WriteLine vbCRLF & "VarType(Err)             : " & VarType(Err)
    out.WriteLine "TypeName(Err)            : " & TypeName(Err)
    out.WriteLine "VarType(Err) And vbError : " & _
                                        CBool(VarType(Err) And vbError)
    out.WriteLine "VarType(Err) And vbObject: " & _
                                        CBool(VarType(Err) And vbObject)
    out.WriteLine "Error " & Err.Number & ": " & Err.Description
    Err.Clear
  End If
'######################################################################

The result is somewhat unexpected. HTH

-- 
ЯR

[toc] | [prev] | [next] | [standalone]


#11927

FromJJ <jj4public@vfemail.net>
Date2018-04-29 22:51 +0700
Message-ID<1u87muxsbkmpk.1znphd68dbaj$.dlg@40tude.net>
In reply to#11926
On Sun, 29 Apr 2018 11:35:26 +0200, Roger Roesler wrote:
> 
> This script performs logical conjunctions on two expressions:
> 
> '######################################################################
>   Dim a(0), out
> 
>   a(0) = 1
>   WScript.Echo "VarType(a)               = " & VarType(a)
>   WScript.Echo "TypeName(a(0))           = " & TypeName(a(0))
>   WScript.Echo "VarType(a) And vbArray   = " & _
>                                         CInt(VarType(a) And vbArray)
>   WScript.Echo "VarType(a) Xor vbVariant = " & _
>                                         CInt(VarType(a) Xor vbVariant)
>   Set out = WScript.StdOut
>   out.WriteLine "VarType(out) And vbObject: " & _
>                                         CBool(VarType(out) And vbObject)
>   out.WriteLine "VarType(out)             : " & VarType(out)
> 
>   On Error Resume Next  ' raise an error
>   out.WriteLine "VarType(a) And vbArray   = " & VarType(a) And vbArray
>   If Err Then
>     Set out = WScript.StdErr
>     out.WriteLine vbCRLF & "VarType(Err)             : " & VarType(Err)
>     out.WriteLine "TypeName(Err)            : " & TypeName(Err)
>     out.WriteLine "VarType(Err) And vbError : " & _
>                                         CBool(VarType(Err) And vbError)
>     out.WriteLine "VarType(Err) And vbObject: " & _
>                                         CBool(VarType(Err) And vbObject)
>     out.WriteLine "Error " & Err.Number & ": " & Err.Description
>     Err.Clear
>   End If
> '######################################################################
> 
> The result is somewhat unexpected. HTH

You shouldn't apply bitwise operator on variable types because variable type
values mostly are not bit masks (except vbArray).

In that code, vbError is 10, and vbObject is 9. AND-ing them would result to
8, where if it's converted to boolean, it will be true. Because numbers
which isn't zero, will always evaluate to true if it's converted to boolean.

So, instead of:

  CBool(VarType(Err) And vbError)

It should be:

  ((VarType(Err) And &HFFF) = vbError)

[toc] | [prev] | [next] | [standalone]


#11928

From"Roger Roesler" <worm.composter@nospam.arcornews.de>
Date2018-04-29 19:54 +0200
Message-ID<fkmfa6F7spdU1@mid.individual.net>
In reply to#11927
JJ <jj4public@vfemail.net> typed:

>> The result is somewhat unexpected. HTH
>
> You shouldn't apply bitwise operator on variable types because
> variable type values mostly are not bit masks (except vbArray).
>
> In that code, vbError is 10, and vbObject is 9. AND-ing them would
> result to 8, where if it's converted to boolean, it will be true.
> Because numbers which isn't zero, will always evaluate to true if
> it's converted to boolean.
>
> So, instead of:
>
>  CBool(VarType(Err) And vbError)
>
> It should be:
>
>  ((VarType(Err) And &HFFF) = vbError)

Ok, thanks!

-- 
ЯR

[toc] | [prev] | [standalone]


Back to top | Article view | microsoft.public.scripting.vbscript


csiph-web