|
-
Jul 1st, 2006, 07:59 AM
#1
Thread Starter
Hyperactive Member
[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
-
Jul 1st, 2006, 08:32 AM
#2
Addicted Member
Re: Help on this code?
Is it generating any error messages ?
In this section:
VB Code:
For i = 1 To lCount
Get #nFileNum, , cResources(i)
MsgBox lCount & " " & cResources(i).Name & "-" & cResources(i).Keywords
Next i
You're putting the information into cResources(i), I think it should be something like:
Get #nFileNum, , cResources(i).Name
Get #nFileNum, , cResources(i).Keywords
Edit:
Same goes for : Put #nFileNum, , cResources(i)
I think it should be something like:
Put #nFileNum, , cResources(i).Name
Put #nFileNum, , cResources(i).Keywords
Althougth instead of PUT and Get, I would suggest Print # and Input #.
Last edited by Keith_VB6; Jul 1st, 2006 at 08:35 AM.
Keith_VB6
If you have any further questions, just ask.
If this solves things, then please mark the thread resolved.
[Thread Tools] --> [Mark Thread Resolved]
-
Jul 1st, 2006, 09:26 AM
#3
Thread Starter
Hyperactive Member
Re: Help on this code?
Thanks Keith_VB6, but it´s not working, any suggestions?
-
Jul 1st, 2006, 12:17 PM
#4
Addicted Member
Re: Help on this code?
Are you receiving any error messages. If so, what are they and on what line of code ? Comment out the "On Error GoTo 0" first.
Keith_VB6
If you have any further questions, just ask.
If this solves things, then please mark the thread resolved.
[Thread Tools] --> [Mark Thread Resolved]
-
Jul 1st, 2006, 01:27 PM
#5
Lively Member
Re: Help on this code?
the problem is that lCount is declared as Integer in Show_Click() and as Long in Save_Click().
declare lCount as Long in Show_Click() too and it will work
-
Jul 1st, 2006, 05:15 PM
#6
Addicted Member
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.
Keith_VB6
If you have any further questions, just ask.
If this solves things, then please mark the thread resolved.
[Thread Tools] --> [Mark Thread Resolved]
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
|