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



Scan codes ?

by Lisztfr (no login)

Is it possible to print the keyboard's scan codes, with Qbasic or any other mean ? i have Dobox... on C1000. Qbasic is running. I need the scan codes for setting up Xkeyb.

FR.KEY

50 , ? #0 #0 #0
51 ; . #0 #0 <
52 : / #0 #0 >
53 #33 õ #0 #0 #0
86 < > #0 #0 #0

[SHIFTS]
54 42 29 56 70 69 58 82

SHIT1-SHIFT2-CTRL-ALT

You can see that ALT is here bind to key 56, which i don't have.

Example, if i replace 56 with 52, the "/" key will be Alt.

Or if i replace one of the SHifts with 56 they will be Alt....

The scan code for "/" is 52, the first number from the line.

I need a way to get all these codes from my Zaurus Keyboard...

thanks, l





Posted on Oct 1, 2010, 1:34 AM

Respond to this message   

Return to Index


INP(&H60)

by (Login burger2227)
R

DO
code = INP(96)
IF code <> pcode THEN LOCATE 10, 10: PRINT code; " "
K$ = INKEY$ 'clear kb buffer
pcode = code
LOOP UNTIL K$ = CHR$(27)

Posted on Oct 1, 2010, 2:02 AM

Respond to this message   

Return to Index


OK

by Lisztfr (no login)

But it crashs the Dosbox :)

It was exactly what i meant ...

Posted on Oct 1, 2010, 3:19 AM

Respond to this message   

Return to Index


Why you using DOSBOX, LOL? Use QB64

by (Login burger2227)
R

QB64 can run that code! You should not need DOSBOX. Galleon is gonna update QB64 soon so that foreign computers should not have keyboard problems anymore.

Only Ben still uses that stuff!

Posted on Oct 1, 2010, 12:44 PM

Respond to this message   

Return to Index


Zaurus C1000

by Lisztfr (no login)

I'm trying to test a few Qbasic programs on this Sharp PDA, which runs linux. Also, not a single person on the world thought about putting the scan codes on the web... And, my ROM (Cacko) can't run Showkeys, nor Keydump. So i'm tipping in the dark guessing for scan codes, trying to do my best with xkeyb. But i'm relying now of someone give me the codes :)

The reason is that Dosbox... gosh, all this stuff is more or less abandon ware and obsolete hardware : Dosbox cannot map correctly the keys. Mapper.txt is ignored, imho, on 0.63.

Posted on Oct 1, 2010, 3:21 PM

Respond to this message   

Return to Index


*Can't you find the codes on your PC?

by (Login Mikrondel)
Moderator

Posted on Oct 1, 2010, 4:15 PM

Respond to this message   

Return to Index


HERE, I hope you can use bitmaps

by (Login burger2227)
R

[linked image]

These codes are from my demonstrator.

Download here:http://dl.dropbox.com/u/8440706/Q-Basics.zip

This bitmap is in the download.

Ted

Posted on Oct 1, 2010, 5:06 PM

Respond to this message   

Return to Index


* That's purddy! :)

by (Login The-Universe)
Admin

Posted on Oct 1, 2010, 6:57 PM

Respond to this message   

Return to Index


* It's purddy because it is in SCREEN 12

by (Login burger2227)
R

Posted on Oct 1, 2010, 9:20 PM

Respond to this message   

Return to Index


Very nice :-)

by Lisztfr (no login)

http://upload.wikimedia.org/wikipedia/commons/e/e8/Sharp_Zaurus_SL-C1000_--_open_1280x960.jpg

BTW there is a much more difficult fractal to program...

http://fractalenlightenment.com/wp/wp-content/uploads/image-import/_Z8mwJp4iSOo/RxT5JjRtcdI/AAAAAAAADnI/le_YlI6PCHo/s400/Koch%2BSnowflake.JPG

The previous i posted where only with shifting and /, *, +...

Posted on Oct 2, 2010, 12:43 AM

Respond to this message   

Return to Index


Can you use PEEK? You can read the CAPS, SHIFT, ALT, CTRL NUM LOCK etc.

by (Login burger2227)
R

DEF SEG = 0
DO
port = PEEK(1047)
IF port > 0 THEN LOCATE 26, 19: COLOR 11: PRINT "Turn ALL Locks off to see each key's bit value!"
COLOR 14: LOCATE 8, 23: PRINT "PEEK(1047) ="; port; "'save initial value to reset later! "
LOCATE 9, 45
IF (port AND 4) = 4 THEN COLOR 10: PRINT "CTRL KEY PRESSED " ELSE COLOR 12: PRINT "CTRL KEY RELEASED"
LOCATE 10, 45
IF (port AND 8) = 8 THEN COLOR 10: PRINT "ALT KEY PRESSED " ELSE COLOR 12: PRINT "ALT KEY RELEASED"
LOCATE 13, 45
IF (port AND 16) = 16 THEN COLOR 10: PRINT "SCROLL LOCK ON " ELSE COLOR 12: PRINT "SCROLL LOCK OFF"
LOCATE 17, 45
IF (port AND 32) = 32 THEN COLOR 10: PRINT "NUMBER LOCK ON " ELSE COLOR 12: PRINT "NUMBER LOCK OFF"
LOCATE 21, 45
IF (port AND 64) = 64 THEN COLOR 10: PRINT "CAPS LOCK ON " ELSE COLOR 12: PRINT "CAPS LOCK OFF"
LOCATE 25, 45
IF (port AND 128) = 128 THEN COLOR 10: PRINT "INSERT MODE ON " ELSE COLOR 12: PRINT "INSERT MODE OFF"
Align 11, 29, "Press mode keys to change or ESC to quit!"
LOOP UNTIL INKEY$ = CHR$(27) 'escape key exit
DEF SEG

Posted on Oct 2, 2010, 7:41 AM

Respond to this message   

Return to Index


*Align ? (syntax error)

by Lisztfr (no login)

*

Posted on Oct 2, 2010, 9:09 AM

Respond to this message   

Return to Index


i think thats clippys stupid text center routine

by Anonymous (no login)

Posted on Oct 2, 2010, 9:16 AM

Respond to this message   

Return to Index


STUPID people post anonymously cause they have no guts!

by (Login burger2227)
R

SUB Align (Tclr, Trow, txt$)
Tcol = 41 - (LEN(txt$) \ 2)
COLOR Tclr: LOCATE Trow, Tcol: PRINT txt$;
END SUB

Don't mind the ASS, if I ran this forum, he would be long gone. He contributes nothing here and is an imbecile derelict.

Posted on Oct 2, 2010, 9:47 AM

Respond to this message   

Return to Index


This is working !

by Lisztfr (no login)

Thanks Clippy, this works, at least, since on the Zaurus for the moment i didn't map Alt, nor Scroll, and Insert, or num...

It shows me Ctrl, and Shift (shift prints 0E 52)

Mapped in xkeyb to :

[SHIFTS]
54 42 29 56 70 69 58 82

54 or 42 (scan codes)...

'Just completed SCREEN 12.

Any chance to see scan codes ?


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


DECLARE SUB Align (Tclr, Trow, txt$)

SCREEN 12


DEF SEG = 0
DO
port = PEEK(1047)
IF port > 0 THEN LOCATE 26, 19: COLOR 11: PRINT "Turn ALL Locks off to see each key's bit value!"
COLOR 14: LOCATE 8, 23: PRINT "PEEK(1047) ="; port; "'save initial value to reset later! "
LOCATE 9, 45
IF (port AND 4) = 4 THEN COLOR 10: PRINT "CTRL KEY PRESSED " ELSE COLOR 12: PRINT "CTRL KEY RELEASED"
LOCATE 10, 45
IF (port AND 8) = 8 THEN COLOR 10: PRINT "ALT KEY PRESSED " ELSE COLOR 12: PRINT "ALT KEY RELEASED"
LOCATE 13, 45
IF (port AND 16) = 16 THEN COLOR 10: PRINT "SCROLL LOCK ON " ELSE COLOR 12: PRINT "SCROLL LOCK OFF"
LOCATE 17, 45
IF (port AND 32) = 32 THEN COLOR 10: PRINT "NUMBER LOCK ON " ELSE COLOR 12: PRINT "NUMBER LOCK OFF"
LOCATE 21, 45
IF (port AND 64) = 64 THEN COLOR 10: PRINT "CAPS LOCK ON " ELSE COLOR 12: PRINT "CAPS LOCK OFF"
LOCATE 25, 45
IF (port AND 128) = 128 THEN COLOR 10: PRINT "INSERT MODE ON " ELSE COLOR 12: PRINT "INSERT MODE OFF"
Align 11, 29, "Press mode keys to change or ESC to quit!"
LOOP UNTIL INKEY$ = CHR$(27) 'escape key exit
DEF SEG

