QBasic and QB64 Discussion Board

[QB Forum Archives (1999-2009)/ ] [QB FAQ] [QB Links and Downloads] [Subforums and Chat Room] [Search]

QB64.Net Homepage   QB/QB64 Keywords   QB Graphics Forum   Homework Policy


How do you make an enemy move?

by (no login)

So I'm trying to make an RPG game, I want to know how I can move enemys without crashing into walls. I'm pretty new at this so you might have to explain it a bit. Thanks.

Posted on Jan 21, 2012, 3:21 PM

Respond to this message   

Return to Index


Before a sprite moves, check for the wall

by (Login burger2227)
R

You can use POINT or the SCREEN function in ASCII games to find the wall color or make up a map array of where the walls are to find them.

Before you move the sprite, make sure that you CAN move there. If you need to find the screen borders make sure the coordinates do not exceed the screen size.

Posted on Jan 21, 2012, 6:25 PM

Respond to this message   

Return to Index


Re: How do you make an enemy move?

by Rick4551 (no login)

Well I already used arrays for my map to stop the actual player from going through the walls. But I really need to know how the enemies/AI move on their own and without crashing into walls.

I had an idea of putting it into a loop but it would just loop the enemy movement and the actual you won't be able to move your guy.

Posted on Jan 21, 2012, 8:24 PM

Respond to this message   

Return to Index


Here's a little program that explains it...

by (Login qb432l)
R

It takes a bit of study, but once you understand the concepts, you can create any type of game play area and have AI pieces navigate that area as if they know where they're going -- but with all movement randomly generated. Their location on the map can be established by adding 100 to the square's value while they're there so your player knows if an enemy is there.
Good luck!
-Bob

'Copy code from here ------------------------------------------------------
'AI NAVIGATION OF A PATH: Press F5 to run.

'A 2-dimensional array is dimmed representing a 16x24 square play area
DIM Map(1 TO 24, 1 TO 16) AS INTEGER

'DATA reflects the values of the play area: 1 is non-path, 0 is straight
'path with no intersections, and intersections have values as follows...

MapDATA:
DATA 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
DATA 1, 6, 0, 0, 0, 0, 14,0, 0, 0, 0, 0, 14,0, 0, 0, 14,0, 14,0, 14,0, 12,1
DATA 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1
DATA 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1
DATA 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 7, 0, 15,0, 15,0, 13,1
DATA 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1
DATA 1, 7, 0, 0, 14,0, 15,0, 0, 14,0, 0, 13,1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1
DATA 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 7, 0, 0, 0, 15,0, 11,0, 11,0, 13,1
DATA 1, 7, 0, 0, 11,0, 13,1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1
DATA 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1
DATA 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 7, 0, 0, 0, 15,0, 0, 0, 0, 0, 13,1
DATA 1, 7, 0, 0, 0, 0, 13,1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1
DATA 1, 0, 1, 1, 1, 1, 7, 0, 0, 11,0, 0, 13,1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1
DATA 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1
DATA 1, 3, 0, 0, 0, 0, 11,0, 0, 0, 0, 0, 11,0, 0, 0, 11,0, 0, 0, 0, 0, 9, 1
DATA 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1

'To begin with, each of the four possible directions of travel are
'represented by the lower four bits of a byte: 1, 2, 4 and 8. The "UP"
'direction is given a value of 1, "RIGHT" gets a value of 2, "DOWN" gets
'a value of 4, and "LEFT" a value of 8.

'An intersection's value then, is simply an addition of these values
'depending on which directions are possible. For example, the bottom-
'left turn in the grid has only two possible directions: "UP" and
'"RIGHT", therefore its value is 1 + 2 = 3. An intersection wherein
'all directions are possible is valued as 1 + 2 + 4 + 8 = 15. I'm
'sure you get the idea.

'The direction an AI game piece is coming from is given the value of
'that direction. The variable "ExDIRECTION", for example, will have a
'value of 2 if the AI game piece is coming from the right.

'NOW...

'As the AI game piece moves, its Row and Column variables (Row/Col) are
'constantly updated based on the direction of travel. If the piece is
'moving to the left, then Col = Col - 1, etc..

'Before the piece moves, its position relative to the map is checked.
'Map(Col, Row) will give us this value. If the value of that array
'element is zero, the piece simply continues along in the direction
'it has been going. If, on the other hand, the square has a value,
'then it is known to be an intersection and a turn must be determined.

'To begin with, there is a random value generated representing the
'four turns (1, 2, 4 and 8):
'NewDIRECTION = INT(RND * 4) + 1
'This will give a value of 1, 2, 3 or 4. Then we simply say:
'IF NewDIRECTION = 3 THEN NewDIRECTION = 8
'Hence, 1, 2, 4 or 8 are generated.

'Then we do what is called a bit-wise comparison of this random value
'with the intersection to see if our randomly-chosen turn is possible
'at that intersection. We simply AND NewDIRECTION with Map(Col, Row).
'Basically, what this is asking is, does my random turn exists at this
'intersection? If, for example, the random turn is 1 (UP) and the
'value of the intersection is 3 (UP/RIGHT), then the answer comes back
'YES (in other words, the 1-bit is set in the value 3 [0011]. This
'means that an "UP" turn is legal. The next thing that must be deter-
'mined is if the random turn is where we came from. If it is, then we
'try again, otherwise we'd constantly be bouncing off intersections
'rather than going through them. This is simply a case of comparing
'the NewDIRECTION variable with the ExDIRECTION variable to make sure
'they're not the same.

'The whole thing is enclosed in a DO loop that just keeps looping
'until it gets a viable result:

'DO
'Choose random direction (NewDIRECTION will = 1, 2, 4 or 8)
'LOOP UNTIL ((Map(Col, Row)) AND NewDIRECTION)
'---line continues--- AND (NewDIRECTION <> ExDIRECTION)

'The above loop will execute instantaneously and with a viable turn.

'Now we have a new direction of travel, as well as a new "ExDIRECTION".
'The x/y increments are set accordingly and Row and Col are updated with
'each iteration of the main loop.

'ACTUAL PROGRAM BEGINS HERE ------------------------------------------------

'Read DATA into map array
RESTORE MapDATA
FOR Row = 1 TO 16
FOR Col = 1 TO 24
READ Map(Col, Row)
NEXT Col
NEXT Row

SCREEN 12
PALETTE 4, 63 'bright red for moving square

'Draw play area based on values in the array
Row = 0: Col = 0
FOR x = 80 TO 540 STEP 20
Col = Col + 1
FOR y = 80 TO 380 STEP 20
Row = Row + 1
IF Map(Col, Row) <> 1 THEN Colr = 1 ELSE Colr = 9
LINE (x, y)-(x + 19, y + 19), Colr, BF
NEXT y
Row = 0
NEXT x

COLOR 7
LOCATE 4, 31: PRINT "AI NAVIGATION OF A PATH"
LOCATE 27, 33: PRINT "PRESS SPACE TO QUIT"

'Initialize AI game piece postion, both in terms of the array (Row/Col)
'and in graphical terms (x/y):
Row = 2: Col = 2
x = 100: y = 100
Speed = 2 'increase to slow/decrease to speed up

'Start the main loop
DO
LINE (x, y)-(x + 19, y + 19), 1, BF 'erase old game piece postion

IF Map(Col, Row) <> 0 THEN 'make sure we're at an intersection

'NOTE: We are at an intersection to begin with which is why there
'was no need to initialize the variable ExDIRECTION

'------------------- the random loop explained above --------------------
DO
NewDIRECTION = INT(RND * 4) + 1
IF NewDIRECTION = 3 THEN NewDIRECTION = 8
LOOP UNTIL (Map(Col, Row) AND NewDIRECTION) AND (NewDIRECTION <> ExDIRECTION)
'------------------------------------------------------------------------

END IF

'Establish increments, Row/Col changes based on NewDIRECTION (which
'remains unchanged if the square was a zero).

SELECT CASE NewDIRECTION
CASE 1: IncX = 0: IncY = -20: Row = Row - 1: ExDIRECTION = 4
CASE 2: IncX = 20: IncY = 0: Col = Col + 1: ExDIRECTION = 8
CASE 4: IncX = 0: IncY = 20: Row = Row + 1: ExDIRECTION = 1
CASE 8: IncX = -20: IncY = 0: Col = Col - 1: ExDIRECTION = 2
END SELECT
x = x + IncX: y = y + IncY 'graphical x/y incrementation

'Draw/PUT game piece
LINE (x, y)-(x + 19, y + 19), 4, BF
CIRCLE (x + 10, y + 10), 6, 14
PAINT STEP(0, 0), 14

'Wait for retrace (creates adequate pause so we see the game piece)
FOR Delay = 1 TO Speed
WAIT &H3DA, 8
WAIT &H3DA, 8, 8
NEXT Delay

a$ = INKEY$ 'check for exit request
LOOP UNTIL a$ = " " 'main loop terminates



    
This message has been edited by qb432l on Jan 21, 2012 8:50 PM
This message has been edited by qb432l on Jan 21, 2012 8:49 PM
This message has been edited by qb432l on Jan 21, 2012 8:46 PM
This message has been edited by qb432l on Jan 21, 2012 8:43 PM

Posted on Jan 21, 2012, 8:42 PM

Respond to this message   

Return to Index


Tell the enemy where you are

by (Login burger2227)
R

The program knows where you are so move the enemy in that direction. If it encounters a wall, it will have to move in a free direction trying to move toward you in a column or row direction.

Posted on Jan 21, 2012, 8:53 PM

Respond to this message   

Return to Index


it could get trapped

by Ben (no login)

http://en.wikipedia.org/wiki/Pathfinding

read this,
try to post some code here that works somehow like your game for the members here could adapt to your situation in their solutions

Posted on Jan 21, 2012, 10:17 PM

Respond to this message   

Return to Index


Going towards a different approach

by Rick4551 (no login)

Ok so I'm going for a different approach. Instead of having the enemy move and attack on its own I'll just make it intiate a battle, where you pick to attack, defend or heal and the computer does the same. I did all that but now my main problem is that everytime the battle ends I can't move the person anymore, I've tried exit do which doesn't help.
Here is the part of the code: Drawmaps are a sub

drawmap

col% = 3
row% = 3
x% = 16
y% = 16
score% = 0
PUT (88, 112), glass()
PUT (x%, y%), hero()
herohealth% = 100
heroarmor% = 100
DO '*****************************movement code
k$ = INKEY$
IF k$ = CHR$(0) + CHR$(77) THEN 'right arrow key
IF MID$(map$(row%), col% + 1, 1) = " " THEN
PUT (x%, y%), hero()
x% = x% + 8
col% = col% + 1
PUT (x%, y%), hero()
score% = score% + 1
END IF
ELSEIF k$ = CHR$(0) + CHR$(75) THEN 'left arrow key
IF MID$(map$(row%), col% - 1, 1) = " " THEN
PUT (x%, y%), hero()
x% = x% - 8
col% = col% - 1
PUT (x%, y%), hero()
score% = score% + 1
END IF
ELSEIF k$ = CHR$(0) + CHR$(80) THEN 'down arrow key
IF MID$(map$(row% + 1), col%, 1) = " " THEN
PUT (x%, y%), hero()
y% = y% + 8
row% = row% + 1
PUT (x%, y%), hero()
score% = score% + 1
END IF
ELSEIF k$ = CHR$(0) + CHR$(72) THEN 'up arrow key
IF MID$(map$(row% - 1), col%, 1) = " " THEN
PUT (x%, y%), hero()
y% = y% - 8
row% = row% - 1
PUT (x%, y%), hero()
score% = score% + 1
END IF '**********************end of movement code
END IF
LOCATE 1, 1
PRINT "Score:"; score%
LOCATE 2, 2
PRINT x%; " "; y%
LOCATE 1, 27
PRINT "Health:"; herohealth%
LOCATE 2, 27
PRINT "Armor: "; heroarmor%
IF x% = 88 AND y% = 112 THEN
PUT (280, 40), arrow()
END IF
IF x% = 296 AND y% = 40 THEN
CLS
drawmap2
x% = 8
y% = 40
col% = 2
row% = 6
PUT (x%, y%), hero()
PUT (16, 64), badguy()
PUT (64, 24), badguy()
PUT (120, 40), badguy()
PUT (136, 40), badguy()
PUT (184, 40), badguy()
END IF
IF x% = 16 AND y% = 64 OR x% = 64 AND y% = 24 OR x% = 120 AND y% = 40 OR x% = 136 AND y% = 40 OR x% = 184 AND y% = 40 THEN
enemhealth% = 100
enemarmor% = 100


'**************************battlemap
DO
CLS
OPEN "J:\qb\btlmap.txt" FOR INPUT AS #9
row% = 0
mapx% = 0
mapy% = 0
DO
row% = row% + 1
LINE INPUT #9, map$(row%)
FOR col% = 1 TO LEN(map$(row%))
IF MID$(map$(row%), col%, 1) = "w" THEN
PUT (mapx%, mapy%), map()
END IF
mapx% = mapx% + 8
NEXT col%
mapx% = 0
mapy% = mapy% + 8
LOOP UNTIL EOF(9)
CLOSE #9
PUT (96, 64), hero()
PUT (208, 64), badguy()
'***************************end of battlemap drawing


LOCATE 14, 9
PRINT "Please choose something:"
LOCATE 16, 10
COLOR 47
PRINT "D: Defend"
LOCATE 18, 10
COLOR 40
PRINT "A: Attack"
LOCATE 20, 10
COLOR 54
PRINT "H: Heal"
LOCATE 1, 1
PRINT "Score:"; score%
LOCATE 1, 20
PRINT "Your health:"; herohealth%
LOCATE 2, 20
PRINT "Your armor: "; heroarmor%
LOCATE 4, 20
PRINT "Enemy health:"; enemhealth%
LOCATE 5, 20
PRINT "Enemy armor:"; enemarmor%

LOCATE 22, 9
INPUT opt2$
enemopt% = RND + 1
enemattak% = RND * 10 + 10
heroattak% = RND * 10 + 10
IF UCASE$(opt2$) = "D" THEN
'defending code
ELSEIF UCASE$(opt2$) = "A" THEN
'attack code
ELSEIF UCASE$(opt2$) = "H" THEN
'healing code
END IF
IF herohealth% <= 0 THEN
'cut the code for the game over screen
END IF
IF enemhealth% <= 0 THEN
CLS
drawmap2
x% = x% + 8 'this the that's giving me problems
col% = col% + 1 'don't know how to get the game to show
PUT (x%, y%), hero()
score% = score% + 150
EXIT DO
END IF
LOOP
END IF
LOOP UNTIL k$ = CHR$(27) 'esc key to end

Posted on Jan 22, 2012, 4:05 PM

Respond to this message   

Return to Index


Re: Going towards a different approach

by Rick4551 (no login)

Never mind I found the problem but thanks for the help. :)

Posted on Jan 23, 2012, 5:59 PM

Respond to this message   

Return to Index


Move It -- Just for fun

by Solitaire (Login Solitaire1)
S

