From: tom88 on 21 Mar 2010 21:59 Air code but hopefully enough to ask my question. Can I do this and if so how do I define x? Thanks, Dim a(10) as myUDT1 Dim b(20) as myUDT2 Dim c(30) as myUDT3 �doing something, now process common elements of UDTs CommonUDTProcessing a CommonUDTProcessing b CommonUDTProcessing c Public Sub CommonUDTProcessing(x as ?) For i=1 to ubound(x) x(i).somefield=something Next End Sub
From: Nobody on 21 Mar 2010 22:19 "tom88" <nospam(a)nospam.net> wrote in message news:%23PWa$MWyKHA.5040(a)TK2MSFTNGP02.phx.gbl... > Air code but hopefully enough to ask my question. > > Can I do this and if so how do I define x? > > > Thanks, > > > Dim a(10) as myUDT1 > Dim b(20) as myUDT2 > Dim c(30) as myUDT3 > > �doing something, now process common elements of UDTs > CommonUDTProcessing a > CommonUDTProcessing b > CommonUDTProcessing c > > > Public Sub CommonUDTProcessing(x as ?) > > For i=1 to ubound(x) > x(i).somefield=something > Next > > End Sub No you can't, but you could make one UDT inside another, and define x As that smaller UDT. Example: Type myUDTCommon ' Common to all UDT's somefield1 As String somefield2 As Long End Type Type myUDT1 Common As myUDTCommon somefield10 As String End Type Public Sub CommonUDTProcessing(x As myUDTCommon) x.somefield1 = "Test" x.somefield2 = 123 End Sub Public Sub Test() For i=1 to ubound(a) CommonUDTProcessing a(i).Common Next End Sub You can even have dynamic arrays of UDT's inside other dynamic arrays of UDT's, and ReDim these sub arrays differently. Example: ReDim Preserve x(5).y(2).z(1 To 10) As String This would only ReDim "z" of the 2nd "y" of the 5th "x" to 10 elements.
From: MikeD on 22 Mar 2010 21:46 "Nobody" <nobody(a)nobody.com> wrote in message news:enFifYWyKHA.2552(a)TK2MSFTNGP04.phx.gbl... > "tom88" <nospam(a)nospam.net> wrote in message > news:%23PWa$MWyKHA.5040(a)TK2MSFTNGP02.phx.gbl... >> Air code but hopefully enough to ask my question. >> >> Can I do this and if so how do I define x? >> >> >> Thanks, >> >> >> Dim a(10) as myUDT1 >> Dim b(20) as myUDT2 >> Dim c(30) as myUDT3 >> >> 'doing something, now process common elements of UDTs >> CommonUDTProcessing a >> CommonUDTProcessing b >> CommonUDTProcessing c >> >> >> Public Sub CommonUDTProcessing(x as ?) >> >> For i=1 to ubound(x) >> x(i).somefield=something >> Next >> >> End Sub > > No you can't, but you could make one UDT inside another, and define x As > that smaller UDT. Example: Sure about that? Can't the parameter be Variant to allow any UDT to be passed to it? Not something I'd really recommend for various reasons, but I think you can do it (never tried personally). -- Mike
|
Pages: 1 Prev: LostFocus not firing Next: How to Detect Locale Change in VB6 / VBA? |