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 10,151 of 10,840   
   John F. Eldredge to giveup@hotpop.com   
   Re: How do I use use multiple arrays wit   
   29 Jul 06 17:39:45   
   
   From: john@jfeldredge.com   
      
   On Thu, 18 Aug 2005 16:08:54 GMT, T  wrote:   
      
   >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?   
   >   
   >   
   >   
   >Thanks in advance   
   >John   
      
   You could pass the array as an argument to the function.  For example,   
      
   >Option Explicit   
   >Option Compare Text   
   >   
   >Private arr1 As Variant   
   >Private arr2 As Variant   
   >   
   >Private Sub Command1_Click()   
   >    listarray arr1   
   >End Sub   
   >   
   >Private Sub Command2_Click()   
   >    listarray arr2   
   >End Sub   
   >   
   >Private Sub Form_Load()   
   >    arr1 = Array("alpha", "bravo", "charlie")   
   >    arr2 = Array("delta", "echo", "foxtrot")   
   >End Sub   
   >   
   >Private Sub listarray(ByRef ThisArray As Variant)   
   >    Dim intIndex   
   >   
   >    If IsArray(ThisArray) Then   
   >        For intIndex = LBound(ThisArray) To UBound(ThisArray)   
   >            MsgBox ThisArray(intIndex)   
   >        Next   
   >    Else   
   >        MsgBox "argument passed isn't an array"   
   >    End If   
   >End Sub   
      
   where command1 and command2 are the names of command buttons.   
      
   --   
   John F. Eldredge -- john@jfeldredge.com   
   PGP key available from http://pgp.mit.edu   
   "Reserve your right to think, for even to think wrongly is better   
   than not to think at all." -- Hypatia of Alexandria   
      
   --- 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