Basic course for newbies

Página 10/11
3 | 4 | 5 | 6 | 7 | 8 | 9 | | 11

Por Poltergeist

Champion (278)

imagem de Poltergeist

31-12-2013, 13:03

First things first then: Start with the simple thing: screenhandling is relatively easy in Basic, diskhandling is hard, so I would start with the problem of showing more files than fit on the screen.

First of all: how many files do fit on the screen? Let's say you want to display 5 files per line, and use 20 lines (you could go up to 24, but you might want to display some statusdata, the name of your program, functionkeys on the bottom, et cetera. You can still display 100 files on one screen, and still have some room to spare.

some pseudo code (which you should be able to translate to real basic)
Now, lets set variable AP (which stands for ArrayPointer) to 0.
Display files:
Display files AP to AP+99 on screen

Cursorhandling:
if cursorline >20 then cursorline=20: ap=ap+5: if ap>numberoffiles-99 then ap=ap-5: goto display files else goto displayfiles
if cursorline <0 then cursorline=0: if ap<0 then ap=0: goto display files else goto display files

It's up to you to create some errorhandling, and to determine what file is pointed at, but that should not be to hard. For testing use fill the array FO$ with 1000 different names.

Por NYYRIKKI

Enlighted (5938)

imagem de NYYRIKKI

08-01-2014, 13:34

edoz wrote:
NYYRIKKI wrote:
Manuel wrote:

Edoz:
390 TIME=0:FOR I=0 TO 8:I=TIME:NEXT I
That line makes no sense, please recheck the post I did about TIME. Or explain what you're doing here Smile

You can't blame Edoz here... That was my change... Although this is more like habit, there is a reason behind it: Many times I want to know how fast the routine is actually working and I do that by adding "'" as REM in front of the timing line. Then I make changes to speed things up and remove the REM. How ever I also tend to write RENUM very often, so if I use GOTO on timing line while it is commented out I usually have to fix the linenumber as well... So... in the end it is related more to my coding style than functionality.

At least I was understanding it Big smile .. I use renum also very often indeed!

There is also another trick to get rid of the RENUM problem... You can use ELSE instead of REM in the beginning of line. This will skip the line, but the RENUM will still fix the line numbers. Wink

Por edoz

Prophet (2443)

imagem de edoz

08-01-2014, 13:40

Thanks! Big smile I'm still working on the loader .. but at the moment I'm bit busy to learn symbasic Big smile

Por anonymous

incognito ergo sum (116)

imagem de anonymous

02-11-2014, 01:49

Hello, I think this topic will a useful topic for me. Thanks.

Diskbasic 1.0 - I can't print two types of variables

I'm trying to output a string and an integer. However I'm getting error.

Code:
10 CLS
20 DEFSTR A-Z
30 TESTSTR = "test"
40 PRINT "teststr = " + TESTSTR
50 DEFINT A-Z
60 NUM = 10
70 PRINT "num = "; NUM
80 DEFSTR A-Z
90 ALLSTR = TESTSTR + STR$(NUM)
100 PRINT ALLSTR

Output:
teststr = test
num = 10
Type mismatch in 90
Ok

How can I fix this error?

Por meits

Scribe (6509)

imagem de meits

02-11-2014, 02:01

Variables and strings can only be two characters long and you can't just add a string to a variable...
TESTSTR is being read as TE
STR$ is being read as ST$
NUM is being read as NU
ALLSTR is being read as AL
The error you get is because you add a numeric value (variable) to an alphanumeric value (string)
if the value in STR$ is numeric, you could use the VAL command to read the numeric value in the string as a variable...

Por nikel

Supporter (3)

imagem de nikel

02-11-2014, 04:06

Thank you for quick reply, sorry for double post. This line works fine:

PRINT 1 + VAL(I)

Por Manuel

Ascended (18844)

imagem de Manuel

02-11-2014, 15:45

For those reading: STR$ is actually a function to convert the argument into the string type... So it should not have been in the list posted by Meits.

Por Vampier

Prophet (2397)

imagem de Vampier

16-11-2014, 22:04

haven't posted here in a while. Just a quick example for beginning MSX basic programmers (just pause at the beginning of the movie for the listing)
https://www.youtube.com/watch?v=S8JG42mhc6g

Por NYYRIKKI

Enlighted (5938)

imagem de NYYRIKKI

17-11-2014, 05:31

Very nice one, Vampier! Now when I try to remember back, exactly these kind of easy animations for MSX2 were one of the reasons I totally felt in love with MSX-BASIC!

TIP: SIN and COS take angle parameter as radians. Full circle in radians is same as ATN (1)*8 in BASIC.
Excercise: Use this information to fix the "bug" seen in video.

Por Poltergeist

Champion (278)

imagem de Poltergeist

17-11-2014, 09:28

@Vampier: Nice example
@nikel: Meits isn't completely right. He is right about the length of the variablenames. Only the first two are used, so teststr would be the same as testnum (for example)

STR$ is a basic command to convert a numerical value to a string. You are using it right, but the error is not just in line 90: you're already starting wrong.

First you're using a defstr A-Z, which simply says: every variable I'm using is going to be a string. You then fill the variable teststr with a string. This works.
Then you're redefining all variables as an integer. You give num the value of 10. This also works, but while redefining all variables, you loose the value of teststr. If you would insert line 75 with print teststr, it would give a 0, not test
After that, you are redefining all variables again as strings. You're loosing the value of Num (which is now "" (emtpy), because it's a string)
In line 90, you're trying to convert the variable num (which is a string) to a string. str$ needs a numerical value, and num is a string. Hence the error

What I would do: Loose the defint en defstr command. For strings, use the $ to indicate a string as variablename (like teststr$="test") and % for the integers (e.g. num%=10)

not tested example:

10 CLS
30 TESTSTR$ = "test"
40 PRINT "teststr = " + TESTSTR$
60 NUM% = 10
70 PRINT "num = "; NUM%
90 ALLSTR$ = TESTSTR$ + STR$(NUM%)
100 PRINT ALLSTR$
Página 10/11
3 | 4 | 5 | 6 | 7 | 8 | 9 | | 11