Results 1 to 5 of 5

Thread: Problem with retieving records

  1. #1

    Thread Starter
    Lively Member Maldini's Avatar
    Join Date
    Sep 2001
    Posts
    73

    Problem with retieving records

    Can anyone point me in the right way as to why this code doesn't work?

    VB Code:
    1. Private Type record
    2.     name As String * 15
    3.     gender As String * 1
    4.     status As String
    5.     children As Integer
    6. End Type
    7. Dim field As record
    8. Dim x As Integer
    9. Dim fileno As Integer
    10. Dim recordlen As Long
    11. Dim recnum As Integer
    12. Dim y As Integer
    13. Dim z As Integer
    14.  
    15. Private Sub Form_Load()
    16. Dim name() As String
    17. Dim gender() As String
    18. Dim status() As String
    19. Dim children() As Integer
    20. Dim value As String
    21.  
    22. Dim fileno As Integer
    23. fileno = FreeFile
    24. value = 2
    25. x = 1
    26. y = 0
    27.  
    28. dlg2.FileName = "c:\My Documents\storage.txt"
    29. file_2_open = dlg2.FileName
    30. recordlen = Len(field)
    31. recnum = FileLen(file_2_open) / recordlen
    32. Open file_2_open For Random As fileno Len = recordlen
    33.     For z = x To recnum
    34.         Get fileno, x, field.name & field.gender & field.status & field.children
    35.         If field.gender = "M" Then
    36.             If field.children > value Then
    37.                 lblName1(y).Caption = Trim(field.name)
    38.                 lblGender1(y).Caption = Trim(field.gender)
    39.                 lblStatus1(y).Caption = Trim(field.status)
    40.                 lblChildren1(y).Caption = Trim(field.children)
    41.                 y = y + 1
    42.             Else:
    43.             End If
    44.         Else:
    45.         End If
    46.     x = x + 1
    47.     If y = 2 Then
    48.     Exit For
    49.     End If
    50.     Next z
    51. Close fileno
    52. End Sub

    basically, I hv these records in storage.txt... each record consisting of 4 fields.....

    now i can't retrieve them...

    i get this compile error "variable required - can't assign to expression" and when choosiung to debug in VB, it points to the & in:
    Get fileno, x, field.name & field.gender & field.status & field.children

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    You only have to pass the UDT and not it's member.
    VB Code:
    1. Get fileno, x, field
    Best regards

  3. #3

    Thread Starter
    Lively Member Maldini's Avatar
    Join Date
    Sep 2001
    Posts
    73
    Thx for the quick reply.... its amazing how fast u guys respond

    Well, that didn't really fix everything... now I get runtime error 59 "bad record length".... and when choosing to debug, it points towards the line with the get statement:

    Get fileno, x, field

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    All the members of your UDT must be fixed length. You have to change the status member to be a fixed length string.
    VB Code:
    1. Private Type record
    2.     name As String * 15
    3.     gender As String * 1
    4.     status As String [b]* 5[/b] 'or whatever length you need
    5.     children As Integer
    6. End Type
    Best regards

  5. #5

    Thread Starter
    Lively Member Maldini's Avatar
    Join Date
    Sep 2001
    Posts
    73
    thx man, its error free now

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