END

SUB Align (Tclr, Trow, txt$)
Tcol = 41 - (LEN(txt$) \ 2)
COLOR Tclr: LOCATE Trow, Tcol: PRINT txt$;
END SUB

Posted on Oct 2, 2010, 11:49 AM

Respond to this message   

Return to Index


Looks like you want to run a forum, can I help?

by (Login The-Universe)
Admin


If you could manage to tone down the rhetoric, and come up with more constructive ways to deal with problem posters, sure, you probably could get mod privilages.

In the future, please consider that. I don't want to bother flagging posts, that experiment didn't go well when Mac tried it, and I fully get why. My take on this is there isn't enough wood left around here to bother starting a flame war, anyway.

Pete

Posted on Oct 2, 2010, 2:47 PM

Respond to this message   

Return to Index


* I considered that, but I didn't want you to be overwhelmed with posts from Phylo. :-)

by (Login burger2227)
R

Posted on Oct 2, 2010, 5:04 PM

Respond to this message   

Return to Index


Just checking...

by (no login)

Just checking to see if anything new has come up....

Posted on Oct 6, 2010, 8:07 PM

Respond to this message   

Return to Index


Are you under the impression that I've posted recently?

by (Login PhyloGenesis)
Moderator

The last time I posted was before school started, over two months ago, in this thread: http://www.network54.com/Forum/648955/message/1280445220/What+if

Just in case you thought I'd been posting anonymously or something.

PhyloGenesis


- QBasic Rules - Mac (RIP)

Posted on Oct 26, 2010, 12:29 AM

Respond to this message   

Return to Index


Complete scankey program listed in sub-forum:

by Solitaire (Login Solitaire1)
S

Posted on Oct 1, 2010, 9:59 AM

Respond to this message   

Return to Index


*It's official, I need glasses. I swore I read it as: "Complete skanky program..."

by (Login The-Universe)
Admin

Posted on Oct 2, 2010, 2:49 PM

Respond to this message   

Return to Index


Downloading QBasic

by JohnD (no login)

I have got all kind of connections to QBasic via Google, but don't see a way to download it onto my Vista laptop. Help please. Thanx.

Posted on Sep 30, 2010, 10:42 AM

Respond to this message   

Return to Index


* Can't you unzip it or what?

by (Login burger2227)
R

Posted on Sep 30, 2010, 11:50 AM

Respond to this message   

Return to Index


Iff your Vista is 64-bit, don't bother...

by (Login The-Universe)
Admin

QB only runss on 32 and 16-bit platforms. go to www.qb64.net, instaed. If your vista is 32-bit, Some of QB will work. but you won't be able to run any graphics programs, as Vista doesn't support full-screen mode.

Why you can't download, well, as Clippy stated, you didn't give use enough info to help you. A QB download is like any other. Right click, select save target as, and download it.

Pete

Posted on Sep 30, 2010, 12:00 PM

Respond to this message   

Return to Index


Simple DARN recursive circles fractal !

by (no login)

Beware, this is TRUE : All you wanted to know about recursivity without darning to ask, in a demo. Ye it is unbelievable.

I would be glad to see a *clear* code for this with nested loops :) Or anything ITERATIVE.

Does QB64 run recursive code ?

And don't run this with n = 32, this ends never on my P III 750 Mhz, while n = 16 is still ok.

=============== CODE =================

DECLARE SUB CIRCLES (X, Y, R, C, n)
COMMON SHARED n, X, Y, R, C

SCREEN 12

n = 16

X = 320
Y = 240
R = 220
C = 1

PSET (X, Y)
CIRCLE (X, Y), R, C

CALL CIRCLES(X, Y, R, C, n)

a$ = INPUT$(1)

SYSTEM
END

SUB CIRCLES (X, Y, R, C, n)

IF n <= 0 THEN EXIT SUB

CIRCLE (X, Y), R, C

CALL CIRCLES(X - (R / 2), Y, (R / 2), 1, n - 1)

CALL CIRCLES(X + (R / 2), Y, (R / 2), 5, n - 1)

END SUB

Posted on Sep 28, 2010, 8:14 AM

Respond to this message   

Return to Index


Re: Simple DARN recursive circles fractal !

by Anonymous (no login)

http://www.network54.com/Forum/648955/message/1252828047/This+method+will+be+hard+to+better---

Posted on Sep 28, 2010, 8:30 AM

Respond to this message   

Return to Index


Sorry but this is not the spirit of recursion ;-)

by Lisztfr (no login)

Is recursion only the fact of calling one's self ? no... In that case it can be replaced by a loop.

I tried something like this before posting my code, like here : the counter was put inside the sub. This didn't make any sens.

My code here is a level beyond that :-) :

1) the counter is put inside the set of variables called by the sub (n)
2) the sub calls itself twice.

In fact circles are draw in 2 ^ n times. The recursion is true, it's not a loop... each time we have x 2 more circles. This is exponential calling.

If a function is calling it self, it also like f(n - 1).




Posted on Sep 28, 2010, 8:48 AM

Respond to this message   

Return to Index


*Read about the Ackermann function

by (Login Mikrondel)
Moderator

Posted on Oct 1, 2010, 8:57 PM

Respond to this message   

Return to Index


Triangle fractal recursiv

by (no login)

DECLARE SUB TRI (X, BY, B, H, C, n)

COMMON SHARED B, BY, C

SCREEN 12

n = 8

CONST EQ = .8860254#
B = 200 ' half edge
H = (B * 2 * EQ) ' high
X = 320 ' Sommet 0
C = 15 ' Color
BY = 480 - ((480 - (B * 2 * EQ)) / 2) ' Base line

' coordinates :

'BL = (320 - B, BY) ' base left
'BR = (320 + B, BY)
'S = (320, BY - (B * 2 * .866)) ' peak

'PSET (320, 240)

LINE (X - B, BY)-(X + B, BY), C
LINE -(X, BY - H), C
LINE -(X - B, BY), C

'Upside Down :

'S = (320, BY)
'RU = (320 + B / 2, BY - ((B * 2 * EQ)) / 2)
'LU = (320 - B / 2, BY - ((B * 2 * EQ)) / 2)

LINE (X, BY)-(X + B / 2, BY - H / 2), C
LINE -(X - B / 2, BY - H / 2), C
LINE -(X, BY), C

CALL TRI(X, BY, B, H, C, n)

a$ = INPUT$(1)

SYSTEM

END

SUB TRI (X, BY, B, H, C, n)

IF n <= 1 THEN EXIT SUB

LINE (X, BY)-(X + B / 2, BY - H / 2), C
LINE -(X - B / 2, BY - H / 2), C
LINE -(X, BY), C

CALL TRI(X - B / 2, BY, B / 2, H / 2, C, n - 1)
CALL TRI(X + B / 2, BY, B / 2, H / 2, C, n - 1)

CALL TRI(X, BY - H / 2, B / 2, H / 2, C, n - 1)

END SUB

Posted on Sep 28, 2010, 12:19 PM

Respond to this message   

Return to Index


Beautiful! ...

by (Login qb432l)
R

The triangles remind me of lace or jewelry -- btw, both the circle and triangle examples run fine in QB64 -- and are completed instantly!

-Bob

P.S. I'd hate to have to guess the number of triangles on the latest example!

Posted on Sep 28, 2010, 1:47 PM

Respond to this message   

Return to Index


Colors

by (no login)

Have you notice one can tweak the colors ? like here :

CALL TRI(X - B / 2, BY, B / 2, H / 2, 1, n - 1)
CALL TRI(X + B / 2, BY, B / 2, H / 2, 2, n - 1)

CALL TRI(X, BY - H / 2, B / 2, H / 2, 3, n - 1)

Replace C with any color code.

It is then really nice. But i'm much more amazed by beauty of the code : Only 3 lines to draw a fractal, easy readable code, working like a charm !

The number of triangles grows by a factor 3 with n :)

The total number.. ok.

I'm just wondering if i can do the arithmetic challenge i posted few days ago, with recursivity...




Posted on Sep 28, 2010, 2:13 PM

Respond to this message   

Return to Index


*The colors thing is great, and yes, I should have commented on the code -- very elegant!

by (Login qb432l)
R

*

Posted on Sep 28, 2010, 7:53 PM

Respond to this message   

Return to Index


*Thanks, but not running in XP ?

by Lisztfr (no login)

*

Posted on Sep 29, 2010, 12:14 PM

Respond to this message   

Return to Index


I have Windows 7...

by (Login qb432l)
R

I tried it under DOSBox and it ran fine -- a bit slower than QB64 but fine. Like I said, it's instantaneous in QB64.

Not sure why it won't run in XP. Do other graphics programs run? I've run QBasic graphics programs in XP 32-bit just fine. XP 64-bit, they won't work and you must use a DOS emulator like DOSBox. Fortunately, with QB64 those days are behind me.

-Bob

Posted on Sep 29, 2010, 6:00 PM

Respond to this message   

Return to Index


Vesa stuff .. ?

by Lisztfr (no login)

I guess it's an XP problem like here, and maybe it was Clippy who made that "patch" ? (bugerXXXX)

=> http://www.qbasiiicstation.com/index.php?c=p_member&downloadid=443

i didn't try it yet... it's my dad's PC.

Posted on Sep 30, 2010, 3:43 AM

Respond to this message   

Return to Index


I didn't make the patch. Found it at Phatcode.net.

by (Login burger2227)
R

Another fix is to copy Autoexec.NT found in Repair folder if QB won't run correctly:

COPY C:\Windows\Repair\AutoExec.nt C:\Windows\System32

Just make a BAT file or run from command line. The file in the Repair folder is an original copy. As are the other files in that folder.

Posted on Sep 30, 2010, 9:42 AM

Respond to this message   

Return to Index


Micro$oft's goal is to eventually create operating systems that any idiot can run...

by (Login The-Universe)
Admin


But for now we're content to create operating systems that any idiot can own.

Posted on Sep 30, 2010, 8:07 PM

Respond to this message   

Return to Index


*I would love to see how many they would sell, if they didn't come bundled with new comps!

by (Login qb432l)
R

*

Posted on Oct 1, 2010, 11:55 AM

Respond to this message   

Return to Index


on error goto

by (no login)

I'm trying to delete some .tmp files from one directory, everything is ok but when there is no file i got an error, how I can skip that? I tried this.

on error goto salir
kill ("C:\test\*.tmp")
print "Files Deleted"
sleep 3
end
salir:
print "There are no files to delete"
on error goto 0
resume next
end

Posted on Sep 27, 2010, 12:37 PM

Respond to this message   

Return to Index


on error goto 0 ??

by Lisztfr (no login)

What for ? i would delet that.

Posted on Sep 27, 2010, 1:52 PM

Respond to this message   

Return to Index


Deleted

by Anonymous (no login)

Ok, deleted, the main problem is: when I try to compile my .bas the compiler says

warning errors 0
severe errors 2

on error goto salida
^missing on error (/E) option
resume next
^ Missing resume next (/X)

Posted on Sep 27, 2010, 2:03 PM

Respond to this message   

Return to Index


Use those options when compiling with BC.exe

by (Login burger2227)
R

SHELL "BC MODULE1.BAS /O/S/E/X;"

or command line: BC MODULE1.BAS /O/S/E/X;

Posted on Sep 27, 2010, 2:51 PM

Respond to this message   

Return to Index


Open each FOR APPEND before killing them

by (Login burger2227)
R

Open each file name with APPEND. It will create files that don't exist.

OPEN file$ FOR APPEND AS #1
CLOSE #1
KILL file$

WHY are you trying to kill non-existant files? That's silly!

Posted on Sep 27, 2010, 3:00 PM

Respond to this message   

Return to Index


Re: Open each FOR APPEND before killing them

by Lenfras (no login)

I don't want to kill non-existant files, but what happen if I run my .exe one time? everything is good right? what about twice? that's the error I don't want, I tried to skip error the way I showed you but now the problem is compiling .bas, Ok, I will follow up your advice, I create at least one file before kill.

thank you very much to all of you, and sorry for my english!!

Posted on Sep 29, 2010, 12:46 PM

Respond to this message   

Return to Index


Unfortunately you gotta OPEN them to check em

by (Login burger2227)
R

You don't want to OPEN FOR INPUT ...error if not exist!

OPEN FOR OUTPUT blanks the file, so APPEND, BINARY or RANDOM are the only safe modes to use if you want to see if they exist.

THAT creates a file if it DID NOT exist, but you are gonna kill them anyhow.

WHAT would you suggest and if so, WHY ASK US?????????

WARNING! Using KILL *. ANYTHING is NOT a good idea unless you KNOW what you are doing! YOU DON'T APPARENTLY!

Posted on Sep 29, 2010, 3:24 PM

Respond to this message   

Return to Index


I would change the code a bit, too...

by (Login The-Universe)
Admin


on error goto salir
kill ("C:\test\*.tmp")
on error goto 0
of er1 = 0 the print "Files Deleted" else print "There are no files to delete"
sleep 3
end

salir:
er1 = ERR
resume next
end

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

Pete

PS BC with compiler switches /O/S/E/X; For some reason, I never forget them. happy.gif If you auto-compile with QB, they will be automatically added when the compiler detects the error handler statement.

PPS Clippy uses them too, but he compiles by hand. :O

Posted on Sep 28, 2010, 12:00 AM

Respond to this message   

Return to Index


Correct way to check for file existence:

by Solitaire (Login Solitaire1)
S

There are two different approaches. The first is by using an error handler:

CLS
flag = 0
INPUT "Enter filename: ", filenom$
ON ERROR GOTO check
OPEN filenom$ FOR INPUT AS #1
IF flag = 1 THEN
    PRINT "File does not exist."
    flag = 0
ELSE
    PRINT "File "; filenom$; "exists."
    CLOSE #1
END IF
END

check:
flag = 1
RESUME NEXT

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

The second way is much simpler. However, if the file exists but is empty, it will be deleted:

CLS
INPUT "Enter file name: ", filenom$
OPEN filenom$ FOR APPEND AS #1
N = LOF(1)
CLOSE #1
IF N = 0 THEN
    PRINT "File does not exist"
    KILL filenom$
ELSE
    PRINT "File "; filenom$; exists; ""
END IF
END

Posted on Sep 28, 2010, 12:09 PM

Respond to this message   

Return to Index


* ? exists; "" :-)

by Clippy (Login burger2227)
R

Posted on Sep 29, 2010, 9:25 PM

Respond to this message   

Return to Index


access qbasic

by (no login)

I have windows xp. I am assuming that I have qbasic installed as part of windows. I bought the book qbasic for dummies. It tells me to enter qbasic.exe in the directory, but I don't know how to get to the directory. Thank you for your help.

Posted on Sep 26, 2010, 8:32 AM

Respond to this message   

Return to Index


Wrong

by Lisztfr (no login)

False assuming

Then install Locate32.

Posted on Sep 26, 2010, 8:51 AM

Respond to this message   

Return to Index


Don't assume anything.

by Solitaire (no login)

QBasic is NOT installed with Windows, never was. It came with MS-DOS version 5. It's a DOS program and is no longer compatible with the newer versions of Windows.

You need to download QBasic and install it yourself, in a directory of your choosing. This program is text-based. You must be familiar with the Command prompt and DOS commands in order to proceed with installation.

You can get to the Command prompt in Windows XP by clicking Start in the bottom left corner of the desktop. Then click Run and type CMD. At this point you need to start entering DOS commands. To exit the Command window, type EXIT and press the Enter key.

Note: A DOS directory is equivalent to a Windows folder. You can bypass the Command prompt window by copying the QBasic program to a folder. In order to run the program, you need to click on the QB.EXE file. This is NOT a regular Windows installation. All DOS programs are simply copied to a folder/directory and run directly from the EXE file.


Posted on Sep 26, 2010, 10:33 AM

Respond to this message   

Return to Index


Or

by unseen Machine (no login)

Download QB64 - QBasic for modern operating systems. www.qb64.net

Theres a active forum where you can ask any questions you want, and QB64 makes doing a lot of stuff a lot easier. It can play mp3s, load images with one command and even use TCP/IP!! There are loads of demos and programs on the forum, have a look around ask anything you want, and have fun coding!!!

Posted on Sep 26, 2010, 11:57 AM

Respond to this message   

Return to Index


Random Number Help

by Bob (no login)

I need help writing random numbers. It must calculate a random number 1-18 and the outputs all numbers that add up to that number. Example: if a random number is 5 the output should look like:

1
2
3
4
5


Sorry for the amateur question but I've just started QB. Thanks for the help!

Posted on Sep 25, 2010, 8:07 PM

Respond to this message   

Return to Index


* Read the Homework link above. No code, no help!

by (Login burger2227)
R

Posted on Sep 25, 2010, 9:36 PM

Respond to this message   

Return to Index


Look up

by unseenmachine (no login)

Firstly, clippys right, i cant give you code, however i can point you in the right direction.

Look in the wiki, or qb helpfile if your using original qbasic for the following

RND
RANDOMIZE
TIMER

For the counting up to the number bit, use could use a FOR loop. Start at 1 and loop until your random number is reached.

Have a go and post your code, then i can help more.

Posted on Sep 25, 2010, 9:56 PM

Respond to this message   

Return to Index


Some nice fractal

by (no login)

' DECLARE SUB TRI 'later...

SCREEN 12


CONST EQ = .8860254#
COT = 200 ' half edge
BY = 480 - ((480 - (COT * 2 * EQ)) / 2) ' Base line

' coordinates :

'BL = (320 - COT, BY) ' base left
'BR = (320 + COT, BY)
'S = (320, BY - (COT * 2 * .866)) ' peak

'PSET (320, 240)

LINE (320 - COT, BY)-(320 + COT, BY)
LINE -(320, BY - (COT * 2 * EQ))
LINE -(320 - COT, BY)

'Upside Down :

'S = (320, BY)
'RU = (320 + COT / 2, BY - ((COT * 2 * EQ)) / 2)
'LU = (320 - COT / 2, BY - ((COT * 2 * EQ)) / 2)

LINE (320, BY)-(320 + COT / 2, BY - ((COT * 2 * EQ)) / 2)
LINE -(320 - COT / 2, BY - ((COT * 2 * EQ)) / 2)
LINE -(320, BY)

' Low left :

LINE (320 - COT / 2, BY)-(320 - COT / 4, BY - ((COT * 2 * EQ)) / 4)
LINE -(320 - (COT / 4) * 3, BY - ((COT * 2 * EQ)) / 4)
LINE -(320 - COT / 2, BY)

' Low right :

LINE (320 - COT / 2 + COT, BY)-(320 - COT / 4 + COT, BY - ((COT * 2 * EQ)) / 4)
LINE -(320 - (COT / 4) * 3 + COT, BY - ((COT * 2 * EQ)) / 4)
LINE -(320 - COT / 2 + COT, BY)

' Up :

LINE (320 - COT / 2 + (COT / 2), BY - ((COT * 2 * EQ)) / 2)-(320 - COT / 4 + (COT / 2), BY - ((COT * 2 * EQ)) / 4 - ((COT * 2 * EQ)) / 2)
LINE -(320 - (COT / 4) * 3 + (COT / 2), BY - ((COT * 2 * EQ)) / 4 - ((COT * 2 * EQ)) / 2)
LINE -(320 - COT / 2 + (COT / 2), BY - ((COT * 2 * EQ)) / 2)


END

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

Hand made, - depth ? not much.

The goal is to increase the depth using a RECURS(ed)IVE SUB...












Posted on Sep 24, 2010, 12:28 PM

Respond to this message   

Return to Index


The Sorcerer's Apprentice

by Lisztfr (no login)

I searched for recursion in the archives also. It seems that it was not innvestigated as something different or special... But it is :

http://german.about.com/library/blgzauberl.htm


Now I'll throw myself upon you,
and the sharpness of my axe
I will test, o spirit, on you.
Well, a perfect hit!
See how he is split!
Now there's hope for me,
and I can breathe free!

Woe is me! Both pieces
come to life anew,
now, to do my bidding
I have servants two!
Help me, o great powers!
Please, I'm begging you!

And they're running! Wet and wetter
get the stairs, the rooms, the hall!
What a deluge! What a flood!
Lord and master, hear my call!

CALL !

Posted on Sep 25, 2010, 8:04 AM

Respond to this message   

Return to Index


You've given new meaning to recursion...

by (Login qb432l)
R

Who knew that black magic was a capability in QBasic.

BTW, your fractal triangles look promising. The output reminds me of that riddle: "How many triangles do you see?".

-Bob

Posted on Sep 25, 2010, 8:32 AM

Respond to this message   

Return to Index


Sierpinsky recursiv

by (no login)

DECLARE SUB TRI (X, BY, B, H, C, n)

COMMON SHARED B, BY, C

SCREEN 12

n = 8

CONST EQ = .8860254#
B = 200 ' half edge
H = (B * 2 * EQ) ' high
X = 320 ' Sommet 0
C = 15 ' Color
BY = 480 - ((480 - (B * 2 * EQ)) / 2) ' Base line

' coordinates :

'BL = (320 - B, BY) ' base left
'BR = (320 + B, BY)
'S = (320, BY - (B * 2 * .866)) ' peak

'PSET (320, 240)

LINE (X - B, BY)-(X + B, BY), C
LINE -(X, BY - H), C
LINE -(X - B, BY), C

'Upside Down :

'S = (320, BY)
'RU = (320 + B / 2, BY - ((B * 2 * EQ)) / 2)
'LU = (320 - B / 2, BY - ((B * 2 * EQ)) / 2)

LINE (X, BY)-(X + B / 2, BY - H / 2), C
LINE -(X - B / 2, BY - H / 2), C
LINE -(X, BY), C

CALL TRI(X, BY, B, H, C, n)

a$ = INPUT$(1)

SYSTEM

END

SUB TRI (X, BY, B, H, C, n)

IF n <= 1 THEN EXIT SUB

LINE (X, BY)-(X + B / 2, BY - H / 2), C
LINE -(X - B / 2, BY - H / 2), C
LINE -(X, BY), C

CALL TRI(X - B / 2, BY, B / 2, H / 2, C, n - 1)
CALL TRI(X + B / 2, BY, B / 2, H / 2, C, n - 1)

CALL TRI(X, BY - H / 2, B / 2, H / 2, C, n - 1)

END SUB

Posted on Sep 28, 2010, 12:18 PM

Respond to this message   

Return to Index


*That's Sierpiński to you.

by (Login Mikrondel)
Moderator

Posted on Sep 30, 2010, 6:05 PM

Respond to this message   

Return to Index


* I did not know that Australians used oomlauts! :-P

by Clippy (Login burger2227)
R

Posted on Sep 30, 2010, 6:08 PM

Respond to this message   

Return to Index


* Tak, rozumiem, miniej więcej

by Lisztfr (no login)

*

Posted on Oct 1, 2010, 3:24 PM

Respond to this message   

Return to Index


* It is a fractal. Looking like Sierpinki's, very close.

by Lisztfr (no login)

*

Posted on Oct 1, 2010, 3:28 PM

Respond to this message   

Return to Index


problem with GOTO commmand inside SUB

by YanR (no login)

hello ppl,

i'll make it short
i use a QBX 7.1 qbasic compiler.
and i'm programming a progam that need's to
open a sub routine inspect which button pressed or mouse
and go to the defined choosen label outside of the sub!
in the main program area.

but when i type let's say "goto NEW" new is name of the label
inside the sub it gives me "error 8" label not defined something
i must add that label "NEW" is located outside of the sub in
the main program area.

i need to go to the label "new" from inside of the sub
pl'z help

YanR,
10x.

Posted on Sep 23, 2010, 12:26 PM

Respond to this message   

Return to Index


GOTO

by Lisztfr (no login)

