VBscript searching value in 2d array -


i have 2d array parced xml. example of xml:

  <string-array name="array1">     <field name="city" type="string">moscow</field>     <field name="id" type="number">10</field> (p.s. id unique within array)     <field name="version" type="number">2</field>     .......   </string-array> 

parcing it:

for i=0 nodek.length-1     array1(0,i)=nodek(i).getattribute("name")     array1(1,i)=nodek(i).text next 

so 2d array looks like:

array1(0,0)="city" array1(1,0)="moscow" array1(0,1)="id" array1(1,1)=10 array1(0,2)="version" array1(1,2)=2 

the task pick value id use (in sysid variable) further. following code not work properly

for i=lbound(array1,1) ubound (array1,1)     j=lbound(array1,2) ubound(array1,2)         if j=0             if  array(i,0)="id"                   sysid=array(i,1)                 msgbox "new id is: " & id, 64             end if         end if     next next 

once value (id=10 in our case) found loop should exit. thank in advance!

just write array table

city    id  version moscow  10  2 

then see need loop on 'cols of row 0' find key , address corresponding 'col of row 1' value.

in code:

option explicit  dim array1(1, 2) array1(0,0)="city" array1(1,0)="moscow" array1(0,1)="id" array1(1,1)=10 array1(0,2)="version" array1(1,2)=2  dim sfnd : sfnd = "id"  dim = 0 ubound(array1, 2)     wscript.echo array1(0, i)     if sfnd = array1(0, i)        wscript.echo array1(0, i), "=>", array1(1, i)        exit     end if next 

output:

cscript 22862344.vbs city id id => 10 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -