home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.visual.basic      MS Visual Basic discussions, NOT dot-net      10,840 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 9,659 of 10,840   
   Steve Gerrard to giveup@hotpop.com   
   Re: How do I use use multiple arrays wit   
   18 Aug 05 18:46:17   
   
   From: mynamehere@comcast.net   
      
   "T"  wrote in message   
   news:e4a9g158g9nugi2emibb7ovp66i0r73g30@4ax.com...   
   > Hi all.  I have a problem I have not been able to find a reference   
   > about.  I am using VB6 and am only a hobbyist programmer.  I have 7   
   > arrays of type MyData.  Type MyData has 23 elements.  Which array that   
   > is operated on depends on 1 of 7 options  Currently if I want to write   
   > to an array I have to do this:   
   >   
   > if opt1 then   
   >  array1(x).data1= 36   
   >  array1(x).data2= 23   
   >  ..   
   >  array1(x).data23= 69   
   > else   
   >  if opt2 then   
   >    array2(x).data1 = 43   
   >    array2(x).data2 =77   
   >    ..   
   >    array2(x).data23 =44   
   >  else   
   >    if opt3 then   
   >      array3(x).data1 = 78   
   >      array3(x).data2 = 63   
   >      ..   
   >      array3(x).data23 =22   
   >    end if   
   >  end if   
   > end if   
   >   
   > I would like to use a shorter routine to write/read these arrays   
   > rather than go through 7 long if statements.  Perhaps something like   
   > below that would pick the array to write to:   
   >   
   > sub write (array to use)   
   >  array(x).data1= 36   
   >  array(x).data2= 23   
   >  ..   
   >  array(x).data23= 69   
   > end sub   
   >   
   >   
   > Is there a way to do this?   
   >   
      
      
   Sure - use an array!   
      
   You could use a two dimensional array:   
   Dim MyArray(1 to 7, 1 to 100) As MyData   
      
   in which case the code looks like   
       array(n, x).data23 = 43   
      
   Or you could declare another type (I like this better):   
   Type MyDataArray   
       Arr(1 to 100) As MyData   
   End Type   
      
   Dim MyArrays(1 to 7) As MyDataArray   
      
   and the code would look like   
       MyArrays(n).Arr(x) = 43   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca