(02-02-2025, 09:23 PM)sublogic Wrote: Hi all,
New user here, thanks for providing this forum & please bear with me...
I am trying to learn how to build my own external library of functions and/or subroutines.
Here is what I have right now:
Code: (Select All)'$Include: 'mylib.bas'
AddNumbers
Error in message window: "Statement cannot be placed between SUB/FUNCTIONs on current line"
Code: (Select All)' mylib.bas
' Add two numbers. Or don't.
Sub AddNumbers (a, b)
'AddNumbersResult = a + b
'Print "Adding: "; _ToStr$(a); " + "; _ToStr$(b); " = "; _ToStr$(AddNumbersResult)
Print "Hello world."
End Sub
What I've tried so far:
- Adding, removing parens to/from the call to AddNumbers
- Adding, removing parameters to/from the call to AddNumbers - AddNumbers(2,3)
- Adding, removing "as Integer" to/from Sub/function parameters
- Using variables to call the sub/function, rather than literal integers
- Removing spaces between sub/function name and parens
- Converting the sub to function and back again
- Moving the include directive from top to bottom
- Adding a declaration of the sub to the library file
- Changing all function/sub logic to simply "Hello world." just in case
- Browsing the wiki entries for sub, function, include, etc.
The changes I made have changed the error message to say different things, but I haven't once been able to run the program after guessing which changes were required.
Any help is appreciated! Version I'm using is 4.0, Manjaro Linux. I am used to programming in other languages like PHP, Perl, Raku, Object Pascal, and others, but fairly new to this kind of library-call feature in basic dialects.
Very simple solution here, what would you do if the SUB was in the main program and not in an external file?
Most probably you would place the SUBs and FUNCTIONs at the end of the main code, right?
So, now think where your $INCLUDE line must go.
From the $INCLUDE Wiki page:
Quote:Common extensions are .BI (for declarations, usually included in the beginning of a program) or .BM (with SUBs and FUNCTIONs, usually included at the end of a program).From the SUB Wiki page:
Quote:$INCLUDE text library files with needed SUB and FUNCTION procedures can be included in programs after all sub-procedures.
BTW - Welcome to the Forums.
GuiTools, Blankers & other Projects:
https://qb64phoenix.com/forum/forumdisplay.php?fid=32
Libraries & useful Functions:
https://qb64phoenix.com/forum/forumdisplay.php?fid=23
https://qb64phoenix.com/forum/forumdisplay.php?fid=32
Libraries & useful Functions:
https://qb64phoenix.com/forum/forumdisplay.php?fid=23