Results 1 to 7 of 7

Thread: Is there a VB equivalent to the READ & DATA statements???

  1. #1

    Thread Starter
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526

    Question

    If anyone can help me, I'm trying to convert a QuickBasic4.5 program to VB6 and the one thing tripping me up is that I can't seem to get READ and DATA statements to work . . .



    mikeycorn

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    What is it exactly you are reading from the file and what is the format of the file?

    If you cut'n'paste a couple of lines out of the file, explain how it works and what you want done with it I can help you

  3. #3
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    Ah! The beloved READ and DATA statements of QBasic! I forgot all about them, they were fantastic.

    Anyway Mikeycorn, to answer your question, there are no direct equivalents in VB. None!

    You will have to make a text file in Notepad containing your DATA statement (without the word DATA, and separated by commas) and then read the file into VB like this:

    Code:
    Dim Readtext() as String
    Dim LoopCount as Integer
    
    LoopCount=0
    Open "C:\Wherever\Whatever.txt" for input as #1
      Do
        Redim Preserve Readtext(LoopCount)
        Input #1,Readtext(LoopCount)
        LoopCount=LoopCount+1
      Loop While Not EOF(1)
    Close #1
    Now the array Readtext will contain all of your data.
    Also, you'll have to change the C:\Whereever... to the text file you made. Put this function into your Form_Load event.


  4. #4

    Thread Starter
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526

    Wink

    Hmmm . . . this is such a new way of thinking for me. All the code that I used to write back in the day was so linear, I can remember when the line numbers beside the commands became an optional thing it seemed like flying without a net.

    Now I'm away from programming for a few years and I come back and it's all this modular madness! I used to like having my data self-contained inside the program, now I have to think in modules and forms and multiple files. Oh well, it's good for the brain to have to think in new ways . . .

    My program's called PEST - Personal Exam Self-Tester. The QuickBasic code has around 200 questions with 4 multiple choice answers for each.

    Two questions:

    1) I followed the above code and the Redim Preserve is a pretty interesting statement, but can it go as high as 200?

    2) I'll have to write a program to get rid of all the DATA infront of the text, but some of the questions have commas. Can I keep the text in quotes or should I use a substitute character for the commas???

    Thanks for the help,

    mikeycorn

  5. #5
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    I think an array can have up to 65535 items in it, but I'm not sure. It can certainly have 200.
    Keep the data statements in quotes, then put commas between the quotes.
    If you have separate questions, you could also use a line-break between them.
    i.e. DATA "Hello There","Goodbye There","What's, That?"
    becomes
    "Hello There"
    "Goodbye There"
    "What's, That?"
    or
    "Hello There","Goodbye There","What's, That?"
    Whichever you prefer.
    Can you not just open the QB file in notepad and cut and paste the data statements to a new file?

  6. #6
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    You don't HAVE to get rid of the DATA infront of each line... you can get VB to do it for you when it reads from the file...

    Perhaps as I suggested you cut'n'paste a few lines of the file into here so I can look at it... enough to make it clear what its doing.

    As for arrays going as high as 200 they do it with ease. You can either use that or you can go to a "collection" which is effectively a linked list (ala Pascal or good old C).

    One thing I have always found true of programming is that it follows the lines of evolution... If you don't adapt you die

  7. #7

    Thread Starter
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526

    here's that code

    CLS
    GOSUB 1000
    RANDOMIZE TIMER

    FOR loopp = 1 TO howm
    RESTORE
    qnum% = (RND * datab)

    FOR a = 1 TO loopp
    IF logg(a) = qnum% THEN 90
    NEXT a
    GOTO 95

    90 FOR bb = datab TO 1 STEP -1
    FOR b = 1 TO loopp
    IF logg(b) = bb THEN 92
    NEXT b
    GOTO 93
    92 NEXT bb
    93 qnum% = bb
    95 logg(loopp) = qnum%

    FOR c = 1 TO qnum%
    98 READ b$
    IF c = qnum% AND RIGHT$(b$, 1) = "^" THEN PRINT LEFT$(b$, LEN(b$) - 1): GOTO 98
    IF RIGHT$(b$, 1) = "^" THEN 98
    IF c <> qnum% THEN 105
    IF c = qnum% AND LEN(b$) < 81 THEN PRINT b$: GOTO 105

    FOR d = 81 TO 60 STEP -1
    IF MID$(b$, d, 1) <> " " THEN 99
    PRINT LEFT$(b$, d - 1)
    IF LEN(RIGHT$(b$, LEN(b$) - d)) < 80 THEN PRINT " "; RIGHT$(b$, LEN(b$) - d): GOTO 105
    GOTO 100
    99 NEXT d

    100 FOR dd = d + 79 TO d STEP -1
    IF MID$(b$, dd, 1) <> " " THEN 101
    PRINT MID$(b$, d, dd - d): PRINT " "; RIGHT$(b$, LEN(b$) - dd): GOTO 105
    101 NEXT dd

    105 READ c$(1), c$(2)
    flag = 5: IF c$(2) = "b. false" OR c$(2) = "*b. false" OR c$(2) = "b. no" THEN flag = 2: GOTO 110
    READ c$(3), c$(4), c$(5)
    110 NEXT c

    cor$ = ""
    PRINT
    275 FOR e = 1 TO flag
    IF LEFT$(c$(e), 1) = "*" THEN cor$ = cor$ + MID$(c$(e), 2, 1): c$(e) = RIGHT$(c$(e), LEN(c$(e)) - 1)
    PRINT " ";
    IF LEN(c$(e)) < 72 THEN 280

    FOR d = 72 TO 50 STEP -1
    IF MID$(c$(e), d, 1) = " " THEN PRINT LEFT$(c$(e), d - 1): PRINT TAB(8); RIGHT$(c$(e), LEN(c$(e)) - d): GOTO 290
    NEXT d

    280 PRINT c$(e)
    290 NEXT e
    300 PRINT

    305 INPUT ". . . . . "; ans$: PRINT

    FOR a = 1 TO LEN(ans$)
    b = ASC(MID$(ans$, a, 1))
    IF b < 65 OR b > 90 THEN 306
    IF a > 1 THEN le$ = LEFT$(ans$, a - 1) ELSE le$ = ""
    mi$ = CHR$(ASC(MID$(ans$, a, 1)) + 32)
    IF LEN(ans$) - a > 0 THEN ri$ = RIGHT$(ans$, LEN(ans$) - a) ELSE ri$ = ""
    ans$ = le$ + mi$ + ri$
    306 NEXT a

    IF ans$ <> cor$ THEN 308
    307 PRINT " >>> Correct!!! <<<": cor = cor + 1: GOTO 310
    308 wran% = (RND * 50): IF wran% > 25 THEN wran% = 20
    PRINT " "; w$(wran%); " The answer is "; cor$; "."
    310 PRINT "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
    NEXT loopp

    cen$ = "You got" + STR$(cor) + " questions right out of a possible" + STR$(howm) + ".": GOSUB 2000
    PRINT
    pct = 100 / howm: pct = cor * pct
    grd$ = "n F. (Yikes!)"
    IF pct >= 60 THEN grd$ = " D."
    IF pct >= 70 THEN grd$ = " C."
    IF pct >= 80 THEN grd$ = " B."
    IF pct >= 90 THEN grd$ = "n A!!! (Excellent!)"
    cen$ = "You scored" + STR$(INT(pct)) + "%. If you were being graded, you'd get a" + grd$: GOSUB 2000
    PRINT
    cen$ = "Hope you had fun!": GOSUB 2000
    PRINT
    cen$ = "Press any key to quit . . .": GOSUB 2000

    DO
    LOOP WHILE INKEY$ = ""
    STOP

    1000 w$(1) = "Wrong."
    w$(2) = "I'm afraid not."
    w$(3) = "That would not be the answer we were looking for."
    w$(4) = "Uh . . . no."
    w$(5) = "Perhaps you hit the wrong key."
    w$(6) = "Not really, no."
    w$(7) = "Perhaps we should study a bit more!"
    w$(8) = "Nope!"
    w$(9) = "I don't think so!"
    w$(10) = "I hear that they're hiring over at El Pollo Loco."
    w$(11) = "I'm really trying to be patient here!"
    w$(12) = "You're embarrassing yourself!"
    w$(13) = "Boy, you really had me fooled. I thought you knew this stuff."
    w$(14) = "Yeah okay, whatever."
    w$(15) = ":-( "
    w$(16) = "Why on Earth would you say that??? . . . "
    w$(17) = "Okay, you're just trying to exasperate me, aren't you? . . . "
    w$(18) = "Puh - lease!"
    w$(19) = "I wish I could tell you that you're right, but . . . "
    w$(20) = "Sorry."
    w$(21) = "Doh!"
    w$(22) = "Quit playing around."
    w$(23) = "Ah, #@($*."
    w$(24) = "Bill Gates is not smiling."
    w$(25) = "No me gusta."
    RETURN

    2000 PRINT TAB((80 - LEN(cen$)) / 2); cen$: RETURN




    DATA "1. Before upgrading your operating system, you should first:"

    DATA "a. remove TSRs"
    DATA "*b. backup your hard drive"
    DATA "c. edit the startup files"
    DATA "d. run scandisk"
    DATA "e. run chkdsk"

    DATA "2. What DOS program can you run to see which serial ports are detected?"

    DATA "a. comdiag"
    DATA "*b. MSD"
    DATA "c. command.com"
    DATA "d. SDET"
    DATA "e. serial.chk"

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