Beginner problem

New to FreeBASIC? Post your questions here.
BeginnerST
Posts: 26
Joined: Jun 26, 2016 21:59
Location: Italy

Beginner problem

Postby BeginnerST » Jan 03, 2020 20:49

I can't compile this code with freebasic.
Using VB6 works as expected.

Code: Select all

#lang "fblite"
Option Explicit
Option Base 1

SUB prova(IX AS INTEGER , IY AS INTEGER)

    FOR IX = 1 TO 5
        FOR IY = 1 TO 5
            PRINT "IX=";IX;"  IY=";IY
        NEXT IY
    NEXT IX

    PRINT "INDEX INTERNAL SUB"
    PRINT "IX=";IX;"  IY=";IY

END SUB

'ENTRY POINT
DIM IX AS INTEGER
DIM IY AS INTEGER

CLS
CALL prova(IX , IY)
PRINT "INDEX EXIT SUB"
PRINT "IX=";IX;"  IY=";IY

END
srvaldez
Posts: 2482
Joined: Sep 25, 2005 21:54

Re: Beginner problem

Postby srvaldez » Jan 03, 2020 21:01

it's bad practice to declare the parameters in a function or sub without byval or byref, in this case, it appears that FreeBasic interprets the parameters as arrays

Code: Select all

SUB prova(byval IX AS INTEGER , byval IY AS INTEGER)
fxm
Posts: 9820
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Beginner problem

Postby fxm » Jan 03, 2020 21:08

srvaldez wrote:in this case, it appears that FreeBasic interprets the parameters as arrays
Not exactly.

Extract of the For...Next documentation page:
The iterator must be an intrinsic scalar: only Static/Shared variables and local variables can be used; no other kind can be used, including array elements, UDT members, ByRef parameters or any kind of dereferenced address.

When using the “fblite” dialect, the parameters are passed by default by reference, so the above specification is not applied.
The solution is that proposed above (to force the parameter's passing by value).

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 3 guests