Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I set structures in VB6? 1

Status
Not open for further replies.

tg2003

IS-IT--Management
Feb 6, 2003
270
0
0
IL
Hi,

I'm looking for a way to define structures in VB, but found nothing yet.

I do not mean to Object Oriented - I just want to define a C-like struct with some properties inside, so I can make an array of this struct. I don't need methods nor events.

Is it possible? As I said, I found information only about OO classes.

Thanks in advance!
 
You need to investigate VB's (User Defined) Types - UDTs
 
Thanks!

BTW: Can I define the this UDT as dynamic array? I mean to add items to the array on run-time
 
Yep. Here. Have an example illustrating several things:
Code:
[blue]Option Explicit

Private Type example
    lItemNumber As Long
    strDescription As String
End Type

Private Sub Command1_Click()
    Dim demo() As example
    Dim lp As Long
    
    ReDim demo(4) As example
    
    For lp = 0 To 3
        ReDim Preserve demo(lp) As example
        With demo(lp)
            .lItemNumber = lp
            .strDescription = "I am structure " & lp
        End With
    Next
    
    For lp = 0 To 3
        Debug.Print "Item: " & demo(lp).lItemNumber, "Description: " & demo(lp).strDescription
    Next
End Sub[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top