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


Groups > microsoft.public.scripting.vbscript > #11926

Re: Variable type questions

From "Roger Roesler" <worm.composter@nospam.arcornews.de>
Newsgroups microsoft.public.scripting.vbscript
Subject Re: Variable type questions
Date 2018-04-29 11:35 +0200
Organization No Such Agency
Message-ID <fkli1dF1gifU1@mid.individual.net> (permalink)
References <swdf41oi1p7r$.1s7t32djqg8xd.dlg@40tude.net>

Show all headers | View raw


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

Back to microsoft.public.scripting.vbscript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web