My back went out several weeks ago (the day before New Year's Eve) and I've had a lot of trouble moving around.  At my age, it's taking a long time to recover and I've been homebound for the most part.  (I was home alone watching the Times Square ball drop on TV.)  My son drove me to school on the days I had to teach.  My students helped open doors, carry my stuff and pass around the handouts.

Just for fun, I wrote a short QB program to move a smiling face across, down, and diagonally across the screen.  It moves faster than I can.

CLS
ch$ = CHR$(1)
a = 4
LOCATE 1, 30
PRINT "Move Across"
FOR x = 2 TO 80 STEP 2
    COLOR 14
    LOCATE 4, a
    PRINT " "
    LOCATE 4, x
    PRINT ch$
    a = x
    t = TIMER
    DO WHILE (t + .12) >= TIMER
    LOOP
NEXT x
COLOR 7
LOCATE 2, 30
PRINT "Move Down    "

FOR x = 2 TO 23
    COLOR 14
    LOCATE x - 1, 4
    PRINT " "
    LOCATE x, 4
    PRINT ch$
    t = TIMER
    DO WHILE (t + .12) >= TIMER
    LOOP
NEXT x
COLOR 7

LOCATE 3, 30
PRINT "Move Diagonally"
a = 2
b = 2
FOR x = 2 TO 20
    COLOR 14
    y = x
    z = x * 4
    LOCATE a, b
    PRINT " "
    LOCATE y, z
    PRINT ch$
    a = y
    b = z
    t = TIMER
    DO WHILE (t + .12) >= TIMER
    LOOP
NEXT x
br = 9    'begin row
er = 15   'end row
bc = 32   'begin column
ec = 42   'end column
LOCATE br, bc
PRINT CHR$(218); STRING$(9, CHR$(196)); CHR$(191)
FOR x = br + 1 TO er
    LOCATE x, bc: PRINT CHR$(179)
    LOCATE x, ec: PRINT CHR$(179)
NEXT x
LOCATE x, bc
PRINT CHR$(192); STRING$(9, CHR$(196)); CHR$(217)

LOCATE 10, 35: PRINT "_     _"
LOCATE 11, 35: PRINT CHR$(239); "     "; CHR$(239)
LOCATE 13, 37: PRINT "^"
LOCATE 14, 35: PRINT "\___/"
COLOR 7
LOCATE 20, 36: PRINT "OK"
END

 

 



    
This message has been edited by Solitaire1 on Jan 18, 2012 8:10 PM
This message has been edited by Solitaire1 on Jan 18, 2012 7:58 PM
This message has been edited by Solitaire1 on Jan 17, 2012 4:37 PM

Posted on Jan 17, 2012, 3:20 PM

Respond to this message   

Return to Index


Cute!

by (Login burger2227)
R

Thanks for sharing...I know how you feel.

wink.gif

Posted on Jan 17, 2012, 8:48 PM

Respond to this message   

Return to Index


Solitaire, I love your programs

by AlGoreIthm (no login)

Please Get Well Soon!

==============================================================================

CLS

heading$(1) = "Move Across"
heading$(2) = "Move Down  "
heading$(3) = "Move Diagonally"
limit%(1) = 80: stp%(1) = 2
limit%(2) = 23: stp%(2) = 1
limit%(3) = 80: stp%(3) = 4

FOR round% = 1 TO 3
COLOR 7: LOCATE 2, 30: PRINT heading$(round%)
COLOR 14
y% = 4
FOR x% = 2 TO limit%(round%) STEP stp%(round%)

IF round% = 2 THEN LOCATE x%, y% ELSE LOCATE y%, x%
PRINT CHR$(1)

t = TIMER
DO WHILE (t + .12) >= TIMER
LOOP

IF round% = 2 THEN LOCATE x%, y% ELSE LOCATE y%, x%
PRINT " "
IF round% = 3 THEN y% = y% + 1

NEXT x%, round%

LOCATE 9, 32: PRINT CHR$(218); STRING$(9, CHR$(196)); CHR$(191)

FOR x = 10 TO 15
LOCATE x, 32: PRINT CHR$(179); TAB(42); CHR$(179)
NEXT x

LOCATE x, 32: PRINT CHR$(192); STRING$(9, CHR$(196)); CHR$(217)

LOCATE 10, 35: PRINT "_   _"
LOCATE 11, 35: PRINT CHR$(239); "   "; CHR$(239)
LOCATE 13, 37: PRINT "^"
LOCATE 14, 35: PRINT "\___/"
COLOR 7
LOCATE 20, 36: PRINT "OK"
END



    
This message has been edited by Solitaire1 on Jan 18, 2012 8:11 PM
This message has been edited by Solitaire1 on Jan 18, 2012 7:59 PM

Posted on Jan 17, 2012, 8:52 PM

Respond to this message   

Return to Index


Interesting revision

by Solitaire (Login Solitaire1)
S

I made a slight correction in 3 places where double or triple spaces should have been instead of a single space after it was posted.  It did look a bit off when I ran it -- the eyes were not centered, and the "Move down" didn't cover the previous "s"  I added Alt(255) to those 3 places in my post as well as in yours.

I had never before seen a single NEXT instruction to include the ending of two loops, the way you have it.  Interesting. 

I used variables instead of literals when creating the face.  That made it a lot easier to center and size the box, and place the features correctly.

Glad you liked it.



    
This message has been edited by Solitaire1 on Jan 18, 2012 8:13 PM

Posted on Jan 18, 2012, 8:07 PM

Respond to this message   

Return to Index


*LOL - I get "moves faster than I can". My back went out recently, lasted two weeks.

by (Login qb432l)
R

*

Posted on Jan 17, 2012, 10:44 PM

Respond to this message   

Return to Index


Colors and Patterns -- with link to a subforum for the code

by Solitaire (Login Solitaire1)
S

I posted the program code to the "Big Programs" subforum, even though it's not all that big.  I don't understand how the "Proud" subforum works.  I have 81 "replies" listed under my name, with dozens of programs, all of them using a single url.  How can the individual programs be separated and accessed?

Here is the program I wrote a while back and revised a few days ago.  It has multiple options for changing the foreground color, background color, text color, and non-alphanumeric characters to create hundreds of various patterns.  It displays the values of all the combinations, so a designer can select the pattern combination of choice, and use those values to create a pleasing screen for whatever purpose is needed.  Enjoy!


http://www.network54.com/Forum/190883/message/1326005896/Colors+and+Patterns

 

Posted on Jan 7, 2012, 11:11 PM

Respond to this message   

Return to Index


*Nice work -- lots of fun exploring the myriad combinations.

by (Login qb432l)
R

*



    
This message has been edited by qb432l on Jan 8, 2012 2:01 AM

Posted on Jan 8, 2012, 1:59 AM

Respond to this message   

Return to Index


(edited)

by (Login MCalkins)
Moderator

at:

ELSE 'will use ASCII value of valid input number
w = ASC(sv$) 'new character will assume CHR$ of ASCII value

I think it should be something like:

ELSEIF v > 0 THEN
w = v
ELSE
w = ASC(sv$)

Regards,
Michael



    
This message has been edited by MCalkins on Jan 8, 2012 2:41 PM
This message has been edited by MCalkins on Jan 8, 2012 2:41 PM

Posted on Jan 8, 2012, 2:10 PM

Respond to this message   

Return to Index


Is it really needed?

by Solitaire (Login Solitaire1)
S

That would account for any values I had omitted, but I think all of them were accounted for.  Is there anything that was left out?

Instead, I need to add another condition to the end of the line beginning with

ELSEIF  v = 7

to test for IF v is less than 0

and include it in the nested IF block testing for the correct range.

I made that change in the program listing.

 



    
This message has been edited by Solitaire1 on Jan 8, 2012 4:38 PM

Posted on Jan 8, 2012, 4:35 PM

Respond to this message   

Return to Index


Re: Is it really needed?

by (Login MCalkins)
Moderator

There is no mechanism to set w = v.

So, if I press "c", then type "254", I see "2" instead of "■". Likewise, if I press "c", then type "&hfe", I see "&" instead of "■".

My suggested change was probably not the best or most efficient fix. It was just a small hack that would make the ASCII value entry work.

Regards,
Michael

Posted on Jan 9, 2012, 5:53 PM

Respond to this message   

Return to Index


Solitaire, Would you Consider -

by AlGoreIthm (no login)

Rather than using a numeric system for those characters, use a long string that incorporates all the characters you want to allow and then programming that section accordingly.

This would greatly simplify many of your IF-THEN (ELSE lines because all you need really to check for is re-setting the end of the string back to 1.

One of the advantages of using a long string of characters is that you can actually create the consecutive order that the characters will appear in:

EX: the following are not in ASC order: "!@#*&^$%" , but they would appear in the order you see in the string, so you get to set it up exactly the way you want it to come out.



Posted on Jan 9, 2012, 6:21 PM

Respond to this message   

Return to Index


OK. I fixed it.

by Solitaire (Login Solitaire1)
S

Thanks for the feedback.  My original program used:

ELSE w = v

but with all the extra options I added, it resulted in a solid black background.  I tested it with single characters but didn't anticipate that the ASCII numbers would no longer work.

I added a new string variable - sv1$ - to test for the VAL of the first character. 

If it was 0 and not "0" then I made sv$ = sv1$ 

I added this to the condition that also tested single digits to use the ASCII value of the first character.  Then changed the ELSE to w = v. 

It should be working fine now.

I revised the program code in the subforum to reflect the changes.

============================================================

About the suggestion to use a long string instead of multiple ELSEIFs, that would be very impractical.  First of all, most of those characters are not on the keyboard and it would require a CHR$() with each one of those.  Secondly, with the numbers in code, you can see exactly which values are being skipped.



    
This message has been edited by Solitaire1 on Jan 9, 2012 10:09 PM
This message has been edited by Solitaire1 on Jan 9, 2012 9:53 PM

Posted on Jan 9, 2012, 9:44 PM

Respond to this message   

Return to Index


context menus

by Ben (no login)

what would be a good data structure to store content for sub menus & sub sub sub... menus etc that's unlimited

Posted on Jan 7, 2012, 8:42 PM

Respond to this message   

Return to Index


Re: context menus

by (Login MCalkins)
Moderator

Would you need to add or subtract items at runtime?

well, there's:

http://en.wikipedia.org/wiki/Tree_%28data_structure%29

Whether it's the best or not, I don't know.
You could have an array of strings, perhaps a dynamic one. Each string, perhaps, could start with the MKI$() of the index of the parent, then the MKI$() of the number of children it has, then, for each chile, one MKI$() of the index of the child, then the name of the item.

That should do the job, but there might be better ways of doing it.

If the language has REDIM _PRESERVE, it should be easy to extend it at runtime. You should be able to add items to the end of the array, and update the string of the parent.

If it doesn't need to be extendable at runtime, you might be able to reduce the number of MKI$()s by making rules about the order and relative position of the items. I haven't given a whole lot of thought to it at the moment.

One potential problem is that variable length string space is a very limited resource in QBASIC 1.1. This method might work better in QB64.

One potential workaround, if the items don't need to be extendable, would be to move everything to DATA statements.

Regards,
Michael

Posted on Jan 8, 2012, 1:53 PM

Respond to this message   

Return to Index


Re: context menus

by Ben (no login)

extendable at run time is always good. I do have redim preserve. one thing that i'm most trouble deciding is rather the data text format but how to distinguish sub menus from main menus and so on one i was thinking using like >'s and <'s

menu1>
menu2
menu3
submenu1>
submenu2
submenu3
subsubmenu1>
subsubmenu2<
submenu4<
menu4
menu5<

i dont want to use multidimensional arrays because they are not resizable, and using >'s and <'s is requries string parsing and strring operations are inefficient if there was a way to distgnush andother way or another.

Posted on Jan 8, 2012, 4:21 PM

Respond to this message   

Return to Index


Re: context menus

by (Login MCalkins)
Moderator

you could have 2 arrays, one strings with the names, then another integers with the number of children.

i might respond more later.

regards, michael

Posted on Jan 8, 2012, 9:57 PM

Respond to this message   

Return to Index


Patterns in color - (but need info on the symbol display)

by Solitaire (Login Solitaire1)
S

I revisited an old program I wrote a while back and revised it to add more options and make it work better.  Anyone who is designing a program in text mode can make use of this mulit-faceted display to select just the right combination of colors and patterns for their purpose.

I'd like to post the code here but the forum still has a problem displaying the Less Than symbol.  It looks correct in the preview but not after posting.

I don't have the information on how to correct the display, and I didn't see it in the FAQ, so please post the info here.  Also, it really should be included in the FAQ.

Thanks.

Posted on Jan 5, 2012, 3:07 PM

Respond to this message   

Return to Index


* Doesn't un-checking the Formatted text box help?

by (Login burger2227)
R

Posted on Jan 5, 2012, 3:16 PM

Respond to this message   

Return to Index


I have found, Solitaire...

by (Login qb432l)
R

That if you post code with these symbols, then edit the posted code with the formatted text box unchecked, they will display properly. For example:

These symbols were typed and posted: IF a < b AND c > a THEN

Oops! It posted properly just by unchecking the formatted text box. I didn't have to edit it. Never used to work that way, before.

-Bob



    
This message has been edited by qb432l on Jan 5, 2012 4:00 PM
This message has been edited by qb432l on Jan 5, 2012 3:59 PM

Posted on Jan 5, 2012, 3:58 PM

Respond to this message   

Return to Index


Don't have that box.

by Solitaire (Login Solitaire1)
S

Where IS this "formatted text" box?  I simply don't have it.

All I see is this message at the bottom:

> If "Enable formatted text" box appears above, UNCHECK it if you are posting code.

Well, I don't see any such box anywhere on my screen.

Posted on Jan 5, 2012, 4:27 PM

Respond to this message   

Return to Index


* ODD, what browser?

by (Login burger2227)
R

Posted on Jan 5, 2012, 5:26 PM

Respond to this message   

Return to Index


* IE8

by Solitaire (no login)

Posted on Jan 5, 2012, 5:41 PM

Respond to this message   

Return to Index


*Odd -- I have IE9, but all my previous versions showed the box (???).

by (Login qb432l)
R

*

Posted on Jan 5, 2012, 5:46 PM

Respond to this message   

Return to Index


* ARRGH, you have to log in to get the box!

by (Login burger2227)
R

Posted on Jan 5, 2012, 6:35 PM

Respond to this message   

Return to Index


It doesn't matter whether or not I'm logged in.

by Solitaire (Login Solitaire1)
S

I still don't have that box.  I do have a Message Text with options to change the font, size, and text formatting, but no way to uncheck anything.

So how can I post my code?  It looks good in the preview, but totally convoluted after posting, since I have dozens of those symbols.  All I could do was delete the post.

 

 

Posted on Jan 5, 2012, 10:18 PM

Respond to this message   

Return to Index


Re: It doesn't matter whether or not I'm logged in.

by (Login MCalkins)
Moderator

Here is what I see in IE8 and Firefox 9 when logged in:

http://qbasicmichael.com/downloads/ie8.png
http://qbasicmichael.com/downloads/ff9.png

My first recommendation is to try it in Firefox. Otherwise, I recommend to email it to someone else to post. Otherwise, you'll have to use the HTML entities:

http://w3schools.com/html/html_entities.asp

for <, &#x3c; should work in addition to &lt; and &#60;

Perhaps write a program to automatically replace all the offending characters with the HTML entities, including replacing spaces with the nbsp entity.

Regards,
Michael

Posted on Jan 6, 2012, 1:02 AM

Respond to this message   

Return to Index


Use Chrome! Michael you must always uncheck the box!

by (Login burger2227)
R

I seldom see a link in your posts that is clickable...

wink.gif

Posted on Jan 6, 2012, 8:12 AM

Respond to this message   

Return to Index


I just downloaded Firefox.

by Solitaire (Login Solitaire1)
S

But the forum screen is exactly the same as before.  No formatted text box.

 

Posted on Jan 6, 2012, 1:32 PM

Respond to this message   

Return to Index


That's odd

by (Login MCalkins)
Moderator

especially since all the Firefox settings should be independent from the IE settings. (Unless you chose to import IE's settings.)

You don't have cookies or JavaScript disabled, or anything, do you?

Nevermind, I just tried Firefox with JavaScript disabled, and I still see the checkbox.

I wonder if you're going through some sort of proxy that is changing the web page.

Or perhaps, IE and Firefox are sharing a DLL that helps with the rendering?

Please try to view the page source of the message reply page:

If in Firefox, go to the "Tools" menu, the "Web Developer" sub menu, then choose "Page Source".

It should contain something like:

<input type=checkbox name=htmlpostison value=o checked> Enable formatted text <a href="http://www.network54.com/Help/FormattedText.html" onclick="return largepopupwindowopen('http://network54.com/Help/FormattedText.html')">(Huh?)</a><br>

If not, then you probably have some sort of proxy or filter removing it.

Regards,
Michael

Posted on Jan 6, 2012, 3:36 PM

Respond to this message   

Return to Index


Michael: I don't have that line in Firefox

by Solitaire (no login)

I followed your instructions but didn't see that line in the Page Source.

If it's because of a proxy or filter, how do I disable it?



    
This message has been edited by Solitaire1 on Jan 7, 2012 11:56 AM

Posted on Jan 7, 2012, 11:55 AM

Respond to this message   

Return to Index


Why not just post in in Proud Of Forum and post link here?

by (Login burger2227)
R

I don't recall any problems there and there is no Formatted check box either.

Posted on Jan 7, 2012, 1:56 PM

Respond to this message   

Return to Index


I'm going out on a limb.

by (Login MCalkins)
Moderator

Out of curiosity, do you have the "Also send responses to my email" checkbox?

---------------- For proxy settings:

---- FF

In Firefox, they are under "Tools", "Options", the "Advanced" graphical tab, the "Network" tab, "Connections", the "Settings" button. On mine, it's set to "Use system proxy settings". You might eventually try the "No proxy" option, but first I would look at IE's settings:

---- IE

In Control Panel, select "Internet Options". You can also get there from Internet Explorer by selecting "Tools", "Options."

Once there, go to the "Connections" tab.

If you connect through dial up, find the connection in the list, select it, then click "Settings". See if the checkbox is checked under "Proxy server".

If you connect through normal "wi-fi" or an ethernet port, click "LAN Settings". See if the checkbox is checked under "Proxy server".

----

If you do have proxies enabled, I would try disabling them. I don't know how you connect to the internet. If you're not the one who set up your network, it might be a good idea to talk to the administrator.

----------------

It is possible that some sort of antivirus, spam/privacy filter, toolbar or something is causing this. (I think some antivirus programs do use the proxy settings on your computer.)

Depending on which antivirus you have, you might check its settings to see to what extent it is filtering your web browsing.

It is also possible that your Internet Service Provider is filtering the connection.

Toolbars/extensions:

---- FF

Also, you might go through Firefox's add-ons, looking for anything out of the ordinary. In Firefox, click "Tools", "Add-ons". There will be graphical tabs at the left.

First, look at "Extensions". On mine, the only one I didn't manually add is the .NET framwork one. There are several that I installed manually (Unplug, Flashblock, Mozilla Archive Format).

Also, look at "Plugins". On mine, there are ones from Google, Java, Microsoft (Siverlight, Media player, etc.), and Shockwave Flash.

However, there is nothing antivirus related, and there are no toolbars.

---- IE

You can do the same in Internet Explorer. Under the "Tools" menu, select "Manage Add-ons". Here also, you will have 4 graphical tabs at the left. For example, I have 2 add-ons from Spybot Search & Destroy under "Toolbars and Extensions".

----------------

There are other things, if none of the above works. There is a program called HijackThis.

http://www.trendmicro.com/ftp/products/hijackthis/HijackThis.exe

I would not recommend removing anything with it unless you know what you are doing. However, the log it can produce might be insightful.

It is possible that the problem is caused by malware. There are tools and techniques for detecting and removing malware. Normally, I use CCleaner, ProcessExplorer, Microsoft Security Essentials, Spybot Search & Destroy, and HijackThis. Google the name of anything that you find that looks suspicious. If I suspect problems, then I also use Malwarebytes Anti-Malware. If I suspect a possible rootkit, I use Gmer. I can't really walk you through a detailed malware cleanup here. If you suspect a malware problem, there are forums, for example, Bleepingcomputer, that can walk you through a detailed malware cleanup. Or, if you have a qualified, trustworthy, and affordable computer tech in your area, you might have him/her check out your computer.

Regards,
Michael



    
This message has been edited by MCalkins on Jan 7, 2012 2:24 PM
This message has been edited by MCalkins on Jan 7, 2012 2:22 PM
This message has been edited by MCalkins on Jan 7, 2012 2:20 PM

Posted on Jan 7, 2012, 2:19 PM

Respond to this message   

Return to Index


Partial follow-up info

by Solitaire (Login Solitaire1)
S

I'm on IE. We're using a hi-speed (Verizon) internet connection.  Everything is on a home network my son set up.  I looked up LAN settings, but the Proxy server box is not checked.  It looks like my son installed the Kaspersky Anti-Virus 1012 program.  We used to have AVG but the QB forum page was still the same.

It looks like Kaspersky blocks ActiveX software.  Is this what the text formatting box is made with?

I don't have either of the Options boxes on the QB edit screen checked -- (Also send responses to my email address; Include Signature).

 

Posted on Jan 7, 2012, 4:46 PM

Respond to this message   

Return to Index


Re: Partial follow-up info

by (Login MCalkins)
Moderator

You have the other 2 checkboxes? So you have:

<input type=checkbox name=autorespond value=yes > Also send responses to my email address<br><input type=checkbox name=sigonbox value=o CHECKED> Include Signature

in the source, but not the:

<input type=checkbox name=htmlpostison value=o checked> Enable formatted text <a href="http://www.network54.com/Help/FormattedText.html" onclick="return largepopupwindowopen('http://network54.com/Help/FormattedText.html')">(Huh?)</a><br>

:-P

No, it shouldn't be ActiveX.

Clippy's idea sounds good. There are subforums that don't even give the option of formatted text. The big programs subforum is another,

Regards,
Michael

Posted on Jan 7, 2012, 5:55 PM

Respond to this message   

Return to Index


*ROFL - Type a variable named as "local = 10" in the QB IDE... then press F1 for help.

by Pete (Premier Login iorr5t)
Forum Owner

Posted on Jan 4, 2012, 6:48 PM

Respond to this message   

Return to Index


To add injury to insult...

by (Login qb432l)
R

local = 10
PRINT local

The above code gets an error message (Expected statement). You'd think they'd at least let you use it as a variable name if you can't use it for anything else.

-Bob

Posted on Jan 5, 2012, 3:57 AM

Respond to this message   

Return to Index


* At least it isn't reserved in QB64...yet...

by (Login burger2227)
R

Posted on Jan 5, 2012, 7:46 AM

Respond to this message   

Return to Index


*And never will be. Same with 'SIGNAL'

by Galleon (no login)

Posted on Jan 5, 2012, 1:28 PM

Respond to this message   

Return to Index


Three doors dilemma [corrected]

by (no login)

I'm sorry for my former topic, I forgot I was on a Global Forum.

I have written the code underneath this text, im just a newbie, but I really cant seem to find out, what it is im doing wrong. All the is to it, is that i dont want c to be the same as a OR b
en d not the same as b OR c
My logic tells me this code should suffice but i see a lot of occasions were d is the same as b.

Please help me out here


CLS
' a- car
' b- choice
' c- rejected
' d- alternate proposal
RANDOMIZE TIMER / 3
a = RND
a = INT(a * 3) + 1
INPUT "1/3"; b
fout:
c = RND
c = INT(c * 3) + 1
SELECT CASE c
CASE IS = a OR b
GOTO fout
CASE ELSE
END SELECT
alternatief:
d = RND
d = INT(d * 3) + 1
SELECT CASE d
CASE d = b OR c
GOTO alternatief
CASE ELSE
END SELECT
PRINT "You have chosen"; b; "I would like to tell you it isnt"; c; "would you like to change your choice to"; d; ""
INPUT "ja(1) / nee(2)"; e
SELECT CASE e
CASE IS = 1
IF d = a THEN
PRINT "you won!"
ELSE
PRINT "you lost"
END IF
CASE IS = 2
IF b = a THEN
PRINT "you won"
ELSE
PRINT "your lost"
END IF
END SELECT
END

Posted on Jan 4, 2012, 2:03 PM

Respond to this message   

Return to Index


Don't use OR in SELECT CASE

by (Login burger2227)
R

SELECT CASE c
CASE a, b
CASE ELSE
END SELECT

List possible values with comma separations.

CASE IS can use =, <>, <, >, >= or <=



    
This message has been edited by burger2227 on Jan 4, 2012 3:25 PM
This message has been edited by burger2227 on Jan 4, 2012 3:24 PM

Posted on Jan 4, 2012, 3:23 PM

Respond to this message   

Return to Index


Convoluted code is very hard to understand.

by Solitaire (no login)

Your code makes no sense whatsoever. First of all, get rid of the GOTOs. It makes the code convoluted and impossible to understand. The SELECT CASE block should be self-contained and easy to read. You took an easy block and turned it into something complex.


Why do you have /3 after RANDOMIZE TIMER? That makes no sense.
You should use a range with the correct formula for a random number. For example, to select a number between 1 and 5, you would do this:

a = INT(RND * 5) + 1

What is the user supposed to enter? You don't display any instructions.

If you want something to repeat, use a DO LOOP with a condition to stop repeating.

SELECT CASE does not use logical operators (like OR). A comma is used instead to separate the values. You don't even need to use IS =. For example:


SELECT CASE a
   CASE b, c, d
      PRINT "Incorrect"
   CASE e
      PRINT "Correct"
END SELECT


However, in your program, a SELECT CASE block is not even needed. Maybe this is what you want:


CLS
RANDOMIZE TIMER
a = INT(RND * 5) + 1
DO
   INPUT "Enter a number: ", b
   IF b <> a THEN
      PRINT "Incorrect. Try again."
   END IF
LOOP UNTIL b = a
PRINT "You got it."
END

Posted on Jan 4, 2012, 6:00 PM

Respond to this message   

Return to Index


GOTOs

by Docfxit (no login)

Speaking of GOTO statement, I've noticed you're someone who will do anything to avoid a GOTO statement in any situation, like using 'flags' to break out of nested loops.

I've been required to use a GOTO statement in this one situation where under a certain condition, my program requires going back to the beginning of the main loop:

DO
start:

'important code here
'modifies x

IF x THEN GOTO start

LOOP


Having another outside loop like this:
DO
DO
'main loop
LOOP
LOOP

would not work because there are also other conditions which would require breaking out of the outside loop, and use goto as well.

What would you recommend?

Posted on Jan 4, 2012, 8:32 PM

Respond to this message   

Return to Index


2 loops

by (Login burger2227)
R

DO
DO

LOOP WHILE X

LOOP

OR:

10
DO

IF x THEN 10

LOOP

Posted on Jan 4, 2012, 10:46 PM

Respond to this message   

Return to Index


first one wouldn't work because i have stuff after the IF x and second one uses goto exact

by gayboy (no login)

ly like mine

Posted on Jan 5, 2012, 12:09 AM

Respond to this message   

Return to Index


* IF doesn't need GOTO for line numbers

by (Login burger2227)
R

Posted on Jan 5, 2012, 9:22 AM

Respond to this message   

Return to Index


No GOTO

by Solitaire (Login Solitaire1)
S

Anything is possible without needing to resort to using  a GOTO statement.  Several programming languages exist which do not have this keyword at all.

Instead of branching off to another part of the program, use subprocedures which can be coded once and called several times from any part of the main program.  This makes your code a lot easier to read and debug.

Post your code for more suggestions.



    
This message has been edited by Solitaire1 on Jan 5, 2012 9:16 AM

Posted on Jan 5, 2012, 9:13 AM

Respond to this message   

Return to Index


* Luckily I have Windows, so I don't need three doors. :)

by Pete (Premier Login iorr5t)
Forum Owner

Posted on Jan 4, 2012, 6:50 PM

Respond to this message   

Return to Index


3 deuren dillema, please cheack

by Martijn Kruizinga (no login)

ik heb onderstaande code, het mag op zich voor zichzelf spreken ik wil een simulatie doen van het 3 deuren dillema. Maar wat gaat er mis?

Het idee hiervan is dat c niet hetzelfde mag zijn als a of b
d mag niet hetzelfde zijn als b of c HELP!!!


CLS
' a- auto
' b- keuze
' c- uitgesloten
' d- alternatief voorstel
RANDOMIZE TIMER / 3
a = RND
a = INT(a * 3) + 1
INPUT "1/3"; b
fout:
c = RND
c = INT(c * 3) + 1
SELECT CASE c
CASE IS = a OR b
GOTO fout
CASE ELSE
END SELECT
alternatief:
d = RND
d = INT(d * 3) + 1
SELECT CASE d
CASE d = b OR c
GOTO alternatief
CASE ELSE
END SELECT
PRINT " je hebt gekozen voor"; b; "ik wil je vast vertellen dat het "; c; " niet is, wil je kiezen voor"; d; ""
INPUT "ja(1) / nee(2)"; e
SELECT CASE e
CASE IS = 1
IF d = a THEN
PRINT "je hebt gewonnen!"
ELSE
PRINT "je hebt verloren"
END IF
CASE IS = 2
IF b = a THEN
PRINT "je hebt gewonnen!"
ELSE
PRINT "je hebt verloren"
END IF
END SELECT
END

Posted on Jan 4, 2012, 1:57 PM

Respond to this message   

Return to Index


A WIKI job for Clippy

by Galleon (no login)

The new QB64 help system works great with almost all the WIKI pages. The problem is they are too verbose. The main WIKI page is not what people need to see when they open help in the IDE. To give you an idea only about 10 lines are visible (without scrolling) so we need to make the content that is displayed concise. Maybe you would like to put together a help "home page" for the IDE to use as its default?

Posted on Jan 4, 2012, 4:17 AM

Respond to this message   

Return to Index


Why are you asking here?

by (Login burger2227)
R

I am always on your site daily. What do you want the opening page to include? I can link to the Alphabetical and By Usage pages with the Main Page appendix and QB64 links too. Every section of the main page is a link in itself so they don't all need to be displayed all at once.

To see what I mean, go to the Main Page and click the Edit areas. The new link will be in the url after it has been saved. You don't need to change anything:

http://qb64.net/wiki/index.php?title=Main_Page#Keywords:

I can make a page that has some of the links if you want that. It can be made so that only the Help Menu can see it.

Here is a page I just created. If you want, add things that you feel are needed. I will find the links for them.

http://qb64.net/wiki/index.php?title=QB64_Help_Menu



    
This message has been edited by burger2227 on Jan 4, 2012 5:40 PM
This message has been edited by burger2227 on Jan 4, 2012 1:14 PM

Posted on Jan 4, 2012, 1:11 PM

Respond to this message   

Return to Index


*I'll follow this up in the QB64 discussion forum (link*)

by Galleon (no login)

http://www.qb64.net/forum/index.php?topic=5122.0

Posted on Jan 4, 2012, 10:58 PM

Respond to this message   

Return to Index


qb64 is too slow

by (no login)

I worked in QB 4.5 and PDS 7 and have some programs. Now I find qb64 and try to run my programs in it. It previously creat exe-file and work very slowly. Is there some way to do this more quickly? Sorry for my english. Sergey

Posted on Jan 4, 2012, 12:38 AM

Respond to this message   

Return to Index


*How big are the .BAS files you are working with?

by Galleon (no login)

Posted on Jan 4, 2012, 4:10 AM

Respond to this message   

Return to Index


qb64 is slowly than qb45

by (no login)

Not so big - 5 -20 kb only. But time difference between qb45 and qb64 is significant.
I think that the reason of this is creation of exe-file.

And some more: Runing my programs I find, that qb64 do not know user defined functions:

Command not implemented on line 47
DEF fnacs (x) = 1.571 - ATN(x / SQR(1 - x * x))

Thank you for your cortesy!
Sergey

Posted on Jan 4, 2012, 7:24 AM

Respond to this message   

Return to Index


QB64 takes time to compile the programs into EXE programs

by (Login burger2227)
R

Qbasic had an interpreter that could run your code instantly.

If you can still run Qbasic, use it to create your code and save the BAS files as Text readable when saved. Once you are happy with the results, compile it.

The compiler changes your code to C++ code and compiles it.

Several people have worked on an interpreter, but no luck yet.



    
This message has been edited by burger2227 on Jan 4, 2012 1:03 PM

Posted on Jan 4, 2012, 12:25 PM

Respond to this message   

Return to Index


SELECT EVERY CASE

by Herman Cain (Premier Login iorr5t)
Forum Owner

A poll at QB64 asks if a SELECT EVERY CASE would be a good keyword. I'm all for it. For instance, if I wanted a pepperoni pizza with extra cheese and mushrooms, I could order a 2,4,6

CLS

PRINT "Godfather's Pizza Menu."
PRINT "1) Salami";
PRINT "2) Extra Cheese";
PRINT "3) Pineapple";
PRINT "4) Pepperoni";
PRINT "5) Onions";
PRINT "6) Mushrooms";
PRINT "7) Green Peppers";

LINE INPUT "WHAT 'S YOU WANT ON YO DAMN PIZZA?", pizza$

SELECT EVERY CASE pizza$
CASE 1: PRINT "Salami ";
CASE 2: PRINT "Extra Cheese ";
CASE 3: PRINT "Pineapple ";
CASE 4: PRINT "Pepperoni ";
CASE 5: PRINT "Onions ";
CASE 6: PRINT "Mushrooms ";
CASE 7: PRINT "Green Peppers ";
END SELECT

PRINT "I want " + pizza$

REM I am Herman Cain, and I approved this code.

 

Posted on Jan 2, 2012, 8:04 PM

Respond to this message   

Return to Index


* Dammit Herman. 9-9-9 means Nein! Nein! Nein!

by Female German Godfather's Pizza Worker. (Premier Login iorr5t)
Forum Owner

Posted on Jan 2, 2012, 8:06 PM

Respond to this message   

Return to Index


* Try it with SELECT EVERY WOMAN Herman

by Mitt (Login burger2227)
R

Posted on Jan 2, 2012, 8:13 PM

Respond to this message   

Return to Index


EXIT SELECT would be rather useful

by Ben (no login)

Posted on Jan 2, 2012, 8:33 PM

Respond to this message   

Return to Index


Problem there is...

by (Login qb432l)
R

...(besides the fact that I can't get olives on my pizza) you have to depend on the user to enter a string with the proper format. I'm in favor of it in principal, but idiot-proof it ain't. What would happen, for example, if someone were to take a very long, confused pause right in the middle of their order?

-Bob


Posted on Jan 2, 2012, 10:00 PM

Respond to this message   

Return to Index


NO problem, just tell me what you want and I'll say it!...

by Mitt (Login burger2227)
R

Funny how Pete always tends to think about pizza isn't it...

Posted on Jan 2, 2012, 10:08 PM

Respond to this message   

Return to Index


Hey Bob, I'm sorry you can't get olives on your pizza but...

by Popeye the Coderman (Premier Login iorr5t)
Forum Owner

I'm glad Bluto can't get Olive's on his sausage!

 

Posted on Jan 2, 2012, 10:58 PM

Respond to this message   

Return to Index


* But I will gladly pay you Thursday for a hamburger today!

by (Login burger2227)
R

Posted on Jan 3, 2012, 6:45 AM

Respond to this message   

Return to Index


Actually that code wouldn't work!

by Galleon (no login)

If you entered the string "2,4,6" nothing would happen according to current case condition rules.

Posted on Jan 3, 2012, 3:09 AM

Respond to this message   

Return to Index


Galleon did you see the post about EXIT SELECT?

by (Login burger2227)
R

That might be a good idea too...

Posted on Jan 3, 2012, 6:48 AM

Respond to this message   

Return to Index


Message to Mr. Obama on this Jan 1st., 2012...

by G.O.P. (Premier Login iorr5t)
Forum Owner

PRINT "HAPPY NEWT YEAR!"
'---------------------------------
SYSTEM

'And get your 2013 Mayan calendars before time runs out. Buy yours now on ebay!

'happy.gif

 

 

Posted on Jan 1, 2012, 7:55 PM

Respond to this message   

Return to Index


* Hmmm...I shooda knowed when I saw Iorr logged on...Pete :-P

by (Login burger2227)
R

Posted on Jan 1, 2012, 8:10 PM

Respond to this message   

Return to Index


QBASIC DIVISION RESULT QUESTION.

by (no login)

LET DAY.INT.EXPENSE! = YEAR.INT.EXPENSE! / 365%
YEAR.INT.EXPENSE! IS ' 28 '
DAY.INT.EXPENSE! IS ' 7.671233E-02 ' <=== INCORRECT
DAY.INT.EXPENSE! SHOULD BE SOMETHING LIKE ' .07671233 '

IF THE CALCULATED ANNAUAL INTEREST EXPENSE IS $28, THEN THE DAILY INTEREST EXPENSE SHOULD BE $.0767 N O T $7.67. WHY IS THE RESULT ' 7.671233E-02 ' ?????

LET DAY.INT.EXPENSE! = YEAR.INT.EXPENSE! / 365%
YEAR.INT.EXPENSE! IS ' 42 '
DAY.INT.EXPENSE! IS ' .1150685 ' <=== CORRECT

THE ABOVE RESULTS ARE CALCULATED FROM THE SAME (EXACT)ROUTINE.

Posted on Jan 1, 2012, 11:09 AM

Respond to this message   

Return to Index


The numbers are expressed in scientific notation

by (Login burger2227)
R

7.671233E-02 is actually the value .07671233

E-02 means that the decimal point is moved two places to the left.

If you want to display a notated number to a user use PRINT USING with one less decimal point place in the format template:

PRINT USING "###.######"; DAY.INT.EXPENSE!

The notated value will still calculate correctly.

Posted on Jan 1, 2012, 12:01 PM

Respond to this message   

Return to Index


QBASIC DIVISION PROBLEM.

by (no login)

Hi Clippy,
I'll try to be as brief and concise as possible. I attempted to enter the acutal code from my .BAS file (program) but there was no space left in this 'Message Text' area to write any comments. I'll try to fit part of it. Here goes:

000502 LET YEAR.INT.EXPENSE! = MONEY.NEEDED.KEY1! * INTEREST.RATE.KEY1!
000503 LET MONTH.INT.EXPENSE! = YEAR.INT.EXPENSE! / 012%
000504 LET WEEK.INT.EXPENSE! = YEAR.INT.EXPENSE! / 052%
000505 LET DAY.INT.EXPENSE! = YEAR.INT.EXPENSE! / 365%

THE CONTENTS OF THE VARIABLES ARE LISTED BELOW.
MONEY.NEEDED.KEY1! INTEREST.RATE.KEY1! DAY.INT.EXPENSE!
1400 .02 7.671233E-02
1400 .03 .1150685

My instincts tell me that either BOTH results should contain 'E-02' O R NEITHER SHOULD.
Please be as specific and technical, if necessary, in answering the following questions.
Q01. Specifically, why DOES the first result above CONTAIN 'E-02' ???
Q02. Specifically, why DOES the second result above NOT CONTAIN 'E-02' ???

Thanks again for your time and expertise. Regards, Vince G.

Posted on Jan 1, 2012, 3:26 PM

Respond to this message   

Return to Index


Some numerical values do not need to be as accurate as others

by (Login burger2227)
R

When a SINGLE value requires more than 7 digits the value adds the E+ or E- to indicate the decimal point placement.

DOUBLE values can use up to 15 decimal places before using D+ or D-.

Posted on Jan 1, 2012, 4:56 PM

Respond to this message   

Return to Index


In other words....

by Solitaire (no login)

The result of the first equation came out to no more than 7 digits after the decimal so it could display as is. The result of the second equation was more than 7 digits so it reverted to scientific notation.

If you were to declare your variables as type DOUBLE (using # instead of !) the first result should still be the same, but the second may or may not display in scientific notation depending on whether or not the number of digits after the decimal was more or less than (or equal to) 15.

Posted on Jan 1, 2012, 10:08 PM

Respond to this message   

Return to Index


Type SINGLE is limited to 7 places after the decimal point.

by Solitaire (no login)

Using the ! suffix declares your variable as type SINGLE. After 7 places, the result will revert to scientific notation. The same is true for type DOUBLE, which is limited to 15 places and will still result in scientific notation if the result is longer than that.

In order to display the maximum amount allowed within the limits of the type memory, you can force the result to round up to the nearest value with 7 places for type SINGLE, as follows:

YEAREXPENSE = 28
DAYEXPENSE = YEAREXPENSE / 365
DAYEXPENSE = DAYEXPENSE * (10 ^ 7)
DAYEXPENSE = INT(DAYEXPENSE + .5)
DAYEXPENSE = DAYEXPENSE / (10 ^ 7)
PRINT DAYEXPENSE

To display the result with fewer places, just substitute a smaller value for the 7.

If you use PRINT USING as recommended by Clippy above, it will display the result with the number of places indicated, although internally, the longer value will still be in memory.

To keep the original value of DAYEXPENSE in memory, you may wish to substitute a different variable temporarily and display that value after it computes the rounded result. Example:

YEAREXPENSE = 28
DAYEXPENSE = YEAREXPENSE / 365
num = DAYEXPENSE
num = num * (10 ^ 7)
num = INT(num + .5)
num = num / (10 ^ 7)
PRINT num
PRINT "Original value: "; DAYEXPENSE

Posted on Jan 1, 2012, 3:10 PM

Respond to this message   

Return to Index


QBASIC DIVISION RESULT CONTAINING 'E-02''.

by (no login)

Hi Solitare,
First I want to appologize for not responding sooner. Your response was nothing less
than 'TOP NOTCH'. It was CLEAR, CONCISE, PRECISE and UNDERSTANDABLE. For me, it was one
of the best, if not the best response I have received in regards to a question I posed.
Thanks again. Regards, Vince G.

Posted on Jan 8, 2012, 1:59 PM

Respond to this message   

Return to Index


Program QBasic as 32 bit code

by Rufus (no login)

http://www.rtrussell.co.uk/

You can run many QBasic programs as 32 bit code and with a bit more effort write new QBasic programs and run them as 32 bit code.

Go to the above website and download the QBasic to BBC Basic converter. Follow the instructions for the simple installation. On Vista I found it necessary to put the small download in a separate directory on the C drive before running it.

When the program is run two windows open. Load your old code into the left hand window and convert it to BBC Basic which appears in the right hand window. You can now run your code.

For test purposes you can write new QBasic programs using the left hand window as a simple editor. There are no facilities for saving new programs but you can do a copy and paste operation into Notepad. Save your program with the *.bas extension so that it will load when required

Better still download Notepad++ and customise it to understand QBasic keywords. You will now have a nice system allowing you to write new QBasic programs with nicely highlighted and indented source code for easy readability. You can use lower case if like me you prefer it.

There are some bits of QBasic which are not translated as you will see if you read the documentation. I don't find this a problem.

If you find this system useful then you might like to let Mr Russell know. Some day he might be willing to spend some time and effort in enhancing it. I would especially like to see some higher screen numbers for even better graphics.

Posted on Jan 1, 2012, 9:40 AM

Respond to this message   

Return to Index


QB64 can run on 64 bit Windows, Mac OSX and Linus...

by (Login burger2227)
R

It also has an IDE that can create programs.

Posted on Jan 1, 2012, 10:32 AM

Respond to this message   

Return to Index


HAPPY NEW YEAR!

by Pete (Premier Login iorr5t)
Forum Owner

Well nearly, only a little past 8:45 West Coast time. Will 2012 be the year of qbasic? It may be poised for a comeback! Well, one can dream, and thanks to dreams, we have QB64.

Anyway, it's good to see the mods taking such good care of the forum, and I hope this posts puts the "A" in Rob's Q and A, "Where's Pete?"

Best wishes in 2012 to all the forum regulars and newbies,

Pete

 

 

 

Posted on Dec 31, 2011, 8:48 PM

Respond to this message   

Return to Index


*Howdy, Pete.

by (Login MCalkins)
Moderator

Regards,
Michael



    
This message has been edited by MCalkins on Jan 1, 2012 4:13 PM

Posted on Dec 31, 2011, 10:04 PM

Respond to this message   

Return to Index


*Hi, Pete - Happy New Year to you too!

by (Login qb432l)
R

*

Posted on Jan 1, 2012, 1:06 AM

Respond to this message   

Return to Index


How is basketball going?

by (Login burger2227)
R

My brother is a coach for the Southern High school junior varsity girls team at Deep Creek Maryland. He spends a ton of time working with them! Hope your team does well!

Ted

Posted on Jan 1, 2012, 1:07 AM

Respond to this message   

Return to Index


Happy New Year to all! Revisited Times Square program:

by Solitaire (no login)

DECLARE SUB Ball (x AS INTEGER, y AS INTEGER, w AS INTEGER, tint() AS INTEGER)
DECLARE SUB Pole ()
DIM x AS INTEGER, y AS INTEGER, w AS INTEGER, T AS SINGLE
DIM yr AS INTEGER, mo AS INTEGER, cheer AS INTEGER
DIM year AS STRING, month AS STRING, msg AS STRING, E AS STRING
DIM tint(0 TO 20) AS INTEGER
DIM song(1 TO 5) AS STRING

RANDOMIZE TIMER
year$ = RIGHT$(DATE$, 4)
month$ = LEFT$(DATE$, 2)
yr = VAL(year$)
mo = VAL(month$)
IF mo >= 9 THEN yr = yr + 1
year$ = LTRIM$(RTRIM$(STR$(yr)))
year$ = SPACE$(4) + year$ + SPACE$(7)       'center interchange with message
msg$ = "HAPPY NEW YEAR!"
song$(1) = "p8mbmlO2T220"                   'song - Auld Lang Syne
song$(2) = "ccfffeffaagggfgg"
song$(3) = "agffffaa>ccddddd"
song$(4) = "p8ddccc<aaaffgggfgg"
song$(5) = "agfffdddccfffff"
CLS
LOCATE 6, 22: PRINT "TIMES SQUARE ON NEW YEAR'S EVE"
PRINT TAB(22); STRING$(30, "_")

PRINT : PRINT , , "by Solitaire"
LOCATE 19, 20: PRINT "Press Alt-Enter for a full screen."
PRINT TAB(15); "Program will not work properly in a window."
LOCATE 24, 24: PRINT "Press any key to begin...";
E$ = INPUT$(1)

CLS
FOR x = 0 TO 20             'changing colors of ball as it drops
    READ tint(x)            'assigned to array
NEXT x
CALL Pole
x = 2
y = 10
w = 1
CALL Ball(x, y, w, tint())
w = 0
COLOR 7, 0
LOCATE 25, 1: PRINT "Press any key to begin countdown ";
PRINT TAB(50); "Press Esc to stop";
E$ = INPUT$(1)
IF E$ = CHR$(27) THEN CLS : SYSTEM
LOCATE 25, 1: PRINT SPACE$(70);
s = 260
COLOR 8
LOCATE 10, 12: PRINT "Goodbye..."
LOCATE 10, 58: PRINT yr - 1

FOR x = 1 TO 20
    ex$ = INKEY$
    IF ex$ = CHR$(27) THEN  'Esc places ball on bottom
        CLS
        CALL Pole
        CALL Ball(20, 0, 0, tint())
        COLOR 7, 0: : EXIT FOR
    END IF
    SOUND s, 10             'sound heard while ball is dropping
    s = s + 9
    IF x MOD 2 = 0 THEN     'countdown from 10 to 1
        y = y - 1
    END IF
    CALL Ball(x, y, w, tint())
    T = TIMER
    DO WHILE T + .5 >= TIMER AND T + .5 <= 86400: LOOP
NEXT x

IF ex$ <> CHR$(27) THEN
    COLOR 30, 0
    LOCATE 10, 10
    PRINT msg$
    LOCATE 10, 55
    PRINT year$
    PLAY "P2"
    FOR i = 1 TO 5                      'song - Auld Lang Syne
        PLAY song$(i)
        ex$ = INKEY$
        IF ex$ = CHR$(27) THEN COLOR 7, 0: EXIT FOR
    NEXT i
    c = 16
END IF

IF ex$ <> CHR$(27) THEN cheer = 120
FOR blink = 1 TO cheer              'will not execute if Esc was pressed
    ex$ = INKEY$
    IF ex$ = CHR$(27) THEN COLOR 7, 0: EXIT FOR
    c = c + 1
    IF c = 32 THEN c = 17
    COLOR c, 0
    IF blink > 110 THEN COLOR 30    'messages blink and switch places
    IF blink = 120 THEN COLOR 14
    SELECT CASE blink
        CASE 1 TO 16, 33 TO 48, 65 TO 80, IS > 97
            LOCATE 10, 10
            PRINT msg$
            LOCATE 10, 55
            PRINT year$
        CASE ELSE
            LOCATE 10, 10
            PRINT year$
            LOCATE 10, 55
            PRINT msg$
    END SELECT
    DO
        row = INT(21 * RND) + 2         'confetti fills the sky
        col = INT(75 * RND) + 3         'does not cover ball or pole
    LOOP WHILE row > 17 AND col > 34 AND col < 46 OR col = 40
    tint = INT(15 * RND) + 1
    confetti$ = CHR$(INT(6 * RND) + 1)
    LOCATE row, col
    COLOR tint, 0
    IF blink > 105 THEN
        confetti$ = "*"             'last confetti stars remain blinking
        COLOR tint + 16, 0
    END IF
    PRINT confetti$
    T = TIMER
    DO WHILE T + .15 >= TIMER AND T + .15 <= 86400: LOOP
NEXT blink
COLOR 30                            'blinking yellow
LOCATE 10, 55: PRINT year$          'covers any random confetti
LOCATE 10, 10: PRINT msg$
IF ex$ = CHR$(27) THEN CLEAR        'stop song if Esc was pressed
COLOR 7, 0
LOCATE 25, 3: PRINT "Press any key to end...";
LOCATE 25, 55: PRINT "By Solitaire";
E$ = INPUT$(1)
CLS
DATA 3,3,2,2,3,3,5,5,3,3,2,2,3,3,5,5,3,3,2,2,3,3,3
SYSTEM

SUB Ball (x AS INTEGER, y AS INTEGER, w AS INTEGER, tint() AS INTEGER)
STATIC T AS INTEGER
IF x > 2 THEN               'clear top of ball
    LOCATE x - 1, 38
    PRINT SPACE$(5)         'space prints background color
END IF
LOCATE x, 36: PRINT " "
LOCATE x, 44: PRINT " "
LOCATE x, 37: PRINT SPACE$(7)
COLOR 6
IF x > 2 THEN               'redraw pole on top
    LOCATE x - 1, 40
    PRINT CHR$(186)
END IF
COLOR tint(T)             'redraw descending ball with changing color
IF x > 1 THEN
    LOCATE x, 38
    PRINT CHR$(220); STRING$(3, CHR$(219)); CHR$(220)
END IF
FOR z = 1 TO 2
    IF x = 1 THEN
        LOCATE x + z, 39
        PRINT STRING$(3, CHR$(219))
    ELSE
        LOCATE x + z, 36
        IF z = 1 THEN
            PRINT CHR$(220); STRING$(7, CHR$(219)); CHR$(220)
        ELSE
            PRINT CHR$(223); STRING$(7, CHR$(219)); CHR$(223)
        END IF
    END IF
NEXT z
LOCATE x + 3, 38
IF x > 1 THEN PRINT CHR$(223); STRING$(3, CHR$(219)); CHR$(223)
IF y = 10 THEN
    IF w = 1 THEN
        LOCATE 3, 38
    ELSE
        LOCATE x + 2, 38
    END IF
ELSE
    LOCATE x + 1, 39
END IF
COLOR 0, tint(T)         'background color of countdown number
PRINT y;                 'countdown number
COLOR 7, 0
LOCATE 1, 32
PRINT "TIMES SQUARE BALL"
IF x = 20 THEN
    LOCATE 21, 40
    COLOR 30, tint(T)
    PRINT CHR$(1)                       'happy face replaces countdown number
    LOCATE 22, 40
    PRINT "*"
END IF
T = T + 1               'static counter
END SUB

SUB Pole
COLOR 6     'color of pole
FOR x = 2 TO 24
    LOCATE x, 40
    PRINT CHR$(186)
NEXT x
LOCATE 24
PRINT TAB(37); CHR$(201); STRING$(2, CHR$(205)); CHR$(202); STRING$(2, CHR$(205)); CHR$(187);
END SUB

Posted on Jan 1, 2012, 3:25 PM

Respond to this message   

Return to Index


*Thank-you Solitaire! Now I can officially begin 2012. All the best for the new year!

by (Login qb432l)
R

*

Posted on Jan 2, 2012, 12:22 AM

Respond to this message   

Return to Index


* Thanks, Bob. All the best to you!

by Solitaire (no login)

Posted on Jan 2, 2012, 10:44 AM

Respond to this message   

Return to Index


*HAPPY NEW YEAR TO EVERYBUDDY*

by OPRESION (no login)

*******************

Posted on Jan 1, 2012, 8:29 PM

Respond to this message   

Return to Index