Results 1 to 5 of 5

Thread: My own file format, Need help[soLVEd]

Threaded View

  1. #1

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720

    My own file format, Need help[soLVEd]

    I am trying to make a file format so I can better my self at binary file access. The extension is *.tits and it holds a name, age and comments. This is the code:

    I want to check if the file exists, the function I made isnt working, "FilesHere", Can someone tell me whats wrong with it.

    Problems:

    When I save the file, it makes example.tits but if I open it in notepad I can see the comments and name, I know its because they are string but is there anyway to hide that.

    When loading, I get the name back but age is 0 and I get like half of the comments.


    VB Code:
    1. Option Explicit
    2. Dim VersionCheck As Integer
    3. Dim nLen As Integer, nLen2 As Integer
    4. Private Type TITS
    5.     Name As String
    6.     Age As Byte
    7.     Comments As String
    8. End Type
    9. Dim TheAge As Byte
    10.  
    11. Private Sub Command1_Click()
    12. CommonDialog1.Filter = "T i T S (*.tits)|*.tits"
    13. CommonDialog1.ShowOpen
    14. End Sub
    15.  
    16. Private Sub Command2_Click()
    17. Dim ageX As Byte
    18. Dim CommentsX As String, NameX As String
    19.     If FilesHere(Text1.Text) Then
    20.         Open Text1.Text For Binary Access Read Lock Write As #1
    21.             Get #1, , VersionCheck
    22.             If VersionCheck <> 6 Then MsgBox ("Not made in TFV 6")
    23.             Get #1, , nLen
    24.             NameX = Space(nLen)
    25.             Get #1, , NameX
    26.             Get #1, , nLen2
    27.              CommentsX = Space(nLen2)
    28.             Get #1, , nLen2
    29.             Get #1, , CommentsX
    30.             Get #1, , ageX
    31.         Close #1
    32.         Text2.Text = CommentsX
    33.         Text4.Text = ageX
    34.         Text3.Text = NameX
    35.     Else
    36.         MsgBox ("File not found, dummy!"), , "Where"
    37.     End If
    38.    
    39. End Sub
    40.  
    41. Private Sub Command3_Click()
    42. TheAge = Val(Text4.Text)
    43.  
    44. Dim MyFile() As TITS
    45.     'If FilesHere(Text1.Text) Then
    46.     '    If UCase(Right(Text1.Text, 4)) = "TITS" Then Kill Text1.Text
    47.    ' End If
    48.         Open Text1.Text For Binary Access Write Lock Read Write As #1
    49.             Put #1, , VersionCheck
    50.             nLen = Len(Text3.Text)
    51.             Put #1, , nLen
    52.             Put #1, , Text3.Text
    53.             nLen2 = Len(Text2.Text)
    54.             Put #1, , nLen2
    55.             Put #1, , Text2.Text
    56.             Put #1, , TheAge
    57.         Close #1
    58. End Sub
    59.  
    60. Private Sub Form_Load()
    61. VersionCheck = 6
    62.     Text1.Text = App.Path & "\Example.tits"
    63. End Sub
    64.  
    65. Private Function FilesHere(TheFileName As String) As Boolean
    66.     If FileLen(TheFileName) > 0 Then
    67.         FilesHere = True: Exit Function
    68.     Else
    69.         FilesHere = False: Exit Function
    70.     End If
    71. End Function
    Last edited by scr0p; Nov 15th, 2002 at 03:28 PM.
    asdf

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