|
-
Dec 30th, 2005, 07:51 AM
#1
Thread Starter
Lively Member
Problem with records [Solved]
Okay im making some stupid turkey program as part of some collage work but I can't get this to work
Here is the code for the command button
VB Code:
Private Sub cmdGetNewTurkeys_Click()
Dim Password As String
Dim Inputpassword As String
Password = "venrick"
Inputpassword = InputBox("Please enter the password. Reamber after entering the password all other data in this program will be erased")
If Inputpassword = Password Then
Open App.Path & "\TurkeyList.dat" For Random As #1 Len = 58
Dim RecordNumber As Integer
RecordNumber = 0
Do
RecordNumber = RecordNumber + 1
Put #1, RecordNumber, TurkeyList
TurkeyList(RecordNumber).TurkeyID = RecordNumber
Dim Weight As Integer
Randomize
Weight = Int((5000 * Rnd) + 5001)
TurkeyList(RecordNumber).TurkeyWeight = Weight
TurkeyList(RecordNumber).TurkeySold = False
TurkeyList(RecordNumber).TurkeyCustomer = " "
TurkeyList(RecordNumber).TurkeyOrder = 0
Close #1
Loop Until RecordNumber = 40
Else
MsgBox ("The password you used is incorrect")
End If
End Sub
and here is the modual
VB Code:
Public Type TurkeyListType
TurkeyID As Integer
TurkeyWeight As Integer
TurkeySold As Boolean
TurkeyCustomer As String * 50
TurkeyOrder As Integer
End Type
Public TurkeyList(1 To 40) As TurkeyListType
How ever when i run the program it says "Error Bad file lenght" But i can't work it out :S this is the line of code that it says is wrong
VB Code:
Open App.Path & "\TurkeyList.dat" For Random As #1 Len = 58
What is wrong with that?
Can anyone help me?
Edit: Added [vbcode][/vbcode] tags for more clarity. - Hack
Last edited by ichar; Dec 30th, 2005 at 08:31 AM.
-
Dec 30th, 2005, 08:25 AM
#2
Re: Problem with records
couple of things:
1) I do not get that error...
-if the Turkey.dat is already there.. try deleting it then running.
2) your code needed some re-arraging
-u were trying to "put" the turrkey data before u had it set up
-u were closing the file before u finished writing it
-u needed (Recordnumber) with the Turkeylist()
VB Code:
Dim Password As String
Dim Inputpassword As String
Password = ""
Inputpassword = InputBox("Please enter the password. Reamber after entering the password all other data in this program will be erased")
If Inputpassword = Password Then
Debug.Print App.Path
Open App.Path & "\TurkeyList.dat" For Random As #1 Len = 58
Dim RecordNumber As Integer
RecordNumber = 0
Do
RecordNumber = RecordNumber + 1
TurkeyList(RecordNumber).TurkeyID = RecordNumber
Dim Weight As Integer
Randomize
Weight = Int((5000 * Rnd) + 5001)
TurkeyList(RecordNumber).TurkeyWeight = Weight
TurkeyList(RecordNumber).TurkeySold = False
TurkeyList(RecordNumber).TurkeyCustomer = " "
TurkeyList(RecordNumber).TurkeyOrder = 0
Put #1, RecordNumber, TurkeyList(RecordNumber)
Loop Until RecordNumber = 40
Close #1
Else
MsgBox ("The password you used is incorrect")
End If
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Dec 30th, 2005, 08:30 AM
#3
Thread Starter
Lively Member
Re: Problem with records
Wa hey! thanks Static, as you can properly tell im a bit of a dummy/N00b
Thanks again.
Last edited by Hack; Dec 30th, 2005 at 10:06 AM.
-
Dec 30th, 2005, 09:43 AM
#4
Re: Problem with records [Solved]
No problem!
a) welcome to the forums (just noticed it was your first post)
b) you are not a dummy/n00b you were close
c) you had everything you needed.. just not in the right order! thats pretty good!
also: fyi... just above your the first post is "Thread Tools" if u click that there is a Thread resolved option.. so next post.. you'll know how to easily mark the thread resolved! Enjoy!
Last edited by Hack; Dec 30th, 2005 at 10:06 AM.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|