Results 1 to 4 of 4

Thread: Problem with records [Solved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    124

    Resolved 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:
    1. Private Sub cmdGetNewTurkeys_Click()
    2. Dim Password As String
    3. Dim Inputpassword As String
    4. Password = "venrick"
    5.  Inputpassword = InputBox("Please enter the password. Reamber after entering the password all other data in this program will be erased")
    6.   If Inputpassword = Password Then
    7.  
    8.     Open App.Path & "\TurkeyList.dat" For Random As #1 Len = 58
    9.      
    10.      Dim RecordNumber As Integer
    11.      RecordNumber = 0
    12.      
    13.      Do
    14.       RecordNumber = RecordNumber + 1
    15.      
    16.       Put #1, RecordNumber, TurkeyList
    17.        TurkeyList(RecordNumber).TurkeyID = RecordNumber
    18.         Dim Weight As Integer
    19.         Randomize
    20.         Weight = Int((5000 * Rnd) + 5001)
    21.        TurkeyList(RecordNumber).TurkeyWeight = Weight
    22.        TurkeyList(RecordNumber).TurkeySold = False
    23.        TurkeyList(RecordNumber).TurkeyCustomer = "                                                "
    24.        TurkeyList(RecordNumber).TurkeyOrder = 0
    25.       Close #1
    26.      
    27.      Loop Until RecordNumber = 40
    28.    
    29.   Else
    30.    MsgBox ("The password you used is incorrect")
    31.   End If
    32. End Sub
    and here is the modual
    VB Code:
    1. Public Type TurkeyListType
    2.  TurkeyID As Integer
    3.  TurkeyWeight As Integer
    4.  TurkeySold As Boolean
    5.  TurkeyCustomer As String * 50
    6.  TurkeyOrder As Integer
    7. End Type
    8.  
    9. 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:
    1. 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.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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:
    1. Dim Password As String
    2. Dim Inputpassword As String
    3. Password = ""
    4.  Inputpassword = InputBox("Please enter the password. Reamber after entering the password all other data in this program will be erased")
    5.   If Inputpassword = Password Then
    6.     Debug.Print App.Path
    7.     Open App.Path & "\TurkeyList.dat" For Random As #1 Len = 58
    8.      
    9.      Dim RecordNumber As Integer
    10.      RecordNumber = 0
    11.      
    12.      Do
    13.       RecordNumber = RecordNumber + 1
    14.       TurkeyList(RecordNumber).TurkeyID = RecordNumber
    15.         Dim Weight As Integer
    16.         Randomize
    17.         Weight = Int((5000 * Rnd) + 5001)
    18.        TurkeyList(RecordNumber).TurkeyWeight = Weight
    19.        TurkeyList(RecordNumber).TurkeySold = False
    20.        TurkeyList(RecordNumber).TurkeyCustomer = "                                                "
    21.        TurkeyList(RecordNumber).TurkeyOrder = 0
    22.       Put #1, RecordNumber, TurkeyList(RecordNumber)
    23.  
    24.      
    25.      
    26.      Loop Until RecordNumber = 40
    27.         Close #1
    28.   Else
    29.    MsgBox ("The password you used is incorrect")
    30.   End If
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    124

    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.

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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
  •  



Click Here to Expand Forum to Full Width