Results 1 to 7 of 7

Thread: Random Access Files without UDT's

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Posts
    114

    Random Access Files without UDT's

    I am using Random File Access and I want each record to be defined like this

    Key as Integer
    Name as string * 50
    DOB as date
    SSN as string * 11


    Is there a way I can define each record without using a User Defined Type? Is there a way I could use a collection instead or some other method? As far as I know the only way to do this is by using a UDT.

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    San Jose, Ca. - USA
    Posts
    302

    I don't know much about random file access but...

    you could create a class module and add that to a collection.

    Keep in mind that Dictionaries are much faster than collections and with a dictionary you check if a Key exists or not.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Posts
    114

    Dictionaries

    What is a "Dictionaries"? Also how would I add the fields to a collection?

  4. #4
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    U could Use PropertyBags as well. Just wondering, why not UDTs?

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  5. #5
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    San Jose, Ca. - USA
    Posts
    302
    a Dictionary is similar to a collection go here:

    http://www.vbwm.com/art_1999/whatsnew/Dictionary.asp

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Posts
    114
    I would love to use UDT's but I really don't know how I can pass a UDT from a DLL to a exe program. My exe program is calling the dll. So is there a way I can get the structure of the UDT? Example of my UDT is:

    Private type tmyType
    Name as string * 50
    date as double
    Number as string * 20
    iNumberLines as integer
    end Type
    public myType as tmyType

    Now how would the exe know what field are in the UDT that is defined in the DLL?

  7. #7
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    A UDT must be declared as Public in a Class module. UDT Strings cannot be fixed length.

    VB Code:
    1. [b][i]DLL Class1[/i][/b]
    2.  
    3. Public Type tmyType
    4.     Name As String
    5.     date As Double
    6.     Number As String
    7.     iNumberLines As Integer
    8. End Type
    9.  
    10. Public Property Get SampleData() As tmyType
    11.     Dim udtTemp As tmyType
    12.  
    13.     udtTemp.Name = "Hello World"
    14.     udtTemp.date = Now
    15.     udtTemp.Number = "1000"
    16.     udtTemp.iNumberLines = 734
    17.  
    18.     SampleData = udtTemp
    19.  
    20. End Property
    21.  
    22. [b][i]Client exe project[/i][/b]
    23.  
    24. Dim objTest As Project1.Class1
    25. Dim udtTest As Project1.tmyType
    26.        
    27. Set objTest = New Project1.Class1
    28.        
    29. udtTest = objTest.SampleData
    30.  
    31. Debug.Print udtTest.Name, udtTest.Date, udtTest.iNumberLines, udtTest.Number
    32.  
    33. Set objTest = Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width