You have to exit the sub and return before the label, with a flag for example to tell the main what to do. At least in QB 4,5.

Or put the code you want to run in the main into another SUB and call it from your SUB.


Posted on Sep 23, 2010, 12:45 PM

Respond to this message   

Return to Index


GOTO inside SUB

by YanR (no login)

I don't quite get it, if i exit the sub
it will exit to commands under the sub.

and what is a flag and how do i put it?

i can't put it into anthor sub it's a big program,
with lot's of integers and strings.

please show QB code with example next time, if u can.

is there maybe a command to make the label shared or something like that?

YanR
10x

Posted on Sep 23, 2010, 12:57 PM

Respond to this message   

Return to Index


2 cents..

by Lisztfr (no login)

If someone can tell better ?

Please look at Buffer (TXT1$). The only way i have to go to Start0 label i want to, is to wait for the SUB has returned from where it was called, line 3. In QB 4.5 i don't know an other way ! But after RETURNed, i check the flag (line 4, 5) and then from this place i can GOTO the label...

IF PRINTX > linelength% THEN
GOSUB LineCut
Buffer (TXT1$)
IF flags% = 1 THEN GOTO Start0 'new start after search routin
IF flagtf% = 1 THEN GOTO Start0
GOTO PRINTALL
ELSE
Buffer (linebuf$)
IF flags% = 1 THEN GOTO Start0 'same
IF flagtf% = 1 THEN GOTO Start0
END IF

Posted on Sep 23, 2010, 2:13 PM

Respond to this message   

Return to Index


even better dont use GOTO

by Unseen Machine (no login)

It is old and outdated, and viewed by most as bad coding practice. It makes it hard for others to read your code, and can make it difficult in debugging. Try using a main do loop with triggered calls to subs that perform specific tasks. Other than that i cant help sorry, but best of luck.

Posted on Sep 23, 2010, 7:26 PM

Respond to this message   

Return to Index


Sure

by Lisztfr (no login)

I know other bad practices :

-Nested loops, :)
-No comments :)

To prevent people accidentally understanding your code... Same as the Hight Priest in ancient Egypt : The secret must be kept away from profane.




Posted on Sep 24, 2010, 12:55 AM

Respond to this message   

Return to Index


Nested loops are necessary,

by Solitaire (no login)

especially when working with arrays, or validating data within a loop.

Posted on Sep 26, 2010, 3:33 PM

Respond to this message   

Return to Index


* Another thing to avoid...being French! Nasty people! :-P

by (Login burger2227)
R

Posted on Sep 26, 2010, 8:38 PM

Respond to this message   

Return to Index


Please help with looping

by Luke (no login)

hey guys, I'm really confused about qbasic. I need to learn how to loop, and in doing so create a line of circles going across the middle of the screen. I have no idea how to do this, can anyone help me?

Posted on Sep 22, 2010, 10:02 PM

Respond to this message   

Return to Index


* Homework? Post what you have done so far.

by Clippy (Login burger2227)
R

Posted on Sep 22, 2010, 10:29 PM

Respond to this message   

Return to Index


Loop demo

by Unseen Machine (no login)

First, you should post your code. Second here's a Do style loop that exits when you press the Esc key

DO:LOOP UNTIL INKEY$ = CHR$(27)

if you need to do something a set number of times you can use a FOR loop

for i = 1 to 100
print i
next

will print 1 to 100 on the screen

in older basic you could (qbasic supports it)

i = 0
while i < 100
i = i + 1
print i
wend

this will also print 1 to 100 on the screen

for the drawing of circles, you will need to be in a graphics display mode (any screen mode above 0) and know how to draw circles. Look up CIRCLE, PSET, DRAW, and PAINT all available in the qb64 wiki http://qb64.net/wiki/index.php?title=Main_Page , or if your using original qbasic, press shift and F1 and use the index.

Posted on Sep 23, 2010, 7:19 PM

Respond to this message   

Return to Index


Stupid program

by Lisztfr (no login)

All what i do with recursion is like looping, nothing else. Can anyone actually write a graphical program using recursion, where it's usefull ?

DECLARE SUB RPSET (z%, y%)

SCREEN 12

Z% = 6
y% = 5

CALL RPSET(z%, y%)

END

SUB RPSET (z%, y%)

IF z% = 0 THEN EXIT SUB

PSET (z% * 10, Y%)

CALL RPSET((z% - 1), y% + 10)

END SUB

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

To draw with PSET i need number argument, but since i used PSET while recalling, PSET is not a numbre. The reverse is when i use FUNCTION

DECLARE FUNCTION sum (Z%)
COMMON SHARED s%

SCREEN 12

Z% = 6

s% = sum(Z%)

' PRINT s%

END

FUNCTION sum (Z%)

IF Z% = 0 THEN EXIT FUNCTION

PSET (sum(Z% - 1) + Z%, 10)

END FUNCTION

Posted on Sep 22, 2010, 12:56 PM

Respond to this message   

Return to Index


"For every recursive algorithm, there is an iterative algorithm."

by (no login)

http://vb.mvps.org/hardcore/html/iterativequicksort.htm

Scott’s code proves two points. First, iterative algorithms aren’t necessarily faster than recursive ones. If you check the two versions in the TimeIt application, you’ll see that the recursive version wins by half a hair. But in a race that close you have to give the advantage to the code that uses the least resources. The iterative version gets the nod as the official SortArray procedure in the VBCore component because it can never run out of stack space.

The second point is that recursive algorithms can be a lot simpler than iterative ones. In fact, I think of the recursive version as documentation for the iterative version. You can read the recursive code and it makes sense. Not so the iterative code. I stepped through it and added comments that attempt to explain what’s going on, but I still don’t really understand the details. Mainly I just pray that it works.

Posted on Sep 23, 2010, 3:24 AM

Respond to this message   

Return to Index


Are you sure (*URL)

by qbguy (no login)

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

Posted on Sep 24, 2010, 6:45 AM

Respond to this message   

Return to Index


Yes I'm sure

by (Login Mikrondel)
Moderator

Ackermann function ain't primitive recursive but it can be implemented with a while loop and an array. The array might need to be quite large.

Posted on Oct 10, 2010, 1:08 AM

Respond to this message   

Return to Index


REAL RECURSIVITY (working example)

by Lisztfr (no login)

Sometimes my recursivity examples here was fake, just another way to loop : decreasing a variable was the only thing the call-it-self did.

Now, recursif means not only change a variable but also change the data segment on which it applies, and treat all of these subsequent segments...

So inside the SUB, the SUB needs to call itself more than one time, because that IS recursivity. Else it is a LOOP.

EXAMPLE : each time the following routine calls itself, z% increases by 1, so the routine was called 16 times (for n = 4), 2 ^ 4



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

DECLARE SUB ADD (n)
COMMON SHARED z%

n = 4
z% = 1

CALL ADD(n)

PRINT z%

END


SUB ADD (n)

IF n < 1 THEN EXIT SUB

z% = z% + 1

CALL ADD(n - 1)
CALL ADD(n - 1)

END SUB

Posted on Sep 23, 2010, 5:12 AM

Respond to this message   

Return to Index


No stack space issue ... !

by (no login)

DECLARE SUB ADD (n)
COMMON SHARED z&

n = 20
z& = 1

CALL ADD(n)

PRINT z&

END

SUB ADD (n)

IF n < 1 THEN EXIT SUB

z& = z& + 1

CALL ADD(n - 1)
CALL ADD(n - 1)

END SUB

Posted on Sep 23, 2010, 5:22 AM

Respond to this message   

Return to Index


* 3 ^ 4 ? not working...

by Lisztfr (no login)

*

Posted on Sep 23, 2010, 6:03 AM

Respond to this message   

Return to Index


How to compute cubics with that method ?

by (no login)

DECLARE SUB ADD (n)
COMMON SHARED z&

'SCREEN 12

n = 8
z& = 1

FOR i = 1 TO n
CALL ADD(i)
PRINT z&
z& = 1
NEXT i

END

SUB ADD (n)

IF n < 1 THEN EXIT SUB

z& = z& + 1

'PSET (n * 10, z& * 10)

CALL ADD(n - 1)
CALL ADD(n - 1)
'CALL ADD(n - 1)
'CALL ADD(n - 1)

