Results 1 to 6 of 6

Thread: [RESOLVED] Help on this code?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Resolved [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:
    1. Private Type Resources
    2.     Name As String
    3.     Keywords As String
    4. End Type
    5. Private cResources(1) As Resources
    6.  
    7.  
    8. Private Sub Save_Click()
    9.  
    10. cResources(1).Name = Text1.Text
    11. cResources(1).Keywords = Text2.Text
    12.  
    13. Dim nFileNum As Integer
    14. Dim nLen As Integer, i As Long, lCount As Long
    15. On Error Resume Next
    16. 'delete any existing file
    17. Kill App.Path & "example.bin"
    18. On Error GoTo 0
    19. nFileNum = FreeFile
    20. Open App.Path & "example.bin" For Binary Access _
    21.    Write Lock Read Write As #nFileNum
    22. lCount = UBound(cResources)
    23. Put #nFileNum, , lCount
    24. 'save the array
    25. For i = 1 To lCount
    26.     Put #nFileNum, , cResources(i)
    27.     MsgBox lCount & " " & cResources(i).Name & "-" & cResources(i).Keywords
    28. Next i
    29. Close #nFileNum
    30.  
    31. End Sub
    32.  
    33.  
    34.  
    35. Private Sub Show_Click()
    36.  
    37. Dim lCount As Integer
    38. Dim i As Integer
    39.    
    40. Dim nFileNum As Integer ', lCount As Long
    41. Dim sFileAppIdent As String * 5, nFileAppVersion As Integer
    42. Dim nLen As Integer ', i As Long
    43. nFileNum = FreeFile
    44. Open App.Path & "example.bin" For Binary Access _
    45.    Read Lock Read Write As #nFileNum
    46.  
    47.     Get #nFileNum, , lCount
    48.     If lCount > 0 Then
    49.         'resize array
    50.        ' ReDim cResources(1 To lCount)
    51.         'read items into array
    52.         For i = 1 To lCount
    53.             Get #nFileNum, , cResources(i)
    54.              MsgBox lCount & " " & cResources(i).Name & "-" & cResources(i).Keywords
    55.         Next i
    56.     End If
    57.  
    58. Close #nFileNum
    59. End Sub

  2. #2
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: Help on this code?

    Is it generating any error messages ?

    In this section:
    VB Code:
    1. For i = 1 To lCount
    2.     Get #nFileNum, , cResources(i)
    3.     MsgBox lCount & " " & cResources(i).Name & "-" & cResources(i).Keywords
    4. 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]

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Help on this code?

    Thanks Keith_VB6, but it´s not working, any suggestions?

  4. #4
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    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]

  5. #5
    Lively Member Agilaz's Avatar
    Join Date
    Jun 2006
    Posts
    98

    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

  6. #6
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    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
  •  



Click Here to Expand Forum to Full Width