|
-
Dec 2nd, 2004, 08:34 AM
#1
Thread Starter
Hyperactive Member
Text File Handling [Resolved]
Im making a map editor, and i am saving some variables of the collision objects in a text file, and later loading them in the application.
A few questions, How do i do this? I would have an object array, and i would want to put 5 or so variabled for each object, preferably each objects variables on one line, and then load the line for each object in the app. Any help?
Last edited by psycopatchet69; Dec 3rd, 2004 at 01:46 AM.
-
Dec 2nd, 2004, 12:10 PM
#2
Fanatic Member
simplest way I can think of is to use a tab delimted files
first thing on line could be object name followed by variable settings.
if your objects don't have names, but but are just in an array, have the first item be the index array.
do you know how to write to files??
if you can post your object description I could probably whip up some code.
It Never Fails. Everytime I try to make a program idiot proof, the world makes a better idiot.
-
Dec 2nd, 2004, 12:23 PM
#3
Hyperactive Member
I would use Binary file operations (Get and Put).
"I don't want to live alone until I'm married" - M.M.R.P
-
Dec 2nd, 2004, 01:13 PM
#4
Fanatic Member
you could think of something like, to save:
Code:
Dim iFreeFile As Integer, outFile As String
Dim mVar(3, 5) As Long, aCount As Long, bCount As Long
Dim tStr As String
'define vars here
mVar(1, 1) = 3
mVar(1, 2) = 45
mVar(1, 3) = 33
mVar(1, 4) = 673
mVar(1, 5) = 2
mVar(2, 1) = 78
'etc
'define output file name
outFile = "mydata.xxx"
iFreeFile = FreeFile
Open App.Path & "\" & outFile For Output As #iFreeFile
For aCount = 1 To 3
'reset
tStr = ""
For bCount = 1 To 5
tStr = tStr & mVar(aCount, bCount) & Chr(9)
Next bCount
'print values
Print #iFreeFile, tStr
Next aCount
Close #iFreeFile
and get back the data in the same way. however, if you do have loads of records i would definitely go the way Disiance suggests: use bytes.
Last edited by wildcat_2000; Dec 3rd, 2004 at 05:52 AM.
When your car breaks down,
close all windows and retry 
=> please rate all users posts! <=
-
Dec 2nd, 2004, 10:52 PM
#5
Thread Starter
Hyperactive Member
Re: Text File Handling
No, i do not know how to read or write from files, which is my main purpose of this thread, i should have stated that.
Alright, ill explain my problem a little more clearly.
I made a map editor for my rpg, and it saves the map as one single .bmp
The editor also includes a collision maker, which adds the collisions on the maps, and i want them printed into a text file.
I want the textbox to have all the data for one collision object in one line.
For example:
the first line of the text file i want to have the number of collobjts and thats it
with collobjt(0)
.left = 16
.top = 16
.width = 48
.height = 32
end with
i want this data above to be in the 2nd line of the text file as follows
index,left,top,width,height
0,16,16,48,32
So the text file with 1 collobjt would be as follows
0
0,16,16,48,32
With 2 collobjts
1
0,16,16,48,32
1,32,48,48,32
I also need to know how to read these files
I hope that explains what i am looking for. Please help...Soon, i am done coding the editor except for this part, so i cant use it for my game until i figure this out.
If someone could make me a simple example where it saves and loads the data from textboxes into this format, i would appreciate it.
-
Dec 2nd, 2004, 11:28 PM
#6
Thread Starter
Hyperactive Member
-
Dec 3rd, 2004, 12:42 AM
#7
Re: Text File Handling
Code:
Sub WriteFile()
outFile = "mydata.xxx"
iFreeFile = FreeFile
Open App.Path & "\" & outFile For Output As #iFreeFile
print #iFreeFile, UBound(collobjt)
For x = 0 To UBound(collobjt)
with collobjt(x)
print #iFreeFile, .left, .top, .width, .height
End with
Next x
Close #iFreeFile
End Sub
Sub ReadFile()
Dim colobj ', a,b,c,d
outFile = "mydata.xxx"
iFreeFile = FreeFile
Open App.Path & "\" & outFile For Input As #iFreeFile
read #iFreeFile, colobj
Dim collobjt(colobj)
For x = 0 To UBound(collobjt)
with collobjt(x)
read #iFreeFile, .left, .top, .width, .height
' You may Not be able To read directly into properties. Might have To use
' read #iFreeFile, a,b,c,d
' .left = a
' .top = b
' .width = c
' .height = d
End with
Next x
Close #iFreeFile
End Sub
-
Dec 3rd, 2004, 01:22 AM
#8
Thread Starter
Hyperactive Member
Re: Text File Handling
Thank you very much, i think this is doing the trick, the writefile works perfect, but the readfile i dont really understand.... And i dont think that the "Read #ifreefile" is the right function, because the line is displayed in red in vb....
Last edited by psycopatchet69; Dec 3rd, 2004 at 01:27 AM.
-
Dec 3rd, 2004, 01:45 AM
#9
Thread Starter
Hyperactive Member
Re: Text File Handling
Nevermind, i figured it out, the correct term was "Input" not "Read".
I thank you very much for helping me with my code.
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
|