END SUB

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

After power of 2, for example uncomment one CALL statement will not produce a 3 ^ n...

Posted on Sep 23, 2010, 6:29 AM

Respond to this message   

Return to Index


Fibonacci in a SUB... !

by (no login)

DECLARE SUB ADD (n)
COMMON SHARED z&

'SCREEN 12

n = 8
z& = 1

FOR i = 1 TO n
CALL ADD(i)
PRINT z&
z& = 1
NEXT i

END

SUB ADD (n)

IF n < 1 THEN EXIT SUB

z& = z& + 1

'PSET (n * 10, z& * 10)


CALL ADD(n - 1)
CALL ADD(n - 2)


'CALL ADD(n - 1)
'CALL ADD(n - 1)

END SUB

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

But still want a cubic !

Posted on Sep 23, 2010, 6:44 AM

Respond to this message   

Return to Index


Recursive hell

by Lisztfr (no login)

I think nobody use it very much. But it feels smart and i hate to have a thing and can't do any thing uselful with it.


Posted on Sep 23, 2010, 12:49 PM

Respond to this message   

Return to Index


More stuff

by (no login)

Random programing : try to bring the most confusion possible in variables.


DECLARE SUB ADD (n, X, Y)
COMMON SHARED z&, s&, a&, b&, c&, n

SCREEN 12

n = 8
z& = 1

X = 320: Y = 1

FOR i = 0 TO 8
CALL ADD(i, X, Y)
' PRINT a&; b&; c&; z&
z& = 1

NEXT i

END

SUB ADD (n, X, Y)

IF n < 1 THEN
' n = 0: 'z& = z& - 1
EXIT SUB
END IF

z& = z& + 1

'LINE (1, n * 10)-(X * 10, Y * 10)

PSET (X * 10, Y * 10)


'IF Y < 400 THEN PSET (X, Y)

X = X / 2: Y = Y

CALL ADD(n - 1, X, Y): 'a& = a& + 1
CALL ADD(n - 1, Y + 10, X + 10): 'b& = b& + 1
CALL ADD(n - 1, X * Y, 20): 'c& = c& + 1


END SUB

Posted on Sep 24, 2010, 3:47 AM

Respond to this message   

Return to Index


Recursion unexpected

by (no login)

DECLARE SUB think (a)

CLS

a = 16

think (a)

END

SUB think (a)
PRINT a
IF a > 1 THEN
think (a / 2)
END IF
PRINT a
END SUB

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

16
8
4
2
1
1
2
4
8
16

Subroutine "think" first prints the variable it is passed. Then, if the value is greater than 1, it calls itself again, but passes the variable divided by 2. At the point where the value passed is 1, "think" prints "1", decides not to call itself again, prints "1" again, and then terminates. This terminataion returns program flow to the previous call, which is where the value passed was 2. "think" prints "2" again and terminates, and so on.

???

I understand why 2 will be printed since 2 was the previous value to 1, but when a = 2 then it should ot terminate but call it self again... Gosh. Will watch it step by step...



Posted on Sep 21, 2010, 1:50 AM

Respond to this message   

Return to Index


Floating point numbers do not exactly equal the corresponding integer value.

by Solitaire (no login)

The actual value of a floating point number is very slightly greater than indicated. For example, 1 may actually be 1.000000000000000000000001 or some such thing. Therefore, it is greater than 1.

I'm on my son's computer now so I can't test it myself, but try declaring a as an integer and see what happens.

Posted on Sep 21, 2010, 2:27 AM

Respond to this message   

Return to Index


Same thing with integer

by (no login)

I will try to replace the / 2 (divide) by a negative (-1) to see if there is a limit in the recursiveness

Posted on Sep 21, 2010, 3:37 AM

Respond to this message   

Return to Index


* Try using integer division \

by Solitaire (no login)

Posted on Sep 21, 2010, 8:49 AM

Respond to this message   

Return to Index


a = 80 : stack overflow

by (no login)

DECLARE SUB think (a)

DIM a AS INTEGER

CLS

a = 80

think (a)

END

SUB think (a)
PRINT a
IF a > 1 THEN
think (a - 1)
END IF
PRINT a
END SUB

Posted on Sep 21, 2010, 3:41 AM

Respond to this message   

Return to Index


You have to exit ALL recursions

by angros47 (no login)

DECLARE SUB think (a)

CLS

a = 16

think (a)

END

SUB think (a)
PRINT a
IF a > 1 THEN
think (a / 2)
END IF
PRINT a
END SUB


Let's see what happens:

a=16
think is called:

it does:


PRINT 16
IF 16 > 1 THEN
think 8
END IF
PRINT 16


think 8 means:

PRINT 8
IF 8 > 1 THEN
think 4
END IF
PRINT 8

So, actually "think 16" does:

PRINT 16
IF 16 > 1 THEN

'this is "think 8"
PRINT 8
IF 8 > 1 THEN
think 4
END IF
PRINT 8

' now we are back at "think 16"
END IF
PRINT 16


and so on.

Basically, when you exit from a SUB, you return to the calling procedure: and if you entered the same procedure many times (as you do in a recursion), you have to exit many times: and every time, the PRINT is executed.

To avoid it, you could do something like:

SUB think (a)
PRINT a
IF a > 1 THEN
think (a / 2)
ELSE
END 'Program will stop here.

END IF
PRINT a
END SUB

Posted on Sep 21, 2010, 2:11 PM

Respond to this message   

Return to Index


Function

by (no login)

Thanks, i understand it better now...

But your finale code doesn't "exit sub" ? My opinion so is far, there is no infinite recursion possible,, while calling a SUB, but also it's doesn't make so much sens.. This recursion effect seems more proper applied to FUNCTION. Since the variable is the function it self, in theory we need less stack space... ?

Posted on Sep 21, 2010, 2:45 PM

Respond to this message   

Return to Index


*the final command exit current sub, not all subs.

by angros47 (no login)

Posted on Sep 21, 2010, 2:53 PM

Respond to this message   

Return to Index


findspacce function i wrote some day

by Lisztfr (no login)

DECLARE FUNCTION findspace (aline$, numb%) 'find num% rank space in a string
COMMON SHARED num%

CLS
aline$ = "abc efg hij"
a% = INSTR(INSTR(aline$, " ") + 1, aline$, " ")
PRINT a%

SLEEP

num% = 2
PRINT findspace(aline$, num%)


END

FUNCTION findspace (aline$, num%)

IF num% = 0 THEN exit function

findspace = INSTR(findspace(aline$, num% - 1) + 1, aline$, " ")

END FUNCTION

Posted on Sep 22, 2010, 1:28 AM

Respond to this message   

Return to Index


Sum function

by (no login)

DECLARE FUNCTION sum (z%)
COMMON SHARED s%

Z% = 3

s% = sum(z%)

PRINT s%

END

FUNCTION sum (z%)

IF z% = 0 THEN EXIT FUNCTION

sum = sum(z% - 1) + z%

END FUNCTION

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

This is working since the function is like f(n) = f(n - 1) + Variable, but what about a function like f(n) depends on 2 previous states...

n - 1 and n - 2.



Posted on Sep 22, 2010, 5:43 AM

Respond to this message   

Return to Index


Or you could do

by C. F. Gauss (no login)

'Ligget se
FUNCTION sum(z%)
sum = (z%^2 + z%) / 2
END FUNCTION

Posted on Sep 22, 2010, 12:36 PM

Respond to this message   

Return to Index


Good example here

by (no login)

http://progopedia.com/implementation/qbasic/

DECLARE FUNCTION fibonacci (n)

FOR i = 1 TO 16:
PRINT fibonacci(i); ", "
NEXT i
PRINT "..."

FUNCTION fibonacci (n)
IF (n <= 2) THEN
fibonacci = 1
ELSE
fibonacci = fibonacci(n - 1) + fibonacci(n - 2)
END IF
END FUNCTION

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

That's very nice. I really wonder how that is working, since the first call returns to the function call, so.. Will have a step-by-step look.

It's nice that the program looks like the math formula.





Posted on Sep 22, 2010, 2:11 PM

Respond to this message   

Return to Index


Strange n values

by (no login)

