May 09, 2024, 11:40:56 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Array subscripts errors

Started by Techno, September 27, 2008, 12:59:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Techno

Dear Support

I try to find the solution for the subscript problems.
Can please somebody help me what the problem is
How can I an graphic output created in eba?
Sapero can you help me how I can an graphic output
Sorry but my English is not so good



$USE "Inpout32.lib"
$USE "i2c_lpt.lib"
$INCLUDE "i2c_lpt.inc"
DECLARE IMPORT, Sleep(int time)


GLOBAL m
GLOBAL n
GLOBAL Buffer
'DEF m, n AS WORD
'DEF Buffer[1:5000] AS CHAR

$MAIN
OPENCONSOLE
DEF m, n AS WORD
DEF Buffer[4999] AS CHAR
   
CLS
Serie()
'GraphOutput()
CLOSECONSOLE
END

SUB Parallel_Output(DataWoord AS CHAR)
    i2c_Start()
    i2c_Write(32 * 2 + 0) 'adres 32, schrijven
    i2c_Write(DataWoord)
    i2c_Stop()
RETURN
ENDSUB

SUB Parallel_Input(), CHAR
'DEF ret : CHAR
    i2c_Start()
    i2c_Write(32 * 2 + 1) 'adres 32, lezen
    i2c_NoAck()
    i2c_Stop()
RETURN i2c_Read()
ENDSUB

SUB Serie()
Parallel_Output(0xFF)
i2c_Start()
i2c_Write(32 * 2 + 1) 'adres 32, lezen
FOR n = 1 TO 100
Buffer[n] = Parallel_Input() '100 x data inlezen
i2c_Ack() 'Ontvangst bevestigen
Sleep(10) 'wacht 10 ms
NEXT n
RETURN
ENDSUB

SUB GraphOutput()
DEF DataWoord AS CHAR

'GraphDriver := Detect
'InitGraph (GraphDriver, GraphMode, ' ')
'SetLineStyle (1,2,1)

FOR n = 1 TO 8
'Line (0, n * 20, 700, n * 20)
NEXT n

'SetLineStyle (0, 2, 1)
DataWoord = 1

FOR n = 1 TO 8
FOR m = 1 TO 700
'Line(m - 1,n * 20 - 12 * ((Buffer[m - 1] & DataWoord) >> DataWoord),
'     m, n * 20 - 12 * ((Buffer[n] & DataWoord) >> DataWoord));
NEXT m
DataWoord = DataWoord << 1
NEXT n

DO : UNTIL INKEY$ <> ""
'CloseGraph()
RETURN
ENDSUB

Error Report:
========

Compiling...
PCF8574_Logic_Analyser.eba
File: E:\Program Files\EBDev\projects\Electronics\PCF8574_Logic_Analyser.eba (46) subscript wrong type
Error(s) in compiling "E:\Program Files\EBDev\projects\Electronics\PCF8574_Logic_Analyser.eba"



sapero

There is a limitation for array indexing - the N in Buffer[n] must be of type INT or UINT, not a WORD.
ChangeOPENCONSOLE
DEF m, n AS WORD
toOPENCONSOLE
DEF m, n AS INT

Techno

Sapero

It give the same errors, Can you give the solution
I have added graphic functions



$USE "Inpout32.lib"
$USE "i2c_lpt.lib"
$INCLUDE "i2c_lpt.inc"
DECLARE IMPORT, Sleep(int time)


GLOBAL m
GLOBAL n
GLOBAL Buffer
DEF m, n AS WORD
DEF Buffer[4999] AS INT

SUB Main()
SELECT @MESSAGE
CASE @IDINITDIALOG
Serie()
GraphOutput()
CASE @IDCLOSEWINDOW
run = 0
ENDSELECT
RETURN
ENDSUB

SUB Parallel_Output(DataWoord AS CHAR)
    i2c_Start()
    i2c_Write(32 * 2 + 0) 'adres 32, schrijven
    i2c_Write(DataWoord)
    i2c_Stop()
RETURN
ENDSUB

SUB Parallel_Input(), INT
'DEF ret : CHAR
    i2c_Start()
    i2c_Write(32 * 2 + 1) 'adres 32, lezen
    i2c_NoAck()
    i2c_Stop()
RETURN i2c_Read()
ENDSUB

SUB Serie()
Parallel_Output(0xFF)
i2c_Start()
i2c_Write(32 * 2 + 1) 'adres 32, lezen
FOR n = 1 TO 100
Buffer[n] = Parallel_Input() '100 x data inlezen
i2c_Ack() 'Ontvangst bevestigen
Sleep(10) 'wacht 10 ms
NEXT n
RETURN
ENDSUB

SUB GraphOutput()
DEF DataWoord AS CHAR
DEF hWnd AS WINDOW

