Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: New, again, with BASIC  (Read 28787 times)

0 Members and 1 Guest are viewing this topic.

Newbe

    Topic Starter


    Rookie
  • Learning BASIC "again"
    • QuickBasic 6.4
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows Vista
An Update
« Reply #30 on: April 16, 2013, 12:02:19 PM »
My special thanks to Salmon Trout and Geek-9pm for their fantastic help - including links to more web help. Getting away from the one-line IF-THEN statements seemed to be the key to my problems.

I even got the sound back - my desktop wasn't the problem at all.

I've decided to set this one aside for now and to move on to another project - haven't yet decided what.

Now you know why I say: "Half of knowledge is knowing where to find it."
'Learning.bas
CLS
PRINT "Half of knowledge is knowing where to find it."
SLEEP

Newbe

    Topic Starter


    Rookie
  • Learning BASIC "again"
    • QuickBasic 6.4
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows Vista
Here I go again - with another one
« Reply #31 on: April 30, 2013, 11:40:15 AM »
This program generates a number from two through twelve, simulating the roll of dice. You get to guess the number rolled; get it right and you can try again. Miss it ten times in a row and the game is over.

The program starts by popping up "ROLL THE DICE" one letter at a time but the way I did it seems inefficient. I wonder if there is a more efficient way, say using a DATA statement. The coding of the entire program is copy/pasted below but here is the part I'm wondering about:

LOCATE 5, 21: PRINT "Let's ..."
GOSUB pause: LOCATE 5, 31: PRINT "R " 'pause makes a one-second pause
GOSUB pause: LOCATE 5, 33: PRINT "O "
GOSUB pause: LOCATE 5, 35: PRINT "L "
GOSUB pause: LOCATE 5, 37: PRINT "L "
GOSUB pause: LOCATE 5, 40: PRINT "T "
GOSUB pause: LOCATE 5, 42: PRINT "H "
GOSUB pause: LOCATE 5, 44: PRINT "E "
GOSUB pause: LOCATE 5, 47: PRINT "D "
GOSUB pause: LOCATE 5, 49: PRINT "I "
GOSUB pause: LOCATE 5, 51: PRINT "C "
GOSUB pause: LOCATE 5, 53: PRINT "E "

You can download the program from my website at quickbasic64.weebly.com.
'Learning.bas
CLS
PRINT "Half of knowledge is knowing where to find it."
SLEEP

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: New, again, with BASIC
« Reply #32 on: April 30, 2013, 03:17:11 PM »
I have no idea of what your are doing. Why not just

PRINT "Roll the Dice"

Am, I missing something?

Salmon Trout

  • Guest
Re: New, again, with BASIC
« Reply #33 on: April 30, 2013, 03:24:04 PM »
I have no idea of what your are doing. Why not just

PRINT "Roll the Dice"

Am, I missing something?

He wants to print that phrase, character by character, with a pause after each one.

Newbe

    Topic Starter


    Rookie
  • Learning BASIC "again"
    • QuickBasic 6.4
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows Vista
Re: New, again, with BASIC
« Reply #34 on: April 30, 2013, 05:41:06 PM »
Thank you, Salmon Trout. That's exactly what I'm doing. I'm asking if there's a more efficient way to do it.
'Learning.bas
CLS
PRINT "Half of knowledge is knowing where to find it."
SLEEP

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: New, again, with BASIC
« Reply #35 on: April 30, 2013, 07:18:20 PM »
OK, create a procedure called SLOPRN that takes a string literal as the parameter.
It will can user MID$ to walk thru the letters on by one. After each print,  call the TIMER() to do a short delay.

You would invoke it like this.
LOCATE 5,3
CALL SLOPRN("Roll the Dice.")

Somebody else want to write the procedure? It will take me half and hour 'cause I am so slow.



BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: New, again, with BASIC
« Reply #36 on: April 30, 2013, 08:03:31 PM »
Something like:
Code: [Select]
SUB DELAYPRINT(LINE$, CHARDELAY!)
    DIM I AS INTEGER,STARTTIME AS SINGLE
    FOR I = 0 TO LEN(LNE$)
        PRINT MID$(LNE$,I,1);
        'delay
        STARTTIME=TIMER()
        DO WHILE(TIMER-STARTTIME<CHARDELAY!)
        'nothin.
        LOOP
    NEXT I
END SUB

'EXAMPLE:
DELAYPRINT "This is some text",1

I was trying to dereference Null Pointers before it was cool.

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: New, again, with BASIC
« Reply #37 on: April 30, 2013, 08:27:17 PM »
Yes, BC. That looks good.
By using  a SUB with parameters you can CALL  the same fragment of code over and over again. Just invoke with different parameters and c get various results. Because the SUB uses just local variables, the is no need to be afraid of it doing something bad on your global variables.. (Unless you let it.) The is.was one of the great improvements in QBASIC that set it apart from other BASIC packages of the era.
Remarkable, it even works in a 64 Windows 7. QBASIC still has a number of friends.

