Re: How to initialize a variable as a array structure / structure (type) array (see example)
- From: "Bob Butler" <noway@xxxxxxxxxxx>
- Date: Wed, 10 Dec 2008 14:48:32 -0800
"Sarah M. Weinberger" <mweinberger@xxxxxxxxxxx> wrote in message news:%234HGobxWJHA.5064@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
Yes, I know of that way, but is there no compact nice and elegant way, such as what I described in the C example that would do that? I know that in VB.Net there is a way.
VB.Net:
Dim MyVariable = new MYTYPE(,,) = {{"a", 1, 1}, {"b", 2, 2}, {"c", 3, 3}}
I tried the VB.Net approach in VB6, but I got a complaint on the "new", plus I already know that VB6 does not like braces, so it seems that there is no nice compact and elegant way to populate UDT (User Defined Types) in VB6. VB6 implements UDTs (structures, really) to a basic level, but not all the way. I did a search on Google and came up empty.
Am I right that there is no nice clean elegant way as C and VB.Net has?
No; the closest might be something like this:
Private Type MYTYPE
strName As String
iType As Integer
End Type
Sub Main()
Dim MyVariable() As MYTYPE
LoadMyTypeArray MyVariable, Array("a", 1, "b", 2, "c", 3)
MsgBox MyVariable(2).strName
End Sub
Public Sub LoadMyTypeArray(ByRef TheArray() As MYTYPE, ByVal TheData As Variant)
Dim x As Long
Dim k As Long
ReDim TheArray(1 To UBound(TheData) / 2)
For x = 1 To UBound(TheArray)
TheArray(x).strName = TheData(x * 2 - 2)
TheArray(x).iType = TheData(x * 2 - 1)
Next
End Sub
.
- References:
- VB6: How to initialize a variable as a array structure / structure (type) array (see example)
- From: Sarah M. Weinberger
- Re: How to initialize a variable as a array structure / structure (type) array (see example)
- From: Henning
- Re: How to initialize a variable as a array structure / structure (type) array (see example)
- From: Sarah M. Weinberger
- VB6: How to initialize a variable as a array structure / structure (type) array (see example)
- Prev by Date: Re: How to initialize a variable as a array structure / structure (type) array (see example)
- Next by Date: Re: How to initialize a variable as a array structure / structure (type) array (see example)
- Previous by thread: Re: How to initialize a variable as a array structure / structure (type) array (see example)
- Next by thread: Re: How to initialize a variable as a array structure / structure (type) array (see example)
- Index(es):
Relevant Pages
|