May 18, 2024, 06:27:31 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Very strange

Started by Techno, September 23, 2008, 05:15:50 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Techno

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

talun

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


LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Techno

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


sapero

September 23, 2008, 06:37:10 AM #4 Last Edit: September 23, 2008, 06:45:51 AM by sapero
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()