OPENWINDOW hWnd,0,0,640,220,@SIZE|@MINBOX|@MAXBOX,0,"Lines",&main
CENTERWINDOW hWnd

FOR n = 1 TO 8
LINE hWnd, 0, n * 20, 700, n * 20, RGB(255,0,0)
NEXT n

SETLINESTYLE (hWnd, @LSDASH, 1)
DataWoord = 1

FOR n = 1 TO 8
FOR m = 1 TO 700
LINE m - 1, n * 20 - 12 * ((Buffer[m - 1] & DataWoord) >> DataWoord), m, n * 20 - 12 * ((Buffer[n] & DataWoord) >> DataWoord)
NEXT m
DataWoord = DataWoord << 1
NEXT n

DO : UNTIL INKEY$ <> ""
run = 1
WAITUNTIL run = 0
CLOSEWINDOW hWnd
RETURN
ENDSUB

Error Report:
========

Compiling...
PCF8574_Logic_Analyser.eba
File: E:\Program Files\EBDev\projects\Electronics\PCF8574_Logic_Analyser.eba (46) subscript wrong type
File: E:\Program Files\EBDev\projects\Electronics\PCF8574_Logic_Analyser.eba (69) wrong number of parameters
Error(s) in compiling "E:\Program Files\EBDev\projects\Electronics\PCF8574_Logic_Analyser.eba"



Kind Regards
Stephane

I like EBASIC

      

sapero

September 27, 2008, 02:15:45 PM #3 Last Edit: September 27, 2008, 04:14:42 PM by sapero
Stephane, please read again my response, and change your line 11 (in your second post) toDEF m, n AS INT


This is correct:DEF X AS INT
X = 0
array[X] = 0


This is not corrent (subscript wrong type) :DEF X AS WORD
X = 0
array[X] = 0


But this one will be OK:DEF X AS WORD
X = 0
array[X+0] = 0

Techno

Sapero,

I have that corrected but it give my one compile time error in this line:



$USE "Inpout32.lib"
$USE "i2c_lpt.lib"
$INCLUDE "i2c_lpt.inc"
DECLARE IMPORT, Sleep(int time)


GLOBAL m
GLOBAL n
GLOBAL Buffer
DEF m, n AS WORD
DEF Buffer[4999] AS WORD

SUB Main()
SELECT @MESSAGE
CASE @IDINITDIALOG
Serie()
GraphOutput()
CASE @IDCLOSEWINDOW
run = 0
ENDSELECT
RETURN
ENDSUB

SUB Parallel_Output(DataWoord AS CHAR)
    i2c_Start()
    i2c_Write(32 * 2 + 0) 'adres 32, schrijven
    i2c_Write(DataWoord)
    i2c_Stop()
RETURN
ENDSUB

SUB Parallel_Input(), WORD
'DEF ret : CHAR
    i2c_Start()
    i2c_Write(32 * 2 + 1) 'adres 32, lezen
    i2c_NoAck()
    i2c_Stop()
RETURN i2c_Read()
ENDSUB

SUB Serie()
Parallel_Output(0xFF)
i2c_Start()
i2c_Write(32 * 2 + 1) 'adres 32, lezen
FOR n = 1 TO 100
Buffer[n + 0] = Parallel_Input() '100 x data inlezen
i2c_Ack() 'Ontvangst bevestigen
Sleep(10) 'wacht 10 ms
NEXT n
RETURN
ENDSUB

SUB GraphOutput()
DEF DataWoord AS CHAR
DEF hWnd AS WINDOW

OPENWINDOW hWnd,0,0,640,220,@SIZE|@MINBOX|@MAXBOX,0,"Lines",&main
CENTERWINDOW hWnd

FOR n = 1 TO 8
LINE hWnd, 0, n * 20, 700, n * 20, RGB(255,0,0)
NEXT n

SETLINESTYLE (hWnd, @LSDASH, 1)
DataWoord = 1

FOR n = 1 TO 8
FOR m = 1 TO 700
LINE hWnd, m - 1, n * 20 - 12 * ((Buffer[m - 1] & DataWoord) >> DataWoord), m, n * 20 - 12 * ((Buffer[n + 0] & DataWoord) >> DataWoord)
NEXT m
DataWoord = DataWoord << 1
NEXT n

DO : UNTIL INKEY$ <> ""
run = 1
WAITUNTIL run = 0
CLOSEWINDOW hWnd
RETURN
ENDSUB

Compiling...
PCF8574_Logic_Analyser.eba
File: E:\Program Files\EBDev\projects\Electronics\PCF8574_Logic_Analyser.eba (69) wrong number of parameters
Error(s) in compiling "E:\Program Files\EBDev\projects\Electronics\PCF8574_Logic_Analyser.eba"

