|
-
Nov 14th, 2002, 07:21 PM
#1
Thread Starter
Fanatic Member
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:
Option Explicit
Dim VersionCheck As Integer
Dim nLen As Integer, nLen2 As Integer
Private Type TITS
Name As String
Age As Byte
Comments As String
End Type
Dim TheAge As Byte
Private Sub Command1_Click()
CommonDialog1.Filter = "T i T S (*.tits)|*.tits"
CommonDialog1.ShowOpen
End Sub
Private Sub Command2_Click()
Dim ageX As Byte
Dim CommentsX As String, NameX As String
If FilesHere(Text1.Text) Then
Open Text1.Text For Binary Access Read Lock Write As #1
Get #1, , VersionCheck
If VersionCheck <> 6 Then MsgBox ("Not made in TFV 6")
Get #1, , nLen
NameX = Space(nLen)
Get #1, , NameX
Get #1, , nLen2
CommentsX = Space(nLen2)
Get #1, , nLen2
Get #1, , CommentsX
Get #1, , ageX
Close #1
Text2.Text = CommentsX
Text4.Text = ageX
Text3.Text = NameX
Else
MsgBox ("File not found, dummy!"), , "Where"
End If
End Sub
Private Sub Command3_Click()
TheAge = Val(Text4.Text)
Dim MyFile() As TITS
'If FilesHere(Text1.Text) Then
' If UCase(Right(Text1.Text, 4)) = "TITS" Then Kill Text1.Text
' End If
Open Text1.Text For Binary Access Write Lock Read Write As #1
Put #1, , VersionCheck
nLen = Len(Text3.Text)
Put #1, , nLen
Put #1, , Text3.Text
nLen2 = Len(Text2.Text)
Put #1, , nLen2
Put #1, , Text2.Text
Put #1, , TheAge
Close #1
End Sub
Private Sub Form_Load()
VersionCheck = 6
Text1.Text = App.Path & "\Example.tits"
End Sub
Private Function FilesHere(TheFileName As String) As Boolean
If FileLen(TheFileName) > 0 Then
FilesHere = True: Exit Function
Else
FilesHere = False: Exit Function
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|