Results 1 to 4 of 4

Thread: random access

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    okinawa
    Posts
    3

    Question

    when opening up a file utilizing random acces files

    how do i open and print more than one record at a time
    to the screen

    variables are dimmed properly
    option baseline

    open file for Random as #1 Len(Questions(1))
    numrecs=LOF(1) /Len(Questions(1))
    for i= 1 to numrecs
    get#1, , Questions(i)
    next i
    print i (?)
    close #1

    my probelm is when i look at the form it prints 1 to screen, when i run the program my numrecs = 0 is and len = 150 and skips over get #1, , Questions(1) and doesn't print anything else.

  2. #2
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    OK It's late and I 'm tired...However (If I read it correctly)
    Your file prints all BUT the first one???

    open file for Random as #1 Len(Questions(1))
    numrecs=LOF(1) /Len(Questions(1))
    for i= 1 to numrecs
    get#1, , Questions(i)
    next i
    print i (?) 'You only told it to print the next i, not the first i
    close #1

    again, I hope I read it right
    Lee
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    okinawa
    Posts
    3

    Talking Thank-you I promise I have more

    Ok here goes

    You were absolutely correct.

    What I am ultimately trying to do is read from a random file into a form to create a quizer program.

    I got the records to load into the file, but because of the LOF it runs through the loop and shows the last questions(i)(lblques, opta, optb, optc, optd.) There are currently 10 questions in the rnd flie that I am pulling from and its the tenth one that shows on the form. How do I get it to read one question let the user click on an opt then go to the next question without using new forms.

    formload

    open file for Random as #1 Len(Questions(1))
    numrecs=LOF(1) /Len(Questions(1))
    for i= 1 to numrecs
    get#1, , Questions(i)

    lbl1= i
    lbl2=Questions(1).Question
    opt1(0) = Questions(1).optiona
    opt1(1) = Questions(1).optionb
    opt1(2) = Questions(1).optionc
    opt1(3) = Questions(1).optiond

    next i

    close #1


    The above is what I am trying to do am I on the right track?

  4. #4
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360

    Lightbulb

    You are close:

    formload

    open file for Random as #1 Len(Questions(1))
    numrecs=LOF(1) /Len(Questions(1))
    for i= 1 to numrecs
    get#1, , Questions(i)

    lbl1= i
    lbl2=Questions(1).Question
    opt1(0) = Questions(1).optiona
    opt1(1) = Questions(1).optionb
    opt1(2) = Questions(1).optionc
    opt1(3) = Questions(1).optiond

    next i

    close #1


    But I would try to use something like this
    (If there is only 1 label for output)



    Select Case Opt(Index As Integer)

    Case 0
    LabelName.Caption = Question(1)
    Case 1
    LabelName.caption = Question(2)

    And so on.


    Also:
    This Select case statement should be written in the
    OPT(Index) Click Event...Not the form load procedure.

    I hope this helps...It's kind of Cryptic!
    Lee
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

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