April 18, 2024, 07:38:18 PM

News:

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


Error in the code with gosubs and goto's

Started by Techno, October 28, 2008, 02:11:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Techno

Dear programmer

I try to compile this program that I have written with goto's en gosub's.
How can I written this program structered without goto's en gosub's
It on the elektor book PC ports onder windows 16



$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
DECLARE "kernel32", Sleep(time:int)

CONST BA  = 0x2F8

OPENCONSOLE
DEF ByteArray[3] AS INT
ByteArray = 3, 1, 0, 2
DEF Positie AS STRING

DO
INPUT "Positie", Positie
GOSUB Label1
UNTIL Positie <> ""

DEF U AS INT
DEF X AS INT
DEF S AS INT

LABEL Label1

LABEL Uitvoer
IF(U > X) THEN U++
S = (U % 4)
Out32((BA + 0x04), ByteArray[S])
IF(U = X) THEN RETURN
FOR n = 1 TO 100
NEXT n
GOTO Uitvoer
CLOSECONSOLE


Errror Report
========

Compiling...
StepperMotor.eba
File: C:\StepperMotor.eba (17) Warning: undeclared function 'Label1'
File: C:\StepperMotor.eba (30) RETURN outside of subroutine
Error(s) in compiling C:\StepperMotor.eba

Can someone help me written this code without goto's and gosubs only structered?


Barney

If you bothered to check the help file coming with EBASIC you would have noticed that GOSUB does not work with LABEL. It calls a function with the name you specify after the GOSUB keyword.

This is from the HELP file regarding GOSUB:

Syntax

GOSUB name
GOSUB name(parameters)

Description
Calls a subroutine.  Included for backwards compatibility with other languages.

Parameters
name - Name of subroutine to call
parameters - Comma separated list of parameters

Return value
None

Remarks
It is not necessary to use GOSUB as you can call any subroutine directly by its name.


GOTO on the other hand uses LABEL and can be used as a typical GOTO was used in the older versions of BASIC language.

I suggest you rewrite your program so that it conforms to EBASIC's way of doing things.

Barney

LarryMc

Techno

Read the Languages/Variables/Arrays section of the help file to get your "ByteArray" defined and initialized properly.

Read the Language/Subroutine section of the help file to resolve your "GOSUB Label1" issue.

You never initialized X or U to any start value so your "gosub routine" can never work.

You don't have an end statement so your program would probably crash if it did compile the way you have it right now.
In the General Programming/Text only programs section of the help file there are examples of how to structure a consolewindow program.

You really need to spend some time reading the help file.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library