IonicWind Software

IWBasic => General Questions => Topic started by: Techno on September 23, 2008, 05:15:50 AM

Title: Very strange
Post by: Techno on September 23, 2008, 05:15:50 AM
Dear support

I don't know what this errors main.
Can someone help me what I do wrong with the subscripts of the arrays?



$USE "inpout32.lib"
DECLARE IMPORT, Inp32(PortAddr : WORD), WORD
DECLARE IMPORT, Out32(PortAddr : WORD, PortData : WORD)
DECLARE EXTERN _sscanf(STRING buf, STRING format,...),INT
DECLARE EXTERN sprintf(POINTER p, POINTER p, ...), INT

CONST BA = 0x2F8
'=========================================================================================================='
' Toestand van een sensor opvragen (inlezen)    '
'    '
'Toestand van een schakelaar of een sensor (input) inlezen    '
'De schakelaar of sensor is aangesloten tussen de RTS uitgang die wordt hoog gemaakt, en ingang CTS        '
'Leest de toestand van een schakelaar (sensor) in    '
'Het programma vraagt 2000 maal af en zet de resultaten vervolgens op het beeldscherm        '
'De functie CTS() : toestand van de ingang lezen                                                           '
'=========================================================================================================='


/* Hoofdprogramma */
OPENCONSOLE
DEF Buffer[2000] : CHAR
DEF n : WORD

OUT32 ((BA + 0x04), 2) /* RTS = 1 */
CLS
DO
FOR n = 1 TO 2000 /* CTS : 2000x lezen */
Buffer[n] = CTS()
NEXT n

FOR n = 1 TO 2000
PRINT STR$((Buffer[n])) /* Uitvoer naar scherm */
NEXT n
/* Hoe Delay maken 1000 ms wachten */
UNTIL INKEY$ = ""
/* 2000 ms wachten */
CLOSECONSOLE

SUB CTS(), CHAR
RETURN ((INP32(BA + 0x06) AND 0x10) / 16) /* CTS + read */
ENDSUB



1. How can I create an delay roiutine in ebasic without for loops?

This is the error report:
==============

Compiling...
status_switch.eba
File: E:\Program Files\EBDev\EBCodeArch\Electronics\status_switch.eba (28) subscript wrong type
File: E:\Program Files\EBDev\EBCodeArch\Electronics\status_switch.eba (32) subscript wrong type
Error(s) in compiling "E:\Program Files\EBDev\EBCodeArch\Electronics\status_switch.eba"

With kind regards
Stephane
Title: Re: Very strange
Post by: talun on September 23, 2008, 05:27:05 AM
Hi Stephane,

array in Ebasic are 0 based. From the Ebasic Help:

QuoteIndices start at 0 so the maximum index will be one less than the value specified in the DEF statement.

So the upper index of the array Buffer is 1999 (and not 2000).

bye

Sergio

Title: Re: Very strange
Post by: LarryMc on September 23, 2008, 05:43:46 AM
You defined n as a word and it appears only int can be array index.
change
DEF n : WORD
to
DEF n : INTand see if error goes away.

Larry
Title: Re: Very strange
Post by: Techno on September 23, 2008, 06:03:34 AM
Thanks Larry McCaughn for your quickly response.
I have updated with the corrected syntax en subscripts

Is there an replaced functions in C++ (msvcrt library) or ebasic functions for the pascal functions Keypressed() and Readkey?

With kind regards
Stephane

Title: Re: Very strange
Post by: sapero on September 23, 2008, 06:37:10 AM
from conio.h: getch(), for console only programs.declare extern Readkey alias __getch(),int
declare extern Keypressed alias __kbhit(),int
declare import, Sleep(int time)

print "press a key >"
key = Readkey()
print "you pressed #", key

print "\nnow press one or more keys. You have 2 seconds"
Sleep(2000)

if Keypressed()
print "you pressed ",
while Keypressed()
print "#", Readkey(),
wend
print
else
print "timeout"
endif

' remove all keys from queue
while Keypressed()
Readkey()
wend

' wait for keypress
print "press a key to quit"
Readkey()