|
-
Nov 4th, 2001, 08:11 AM
#1
Thread Starter
Lively Member
Problem with retieving records
Can anyone point me in the right way as to why this code doesn't work?
VB Code:
Private Type record
name As String * 15
gender As String * 1
status As String
children As Integer
End Type
Dim field As record
Dim x As Integer
Dim fileno As Integer
Dim recordlen As Long
Dim recnum As Integer
Dim y As Integer
Dim z As Integer
Private Sub Form_Load()
Dim name() As String
Dim gender() As String
Dim status() As String
Dim children() As Integer
Dim value As String
Dim fileno As Integer
fileno = FreeFile
value = 2
x = 1
y = 0
dlg2.FileName = "c:\My Documents\storage.txt"
file_2_open = dlg2.FileName
recordlen = Len(field)
recnum = FileLen(file_2_open) / recordlen
Open file_2_open For Random As fileno Len = recordlen
For z = x To recnum
Get fileno, x, field.name & field.gender & field.status & field.children
If field.gender = "M" Then
If field.children > value Then
lblName1(y).Caption = Trim(field.name)
lblGender1(y).Caption = Trim(field.gender)
lblStatus1(y).Caption = Trim(field.status)
lblChildren1(y).Caption = Trim(field.children)
y = y + 1
Else:
End If
Else:
End If
x = x + 1
If y = 2 Then
Exit For
End If
Next z
Close fileno
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
-
Nov 4th, 2001, 08:15 AM
#2
You only have to pass the UDT and not it's member.Best regards
-
Nov 4th, 2001, 08:31 AM
#3
Thread Starter
Lively Member
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
-
Nov 4th, 2001, 08:36 AM
#4
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:
Private Type record
name As String * 15
gender As String * 1
status As String [b]* 5[/b] 'or whatever length you need
children As Integer
End Type
Best regards
-
Nov 4th, 2001, 08:40 AM
#5
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|