-
k i have to make a game 4 school
n i have saved a label to disk
now i want to get it back (4 a high scores thing)
so i did this
Open "a:MyFile.dat" For Input As #1
but i want to get it back so i can see it on tha screen!!!!
hhheeeellpppp meeee pplleaase!!!
-
Heeeere is the helppp!
Try this with a textbox.
FileName = "a:\MyFile.dat"
F = FreeFile
Open FileName For Input As F
Text1.Text = Input$(LOF(F), F)
Close F
Good luck!
-
You have to use an Input # statement to read the data back into variables, which you can then assign to the labels' caption property. How is the data in "myfile.dat" stored?
-
lkjl
i saved it from VB??
"a:MyFile.dat" For Output As #1
-
Is it comma seperated, tab delimated, new line for each score? We need to know the format.
-
ummm
i don't know
where does it show that?
-
open up the file in notepad and tell give us an example of what it looks like
-
i copied and pasted what i had in that command button, then opened it in notepad, and this is what it had:
VERSION 5.00
Begin VB.Form Form4
Caption = "Form4"
ClientHeight = 3075
ClientLeft = 60
ClientTop = 465
ClientWidth = 4680
LinkTopic = "Form4"
ScaleHeight = 3075
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 615
Left = 2280
TabIndex = 0
Top = 1080
Width = 1215
End
End
Attribute VB_Name = "Form4"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Open "a:MyFile.dat" For Input As #1
End Sub
I don't know if thats what u need though cuz it doesn't make ne sence 2 me :)
-
This is how i saved it:
Private Sub YesButton_Click()
Dim Data As String
Data = Form2.Label10.Caption
Open "a:MyFile.dat" For Append As #1
Print #1, Data
Close #1
MsgBox "Time Saved"
End Sub
-
Sorry, i meant your Dat file.
"myFile.Dat"
-
yeh i just opened that, but all it had was what i had saved. I saved what a user of the game had entered.
-
Right
What exactly do you want to do with the data in this file. Please be specific.
And again, post an example of what the data in the file looks like.
e.g
Code:
100, 123, 99, 12
'or
100
123
99
12
'etc...
-
k, the program i m making is a snakes and ladders boardgame. it has a timer, and at the end of the game, the user is asked to click when finished. When they click on that, a message box comes up, asking them for their name and then the time that they recieved, they type it in and it puts that data into label10. Then if they want to save thier game, they click a button, and the data that they typed in which is now in label10, saves to disk. i did this like this:
Dim Data As String
Data = Form2.Label10.Caption
Open "a:MyFile.dat" For Append As #1
Print #1, Data
Close #1
MsgBox "Time Saved"
now i want to be able to allow the user to bring back the score that they saved. so i created a button that would do this:
Open "a:MyFile.dat" For Input As #1
it opens the file, but i want to open it so it shows on the form.
at the moment what is in notepad, when dat is opened is exactly what the user typed in
eg.
amanda 1 min 13secs
-
Okaly dokly then.
Code:
'in button
'make sure the file exists
If dir$("myFile.dat") <> "" Then
'open yuor file.
Open "myFile.Dat" for Input As #1
'where data is your variable to hold info.
Line Input #1, data
'display the data in the label or to where ever
Label10.Caption = data
close #1
End If
Hope this helps.
-