FUNCTION fibonacci (n)
PRINT n;
IF (n <= 2) THEN
fibonacci = 1
ELSE
fibonacci = fibonacci(n - 1) + fibonacci(n - 2)
END IF
END FUNCTION

I just added the PRINT n;

1 1 ,
2 1 ,
3 2 1 2 ,
4 3 2 1 2 3 ,
5 4 3 2 1 2 3 2 1 5 ,
6 5 4 3 2 1 2 3 2 1 4 3 2 1 2 8

Example, 6, decrease until 1, then return to the data flow because the Function ENDs, so we have 2 again then END, then 3. So it decrease again...when it reachs 1, now it goes directly to 4 (not used in previous loop).

I tried n = 50, that's very long.

It needs to do all that stuff..

This is for fibonacci = fibonacci(n - 1) + fibonacci(n - 2) + fibonacci (n - 3)

1 1 ,
2 1 ,
3 2 1 0 3 ,
4 3 2 1 0 2 1 5 ,
5 4 3 2 1 0 2 1 3 2 1 0 2 9 ,
6 5 4 3 2 1 0 2 1 3 2 1 0 2 4 3 2 1 0 2 1 3 2 1 0 17

hm... Well...

Posted on Sep 22, 2010, 2:51 PM

Respond to this message   

Return to Index


More Questions Regarding operators, data types indenting, etc...

by Negative (no login)

Thanks for the answers on the last post. After that I came across some more questions Google couldn't answer. =]

-Are AND/OR considered to be operators like +,-,*,/..?

-Is a Boolean a data type like strings, integers, etc.?

-Is an exponent/power (^) considered to be an arithmetic operator?

-In the below example everything inside the DO..LOOP is indented. Is there a certain name for commands that usually have things inside them indented? I know the indenting is not required, but usually the same commands like DO...LOOP, IF...ELSE, etc. get indented.
Example:
DO
PRINT "Hi"
PRINT "Hello"
LOOP