Of course, it one wants to do any visual effects, one ought to try and learn Visual Basic. Still  free for the express version. Early version still available.

Newbe

    Topic Starter


    Rookie
  • Learning BASIC "again"
    • QuickBasic 6.4
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows Vista
Thank you all ...
« Reply #38 on: May 01, 2013, 08:48:01 AM »
for the help. :o
'Learning.bas
CLS
PRINT "Half of knowledge is knowing where to find it."
SLEEP

Newbe

    Topic Starter


    Rookie
  • Learning BASIC "again"
    • QuickBasic 6.4
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows Vista
Re: New, again, with BASIC
« Reply #39 on: July 22, 2013, 12:11:38 PM »
Well here I am again with another endeavor. It's another exercise in trivia but with different questions. I gave up on the sound effects - for the present anyway. This time I tried to be more compact on my coding. For example, instead of repeating the same long request for input, I put the request into a subroutine. I also give the user the option of viewing the program in the smaller default QB64 window or in a full screen.

You can view a copy of the code and/or download the program from my website at quickbasic64.weebly.com.

As always I welcome your input.
'Learning.bas
CLS
PRINT "Half of knowledge is knowing where to find it."
SLEEP

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: New, again, with BASIC
« Reply #40 on: July 22, 2013, 12:22:50 PM »
What did you want to do with sound?
If you have the compiler, you can link your program to other libraries.

Newbe

    Topic Starter


    Rookie
  • Learning BASIC "again"
    • QuickBasic 6.4
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows Vista
Re: New, again, with BASIC
« Reply #41 on: July 23, 2013, 02:09:09 PM »
The only "sound" I've gotten into is beeps. It will be months before I try to get into more than that. I'm not ready to go beyond that. Thanks for the offer.
'Learning.bas
CLS
PRINT "Half of knowledge is knowing where to find it."
SLEEP

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: New, again, with BASIC
« Reply #42 on: July 23, 2013, 10:42:31 PM »
QBASIC does more that beep or tweak.
Look here:
Quote
PLAY

PLAY "[string expression]"

Used to play notes and a score in QBasic on a computer equipped with a MIDI sound-card (all modern computer motherboards with built-in sound support MIDI). The tones are indicated by letters A through G. Accidentals are indicated with a "+" or "#" (for sharp) or "-" (for flat) immediately after the note letter. See this example:

PLAY "C C# C C#"

Whitespaces are ignored inside the string expression. There are also codes that sert the duration, octave and tempo. They are all case-insensitive. PLAY executes the commands or notes the order in which they appear in the string. Any indicators that change the properties are effective for the notes following that indicator.

Ln     Sets the duration (length) of the notes. The variable n does not indicate an actual duration
       amount but rather a note type; L1 - whole note, L2 - half note, L4 - quarter note, etc.
       (L8, L16, L32, L64, ...). By default, n = 4.
       For triplets and quintets, use L3, L6, L12, ... and L5, L10, L20, ... series respectively.
       The shorthand notation of length is also provided for a note. For example, "L4 CDE L8 FG L4 AB"
       can be shortened to "L4 CDE F8G8 AB". F and G play as eighth notes while others play as quarter notes.
On     Sets the current octave. Valid values for n are 0 through 6. An octave begins with C and ends with B.
       Remember that C- is equivalent to B.
< >    Changes the current octave respectively down or up one level.
Nn     Plays a specified note in the seven-octave range. Valid values are from 0 to 84. (0 is a pause.)
       Cannot use with sharp and flat. Cannot use with the shorthand notation neither.
MN     Stand for Music Normal. Note duration is 7/8ths of the length indicated by Ln. It is the default mode.
ML     Stand for Music Legato. Note duration is full length of that indicated by Ln.
MS     Stand for Music Staccato. Note duration is 3/4ths of the length indicated by Ln.
Pn     Causes a silence (pause) for the length of note indicated (same as Ln).
Tn     Sets the number of "L4"s per minute (tempo). Valid values are from 32 to 255. The default value is T120.
.      When placed after a note, it causes the duration of the note to be 3/2 of the set duration.
       This is how to get "dotted" notes. "L4 C#." would play C sharp as a dotted quarter note.
       It can be used for a pause as well.
MB MF  Stand for Music Background and Music Foreground. MB places a maximum of 32 notes in the music buffer
       and plays them while executing other statements. Works very well for games.
       MF switches the PLAY mode back to normal. Default is M
It helps if you have a basic knowledge of how to read music.

Newbe

    Topic Starter


    Rookie
  • Learning BASIC "again"
    • QuickBasic 6.4
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows Vista
Re: New, again, with BASIC
« Reply #43 on: September 20, 2013, 10:43:06 AM »
I have a website which relates to what I'm doing here.

Please check it out at:

http://quickbasic64.weebly.com/

Thank you.
'Learning.bas
CLS
PRINT "Half of knowledge is knowing where to find it."
SLEEP