When I remove this line, then it comes with this link error:
====================================

Compiling...
PCF8574_Logic_Analyser.eba
No Errors

Linking...
Emergence Linker v1.11 Copyright ÂÃ,© 2006 Ionic Wind Software
Unresolved external _window_list
Error: Unresolved extern _window_list ===> What that mains ????
Error(s) in linking E:\Program Files\EBDev\projects\Electronics\PCF8574_Logic_Analyser.exe



Kind Regards
Stephane

pistol350

September 27, 2008, 03:16:28 PM #5 Last Edit: September 27, 2008, 03:29:27 PM by pistol350
QuoteLinking...
Emergence Linker v1.11 Copyright ÂÃ,© 2006 Ionic Wind Software
Unresolved external _window_list
Error: Unresolved extern _window_list ===> What that mains ????
Error(s) in linking E:\Program Files\EBDev\projects\Electronics\PCF8574_Logic_Analyser.exe

Hi Stephane!

You surely have that error because you compiled your source as console. You have to compile it as WINDOW

By the way, about your error with the line statement

You forgot a parameter that is the window handle  :D

so this will work.

LINE hwnd,m - 1, n * 20 - 12 * ((Buffer[m - 1] & DataWoord) >> DataWoord), m, n * 20 - 12 * ((Buffer[n] & DataWoord) >> DataWoord)


EDIT : By the way, you should change your code a bit as even after getting the code compile there is still errors as the windows does not appear.
I guess it's because you call it in your subroutine Main() instead of creating it before.
You will have to change that to get your code working.
Regards,

Peter B.

Techno

Pistol

Can you explean it with an example, I don't understand you

Thanks
Stephane

pistol350

Hi Stephane!
What i meant is for intance by changing your code the way below, you could get the window displayed.
But i can't help you much from that point as i do not know exactly what your program is supposed to achieve.
Basicly i know that it should draw a graphic based on data received from the ports (actually, not so sure ).

There are a few lines that i don't understand. for instance, i'm not sure to get what that is supposed to do.
DataWoord = DataWoord << 1


$USE "Inpout32.lib"
$USE "i2c_lpt.lib"
$INCLUDE "i2c_lpt.inc"
DECLARE IMPORT, Sleep(int time)

DEF hWnd AS WINDOW
GLOBAL m
GLOBAL n
GLOBAL Buffer
DEF m, n, run AS INT
DEF Buffer[4999] AS INT


OPENWINDOW hWnd,0,0,640,220,@SIZE|@MINBOX|@MAXBOX,0,"Lines",&main
CENTERWINDOW hWnd

run = 1
WAITUNTIL run = 0
CLOSEWINDOW hWnd


SUB main()
SELECT @MESSAGE
CASE @IDINITDIALOG
Serie()
GraphOutput()
CASE @IDCLOSEWINDOW
run = 0
ENDSELECT
RETURN
ENDSUB

SUB Parallel_Output(DataWoord AS CHAR)
    i2c_Start()
    i2c_Write(32 * 2 + 0) 'adres 32, schrijven
    i2c_Write(DataWoord)
    i2c_Stop()
RETURN
ENDSUB

SUB Parallel_Input(), INT
'DEF ret : CHAR
    i2c_Start()
    i2c_Write(32 * 2 + 1) 'adres 32, lezen
    i2c_NoAck()
    i2c_Stop()
RETURN i2c_Read()
ENDSUB

SUB Serie()
Parallel_Output(0xFF)
i2c_Start()
i2c_Write(32 * 2 + 1) 'adres 32, lezen
FOR n = 1 TO 100
Buffer[n] = Parallel_Input() '100 x data inlezen
i2c_Ack() 'Ontvangst bevestigen
Sleep(10) 'wacht 10 ms
NEXT n
RETURN
ENDSUB

SUB GraphOutput()
DEF DataWoord AS CHAR

FOR n = 1 TO 8
LINE hWnd, 0, n * 20, 700, n * 20, RGB(255,0,0)
NEXT n

SETLINESTYLE (hWnd, @LSDASH, 1)
DataWoord = 1

FOR n = 1 TO 8
FOR m = 1 TO 700
LINE hwnd,m - 1, n * 20 - 12 * ((Buffer[m - 1] & DataWoord) >> DataWoord), m, n * 20 - 12 * ((Buffer[n] & DataWoord) >> DataWoord)
NEXT m
DataWoord = DataWoord << 1
NEXT n
RETURN
ENDSUB
Regards,

Peter B.

aurelCB

September 28, 2008, 12:12:18 PM #8 Last Edit: September 28, 2008, 01:21:37 PM by aurelCB
Is this some kind of osciloscope wich print voltage pick?
I playing with code(in CB) and i have this result(just picture ,nothing else).
Is your program window look like on image?I'm just courius...