-Is there a way to input quotation marks inside strings (so they'll be shown on the output screen)?

-Arguments & Parameters: "Functions/Commands exchange information by means of parameters and arguments. A parameter refers to any declaration within the parentheses following the function name in a function declaration or definition; argument refers to any expression within the parentheses of a function call."
That quote is a little too hard to understand. What I got from it was: A parameter is anything in parenthesis (...) after a command; and an argument is any expression within parenthesis.
If my definition isn't right, what exactly is a parameter and argument, and what are their differences?

Posted on Sep 20, 2010, 3:10 PM

Respond to this message   

Return to Index


Some answers --

by Solitaire (Login Solitaire1)
S

There are several types of operators used in programming. The following are available in QBasic:

Math operators: +, -, *, /, \, Mod, ^

Relational operators: =, >, etc. (Note: This forum has trouble displaying the less-than symbol. There are 6 altogether.)

Logical operators: AND, OR, NOT, XOR, EQV, IMP

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

QBasic does not have a separate Boolean type but Visual Basic does. The values of a Boolean type are either True or False. In QBasic, it's equivalent to the integer values of 0 (False) or -1 (True) or any non-zero number (True).

For example, if you run this code:
PRINT 4 > 5
The output will be 0.

PRINT 5 > 4
The output will be -1

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

A DO--LOOP is a structure block. Blocks use opening and closing statements and the contents inside the block are usually indented. In Visual Basic, the indentation of a structure block is automatic.

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

Quotation marks can be shown inside a string by using the ASCII value.
For example:

PRINT "He said, "; CHR$(34); "Hello."; CHR$(34)

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

An argument is an expression placed within parentheses following a call from the main program (or it could even be a call from a sub). The expression can be either a variable, a literal value, or a more complicated expression including an operator. A list of several arguments uses a comma separator. For example:

DIM first AS STRING, age AS INTEGER
first = "Joe"
age = 21
CALL mysub(first, age, age + 1)

A parameter is a variable name placed within parentheses in the sub that was called. It can use only variables and must include the variable type. A list of several parameters uses a comma separator. If an expression is used in the argument list, it must be replaced by a variable in the parameter list. For example:

SUB mysub (first AS STRING, age AS INTEGER, year AS INTEGER)
PRINT "Your name is "; first; " and your age is"; age
PRINT "Next year you will be"; year
END SUB

It is very important that the argument list and parameter list correspond in number, order, and type. The name of the variables in the parameter list is not important as long as they correspond. You can use different variable names in the parameter list and it will still work. For example:

SUB mysub (nom AS STRING, old AS INTEGER, year AS INTEGER)
PRINT "Your name is "; nom; " and your age is"; old
PRINT "Next year you will be"; year
END SUB

Note that the parameter list must include only variables, but the argument list may also include literal values or expressions.

Also note that as soon as you save a program with subs, the DECLARE statement automatically appears at the top of the main program. This statement includes the "signature," which is the complete parameter list. You never need to type in the declare statement manually.

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

I hope this answers your questions.



Posted on Sep 20, 2010, 4:03 PM

Respond to this message   

Return to Index


Please Help Me :(

by (no login)

I am begginer with Qbasic,and I need to do this program(donno how) can you please help me :(


- Generate 20 random numbers(from 10-99)
- show odd and even numbers
- recommit odd and recommit even numbers
- show sum of odd and even number
- show then in file

Posted on Sep 20, 2010, 11:43 AM

Respond to this message   

Return to Index


Warning - Can not post this message. Please login and try again.

by (no login)

WTF ?

Posted on Sep 20, 2010, 12:04 PM

Respond to this message   

Return to Index


* READ the Homework Policy in the header! Post your code!

by Clippy (Login burger2227)
R

Posted on Sep 20, 2010, 1:39 PM

Respond to this message   

Return to Index


Draw a circle using only PSET and integers: no SIN/COS, no SQRT...

by angros47 (no login)

Here you are:

SCREEN 12

CONST R=100

DIM X AS INTEGER
DIM Y AS INTEGER
DIM Y2 AS INTEGER
DIM TMP AS INTEGER

FOR X=-R TO R
Y2=R*R-X*X
TMP=1 : Y=Y2
DO
TMP=(Y+TMP)/2
Y=Y2/TMP
LOOP UNTIL ABS(Y-TMP)<2
PSET (320+X,240+Y): PSET (320+X,240-Y):
NEXT
SLEEP

This program uses Pythagorean theorem (the radius of the circle is the hypotenuse, knowing it and X it calculates Y), and a trick to get square root, without using built-in functions.

It's completely useless, but writing it was fun.

Posted on Sep 19, 2010, 1:03 PM

Respond to this message   

Return to Index


Here's one from me

by Unseen Machine (no login)

SCREEN 12

FOR i = 1 TO 8
x = 0
FOR j = 1 TO 8
READ clr
IF clr = 1 THEN PSET (x, y), 15
x = x + 1
NEXT
y = y + 1
NEXT

DATA 0,0,0,0,0,0,0,0
DATA 0,0,1,1,1,1,0,0
DATA 0,1,0,0,0,0,1,0
DATA 0,1,0,0,0,0,1,0
DATA 0,1,0,0,0,0,1,0
DATA 0,1,0,0,0,0,1,0
DATA 0,0,1,1,1,1,0,0
DATA 0,0,0,0,0,0,0,0

Posted on Sep 19, 2010, 2:51 PM

Respond to this message   

Return to Index


Re: Draw a circle using only PSET and integers: no SIN/COS, no SQRT...

by Ben (no login)

x = 100 'radius
y = 0
d = -x

x1 = 100 'coordinates
y1 = 200

SCREEN 12
DO WHILE x > y
y = y + 1
d = d + y + y
IF d > 0 THEN
x = x - 1
d = d - x - x
END IF
PSET (x + x1, y + y1)
PSET (x + x1, -y + y1)
PSET (-x + x1, y + y1)
PSET (-x + x1, -y + y1)

PSET (y + x1, x + y1)
PSET (-y + x1, x + y1)
PSET (y + x1, -x + y1)
PSET (-y + x1, -x + y1)
LOOP

Posted on Sep 19, 2010, 2:51 PM

Respond to this message   

Return to Index


The Breshenham algorithm revisited

by David (no login)

Drawing a circle (or any other function) on the screen we are not trying for high accuracy analogue values. The trick is to determine which is the closest pixel to the function you want to represent so we can work with integers rather than floating point numbers.

All functions will at some point have gradients (grad<1) such that increasing x by one will cause y to either not change or also increase by one. All the algorithm has to do is to change the x value (in pset) by one and decide whether y should change (by one) or stay the same.

Note a circle also has high symmetry so that only one octant has to be calculated and the other octants and be generated by axes reflections.

Below is the challenge to draw 1000 (random sized filled) as quickly as possible without using "CIRCLE".



DEFINT A-S, U-Z
SCREEN 12
RANDOMIZE TIMER
tt = TIMER
m = 1
FOR jj = 1 TO 1000
xoff = INT(RND * 640): yoff = INT(RND * 480)
c = INT(RND * 16)
y = 2 + INT(RND * RND * RND * RND * 130)
d = 0
x = -1
WHILE x < y
x = x + m
d = d + x + x + m
IF d > 0 THEN d = d - y - y + m: y = y - m
FOR k = 0 TO 7
IF k AND 4 THEN a = -x ELSE a = x
IF k AND 2 THEN b = -y ELSE b = y
IF k AND 1 THEN SWAP a, b
q2 = a: q3 = 0
IF a < 0 THEN SWAP q2, q3
FOR q1 = q3 TO q2
PSET (q1 + xoff, b + yoff), c
PSET (640 - q1 - xoff, 480 - b - yoff), c
NEXT q1
NEXT k
WEND
NEXT jj
PRINT TIMER - tt

Posted on Sep 20, 2010, 4:40 AM

Respond to this message   

Return to Index


could you use LINE?

by Ben (no login)

Posted on Sep 20, 2010, 6:30 AM

Respond to this message   

Return to Index


Re: could you use LINE?

by Ben (no login)

RANDOMIZE TIMER
DEFINT A-Z

SCREEN 12

t! = TIMER
FOR i = 1 TO 1000
x = 2 + INT(RND * RND * RND * RND * 130) 'radius
y = -1
d = -x

x1 = INT(RND * 640) 'coordinates
y1 = INT(RND * 480)
COLOR INT(RND * 16)
DO WHILE x > y
y = y + 1
d = d + y + y

IF d > 0 THEN
x = x - 1
d = d - x - x
END IF
'PSET (x + x1, y + y1)
'PSET (x + x1, -y + y1)
'PSET (-x + x1, y + y1)
'PSET (-x + x1, -y + y1)
'PSET (y + x1, x + y1)
'PSET (-y + x1, x + y1)
'PSET (y + x1, -x + y1)
'PSET (-y + x1, -x + y1)
LINE (x + x1, -y + y1)-(-x + x1, -y + y1)
LINE (x + x1, y + y1)-(-x + x1, y + y1)
LINE (y + x1, x + y1)-(-y + x1, x + y1)
LINE (y + x1, -x + y1)-(-y + x1, -x + y1)
LOOP
NEXT
PRINT TIMER - t!


Posted on Sep 20, 2010, 8:53 AM

Respond to this message   

Return to Index


* What trick? There are no non-integer pixel positions!

by Clippy (Login burger2227)
R

Posted on Sep 20, 2010, 8:33 AM

Respond to this message   

Return to Index


More fun

by Lisztfr (no login)

DO
TMP=(Y+TMP)/2
Y=Y2/TMP
LOOP UNTIL ABS(Y-TMP)<2

This looks like it could be put in a recursive function...? (that call itself)






Posted on Sep 20, 2010, 11:43 AM

Respond to this message   

Return to Index


Another challenge

by Lisztfr (no login)

The knight challenge on a chess board. Make the knight go overe all the fieds once, and only once.

64 nested loops ?

Posted on Sep 15, 2010, 2:24 AM

Respond to this message   

Return to Index


*URL

by David (no login)

http://www.network54.com/Forum/202193/message/1206121178/Knight's+Tour

Posted on Sep 15, 2010, 4:09 AM

Respond to this message   

Return to Index


Heuristic in the knight tour

by Lisztfr (no login)

I'm affraid that in the knight's tour there isn't much heuristic, beside of that from the initial poster : The next step should offer the less moves.

Other variant : the 2nd next step should offer the less moves.

But for example, in 3 steps we should get far away from place 1, or, the board should remain center-weighted (each step = 1 unit weight) after 10 steps, or the surface of the 3-5 moves (draw on board) should be maximal, .. this all doesn't make sens.

Random search is silly, with backtracking is little better.

Posted on Sep 16, 2010, 1:45 AM

Respond to this message   

Return to Index


Using Warnsdorff's algorithm

by David (no login)

CLS
DIM q(-10 TO 18, -10 TO 18) AS INTEGER, z(65) AS INTEGER
DIM cx(9) AS INTEGER, cy(9) AS INTEGER, rx(9) AS INTEGER, ry(9) AS INTEGER
r = 4: c = 4 'starting point
q(r, c) = 1
FOR i = 1 TO 8
FOR k = 1 TO 8
LOCATE i, k * 2
PRINT CHR$(176) + CHR$(176);
NEXT k
NEXT i
LOCATE r, c * 2
PRINT CHR$(219) + CHR$(219);
num = 1
z(num) = r + (c - 1) * 8
q(r, c) = 1
WHILE num < 64
rx(1) = r - 1: cx(1) = c - 2
rx(2) = r + 1: cx(2) = c - 2
rx(3) = r - 1: cx(3) = c + 2
rx(4) = r + 1: cx(4) = c + 2
rx(5) = r - 2: cx(5) = c - 1
rx(6) = r + 2: cx(6) = c - 1
rx(7) = r - 2: cx(7) = c + 1
rx(8) = r + 2: cx(8) = c + 1
pmin = 20
FOR i = 1 TO 8
IF rx(i) > 0 AND rx(i) < 9 AND cx(i) > 0 AND cx(i) < 9 AND q(rx(i), cx(i)) = 0 THEN
ry(1) = rx(i) - 1: cy(1) = cx(i) - 2
ry(2) = rx(i) + 1: cy(2) = cx(i) - 2
ry(3) = rx(i) - 1: cy(3) = cx(i) + 2
ry(4) = rx(i) + 1: cy(4) = cx(i) + 2
ry(5) = rx(i) - 2: cy(5) = cx(i) - 1
ry(6) = rx(i) + 2: cy(6) = cx(i) - 1
ry(7) = rx(i) - 2: cy(7) = cx(i) + 1
ry(8) = rx(i) + 2: cy(8) = cx(i) + 1
'END IF
p = 0
FOR k = 1 TO 8
IF ry(k) > 0 AND ry(k) < 9 AND cy(k) > 0 AND cy(k) < 9 AND q(ry(k), cy(k)) = 0 THEN p = p + 1
NEXT k
IF p < pmin THEN pmin = p: imin = i
END IF
NEXT i
pmin = 20
num = num + 1
r = rx(imin): c = cx(imin)
z(num) = r + (c - 1) * 8
IF z(num) > 64 THEN PRINT "off the board": END
q(r, c) = 1
LOCATE r, c * 2
PRINT CHR$(219) + CHR$(219);
tt = TIMER
WHILE TIMER - tt < .2: WEND '*******DELAY*******
WEND
WHILE h$ = ""
h$ = INKEY$
WEND
LOCATE 10, 1
FOR i = 1 TO 64
PRINT USING "###"; z(i);
IF i MOD 8 = 0 THEN PRINT
NEXT i

Posted on Sep 16, 2010, 11:58 AM

Respond to this message   

Return to Index


Ok i will have to jump into that matter, soon i remember some qbasic stuff.

by Lisztfr (no login)

Something unexpected ?

28 11 1 18 3 9 26 41
58 43 33 50 60 54 64 47
32 15 5 20 10 25 35 52
62 56 39 24 7 22 37 27
17 2 12 6 16 31 48 63
53 59 49 34 44 61 46 29
14 8 23 38 21 4 19 13
30 40 55 45 51 36 42 57

"2" is next the 17

nice animation :=) (not reflecting this)

Posted on Sep 16, 2010, 3:31 PM

Respond to this message   

Return to Index


Wolfram has an article on this with example results

by Zom-B (Login Zom-B)
R

Posted on Sep 19, 2010, 4:37 AM

Respond to this message   

Return to Index

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement