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


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

Re: Return a key, value pair from a "for each" loop.

From Ulrich Möller <knobbi38@arcor.de>
Newsgroups microsoft.public.scripting.vbscript
Subject Re: Return a key, value pair from a "for each" loop.
Date 2016-01-27 15:08 +0100
Organization A noiseless patient Spider
Message-ID <n8aiq5$c06$1@dont-email.me> (permalink)
References <56a75878$0$23745$e4fe514c@news.xs4all.nl> <n892t7$1mh$1@dont-email.me> <56a89de3$1$23772$e4fe514c@news.xs4all.nl>

Show all headers | View raw


Am 27.01.2016 um 11:40 schrieb R.Wieser:
> Ulrich,
>
>> I think there is no equivalent in vbscript,
> Others have told me as much too, so I guess I have to believe it. :-)
>
>> but perhaps this can be an alternative for you:
> Thank you, but I allready did all of that.   I just went on to see if there
> where other possibilities.   On of them being the mentioned "for each" with
> not one, but two (or more?) returned results.
>
> Alas, its not available, so I have to let go of the ideas I had for if it
> would be ... :-\
>
> Regards,
> Rudy Wieser
>
>
> -- Origional message:
> Ulrich Möller <knobbi38@arcor.de> schreef in berichtnieuws
> n892t7$1mh$1@dont-email.me...
>> Am 26.01.2016 um 12:31 schrieb R.Wieser:
>>> Hello all,
>>>
>>> Is there, and what is the format of, a "for each" loop which returns TWO
>>> results (key and its associated value) at the same time.   In PHP I
> would
>>> use " foreach ($aList as $sKey => $sValue)".  Is there something
> equivalent
>>> in/under VBScript ?
>>>
>>> Remark: I'm not looking for the dictionary object.   I know that one.
> It
>>> does not have it either. :-)
>>>
>>> (Full disclosure: I'm implementing a IEnumVariant object)
>>>
>>> Regards,
>>> Rudy Wieser
>>>
>>>
>> I think there is no equivalent in vbscript, but perhaps this can be an
>> alternative for you:
>>
>> ' VB Script Document
>> dim avnt(1) ' One dimensional variant array with 2 elements
>> dim v
>>
>> ' Initialize the array
>> avnt(0) = Array("Key1", "Value1")
>> avnt(1) = Array("Key2", "Value2")
>>
>> ' Access the array in a foreach loop
>> For Each v In avnt
>>     wscript.echo v(0), v(1)            '  => outputs key(n) value(n) pairs
>> Next
>>
>> ' Direkt access the array by index values
>> wscript.echo avnt(0)(0)              ' outputs "Key1"
>> wscript.echo avnt(0)(1)              ' outputs "Value1"
>> wscript.echo avnt(1)(0)              ' outputs "Key2"
>> wscript.echo avnt(1)(1)              ' outputs "Value2"
>>
>> Ulrich
>
>
Hi Rudy,

perhaps you missed something. My suggestion uses a mixed Array (array of 
array) in contrast to a 'normal' Array. So you will be able to simulate 
such approach you want. Simply put  as many arrays with key/value pairs 
you want into another surrounding variant array.

see also https://en.wikibooks.org/wiki/Visual_Basic/Arrays on how 
vb/vbscript deals with arrays.

Ulrich

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


Thread

Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-26 12:31 +0100
  Re: Return a key, value pair from a "for each" loop. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-01-26 12:54 +0100
    Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-26 14:18 +0100
      Re: Return a key, value pair from a "for each" loop. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-01-26 14:42 +0100
        Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-26 15:27 +0100
          Re: Return a key, value pair from a "for each" loop. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-01-26 17:08 +0100
            Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-26 18:44 +0100
  Re: Return a key, value pair from a "for each" loop. "Mayayana" <mayayana@invalid.nospam> - 2016-01-26 08:26 -0500
    Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-26 16:41 +0100
  Re: Return a key, value pair from a "for each" loop. JJ <jj4public@vfemail.net> - 2016-01-27 01:01 +0700
    Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-26 20:41 +0100
      Re: Return a key, value pair from a "for each" loop. JJ <jj4public@vfemail.net> - 2016-01-27 16:56 +0700
        Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-27 13:16 +0100
          Re: Return a key, value pair from a "for each" loop. JJ <jj4public@vfemail.net> - 2016-01-28 04:16 +0700
            Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-28 00:17 +0100
            Re: Return a key, value pair from a "for each" loop. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-01-28 00:22 +0100
              Re: Return a key, value pair from a "for each" loop. JJ <jj4public@vfemail.net> - 2016-01-28 16:03 +0700
                Re: Return a key, value pair from a "for each" loop. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-01-28 11:59 +0100
  Re: Return a key, value pair from a "for each" loop. GS <gs@v.invalid> - 2016-01-26 18:10 -0500
    Re: Return a key, value pair from a "for each" loop. GS <gs@v.invalid> - 2016-01-26 18:12 -0500
    Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-27 11:33 +0100
      Re: Return a key, value pair from a "for each" loop. GS <gs@v.invalid> - 2016-01-27 12:27 -0500
        Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-27 19:42 +0100
          Re: Return a key, value pair from a "for each" loop. GS <gs@v.invalid> - 2016-01-27 14:36 -0500
            Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-27 23:34 +0100
              Re: Return a key, value pair from a "for each" loop. GS <gs@v.invalid> - 2016-01-27 18:13 -0500
                Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-28 09:49 +0100
  Re: Return a key, value pair from a "for each" loop. Ulrich Möller <knobbi38@arcor.de> - 2016-01-27 01:30 +0100
    Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-27 11:40 +0100
      Re: Return a key, value pair from a "for each" loop. Ulrich Möller <knobbi38@arcor.de> - 2016-01-27 15:08 +0100
        Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-27 15:51 +0100
  Re: Return a key, value pair from a "for each" loop. ttanaka@cybernet.co.jp - 2016-01-26 17:13 -0800
    Re: Return a key, value pair from a "for each" loop. "Mayayana" <mayayana@invalid.nospam> - 2016-01-26 21:28 -0500
      Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-27 12:41 +0100
        Re: Return a key, value pair from a "for each" loop. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-01-27 12:44 +0100
          Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-27 13:21 +0100
    Re: Return a key, value pair from a "for each" loop. "R.Wieser" <address@not.available> - 2016-01-27 11:43 +0100

csiph-web