[RESOLVED] Help on this code?
Can someone explain me why i'm not getting the value of cResource(1).name value from the bin file in the show click event?, thanks a lot
here is the code i'm using.
VB Code:
Private Type Resources
Name As String
Keywords As String
End Type
Private cResources(1) As Resources
Private Sub Save_Click()
cResources(1).Name = Text1.Text
cResources(1).Keywords = Text2.Text
Dim nFileNum As Integer
Dim nLen As Integer, i As Long, lCount As Long
On Error Resume Next
'delete any existing file
Kill App.Path & "example.bin"
On Error GoTo 0
nFileNum = FreeFile
Open App.Path & "example.bin" For Binary Access _
Write Lock Read Write As #nFileNum
lCount = UBound(cResources)
Put #nFileNum, , lCount
'save the array
For i = 1 To lCount
Put #nFileNum, , cResources(i)
MsgBox lCount & " " & cResources(i).Name & "-" & cResources(i).Keywords
Next i
Close #nFileNum
End Sub
Private Sub Show_Click()
Dim lCount As Integer
Dim i As Integer
Dim nFileNum As Integer ', lCount As Long
Dim sFileAppIdent As String * 5, nFileAppVersion As Integer
Dim nLen As Integer ', i As Long
nFileNum = FreeFile
Open App.Path & "example.bin" For Binary Access _
Read Lock Read Write As #nFileNum
Get #nFileNum, , lCount
If lCount > 0 Then
'resize array
' ReDim cResources(1 To lCount)
'read items into array
For i = 1 To lCount
Get #nFileNum, , cResources(i)
MsgBox lCount & " " & cResources(i).Name & "-" & cResources(i).Keywords
Next i
End If
Close #nFileNum
End Sub
Re: [RESOLVED] Help on this code?
Agilaz was correct. Your original code just need the variable to be the same type. I learned something new, I've never tried saving a UDT before, so I learned something new.