Using INCLUDES, FUNCTIONS PROCEDURES and SUBROUTINES in Oshonsoft

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi, EDIT: Title changed to suit the situation.

I'm working on a program, that is too long, so I need to use INCLUDES.

I've used them before and up to now, have avoided them, as I prefer all of the CODE on one page, but time has come to change.

How is what goes in an INCLUDE chosen? How long etc? I guess CODE that doesn't change goes in them.
C.
 
Last edited:

trebla

Joined Jun 29, 2019
542
For example, you can collect subroutines to different file(s) for leaving main file only for main routine. In PBP INCLUDE directive inserts pointed file text where the INCLUDE is located in main file (after INCLUDE directive).
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
For example, you can collect subroutines to different file(s) for leaving main file only for main routine. In PBP INCLUDE directive inserts pointed file text where the INCLUDE is located in main file (after INCLUDE directive).
Hi T,
Can all subroutines be in the same INCLUDE?
Waht does PBP and directive mean please?
C
 

ericgibbs

Joined Jan 29, 2010
18,766
hi C,
This a clip from the OSH manual.

Include,
Basic source code from an external file can be included to the current program by using INCLUDE directive. Its only argument is a string containing the path to the external .BAS file. This can be the full path or only the file name, if the external file is located in the same folder as the current basic program file. During the compilation process the external basic source will be appended to the current program. Multiple files can be included with separate INCLUDE directives. To maintain the overall basic code structure, it is strongly suggested that the external file contains global declarations, subroutines, procedures and functions, only. Here is one very simple example for the demonstration:

Include "inc1.bas"
Include "inc2.bas"

@jrap
Update:
Do you have a Copy of this OSH doc.?

Will not let me upload!! its only 77kBytes long.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,
This a clip from the OSH manual.

Include,
Basic source code from an external file can be included to the current program by using INCLUDE directive. Its only argument is a string containing the path to the external .BAS file. This can be the full path or only the file name, if the external file is located in the same folder as the current basic program file. During the compilation process the external basic source will be appended to the current program. Multiple files can be included with separate INCLUDE directives. To maintain the overall basic code structure, it is strongly suggested that the external file contains global declarations, subroutines, procedures and functions, only. Here is one very simple example for the demonstration:

Include "inc1.bas"
Include "inc2.bas"
Hi E,
I kind of see.
We have been using the FONT1.bas INCLUDE for a while, I've just got to get used to it, thanks.
C
 

BobaMosfet

Joined Jul 1, 2009
2,110
Hi,
I'm working on a program, that is too long, so I need to use INCLUDES.

I've used them before and up to now, have avoided them, as I prefer all of the CODE on one page, but time has come to change.

How is what goes in an INCLUDE chosen? How long etc? I guess CODE that doesn't change goes in them.
C.
@camerart This may not be directly applicable to your unique situation but in C compilers it works this way:

Header files (include files) are not code files. They are link files that control how much your C file can see into a library that the include (the header file) references. Any .c file that a .h file points at, is a library. That is how they are supposed to be viewed (and how the compiler sees them). They are just not compiled.

For example, if you # include <math.h>, that files only lets you see a little bit of what was in the original math.c file (that may be now in a compiled form as math.lib or math.obj). Many other things may go on in the math library, but you will only know about those things the header file reveals to you.

This is how you control opacity and scope in code. Includes aren't just about organization.
 

trebla

Joined Jun 29, 2019
542
Can all subroutines be in the same INCLUDE?
Waht does PBP and directive mean please?
Directives are commands for compiler/preprcocessor for controlling compile process. They are not BASIC language commands and not compiled for MCU code.

In the INCLUDE file you can have to many subroutines as you need. You can probably write whole program only in include file and INCLUDE this in your main file but it isn't a good practice.

PBP - Pic Basic Pro from MElabs. This is the BASIC compiler i have used for PIC programming, i hope Oshonsoft and PBP syntaxes are close enough to help you in general things. But i believe, inbuilt functions have maybe quite different syntax, so in this area i can't help without studying Oshonsoft documentation properly. It takes time an i suggest you better do this itself because you use this compiler ;)
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Directives are commands for compiler/preprcocessor for controlling compile process. They are not BASIC language commands and not compiled for MCU code.

In the INCLUDE file you can have to many subroutines as you need. You can probably write whole program only in include file and INCLUDE this in your main file but it isn't a good practice.

PBP - Pic Basic Pro from MElabs. This is the BASIC compiler i have used for PIC programming, i hope Oshonsoft and PBP syntaxes are close enough to help you in general things. But i believe, inbuilt functions have maybe quite different syntax, so in this area i can't help without studying Oshonsoft documentation properly. It takes time an i suggest you better do this itself because you use this compiler ;)
Hi T,
Ok, got it.
Regarding using Oshonsoft, I'll just give INCLUDES a try and see what happens. I'm not the best document reader;)
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
Regarding INCLUDES. I made 2x INCLUDES plus a MAIN program, all in the same folder as suggested. It compiled and ran ok, but I couldn't see the simulation, which I rely on. Any sugestions?

I tried posting the 3x files, but am not allowed to?
C
 
Last edited:

jjw

Joined Dec 24, 2013
823
Hi,
Regarding INCLUDES. I made 2x INCLUDES plus a MAIN program, all in the same folder as suggested. It compiled and ran ok, but I couldn't see the simulation, which I rely on. Any sugestions?

I tried posting the 3x files, but am not allowed to?
C
Testing the posting :
It seems that it accepts only one file.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Testing .bas file:
File with .bas extension is not allowed
Hi J,
I always, copy and paste from OSH into Notepad.TXT file, to post, or paste it into INSERT 3x DOTS.
Here is todays short one that doesn't go with that method, here as a JPG.
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
I'm going to post a TXT file using lines from #15 attachment, to find out where it breaks.
C
EDIT: Result of tests in #17
@bertus
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
Adding each line in turn till I got the error messages, all of the above attachments were accepted, but there seems to be a problem with this text: [ XXXXXX ]

I wasn't allowed to post the error text where the XXs are and had to make an image?

test10 is the whole of the of the failed attachment with the error text extracted??
C
 

Attachments

Last edited:

sagor

Joined Mar 10, 2019
903
Best to learn how to insert code. People can't piece together your fragments of code.
One issue is we cannot tell what the maximum size of your string arrays is. Other variable declarations are missing, we cannot tell what is a byte or what is a character other than trying to read fragments of code.
Attach the code by inserting the "code" using the example below:
post.jpg

and insert the text code between the two "code" markers. If the code is too long, insert the different programs in separate "code" inserts or use a second message to add another large segment of code.
Or, make copies of your .BAS files as .TXT files and attach them as individual files in your message, not one line pieces or other segments that have a few lines in it - we can't piece it together.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Best to learn how to insert code. People can't piece together your fragments of code.
One issue is we cannot tell what the maximum size of your string arrays is. Other variable declarations are missing, we cannot tell what is a byte or what is a character other than trying to read fragments of code.
Attach the code by inserting the "code" using the example below:
View attachment 235717

and insert the text code between the two "code" markers. If the code is too long, insert the different programs in separate "code" inserts or use a second message to add another large segment of code.
Or, make copies of your .BAS files as .TXT files and attach them as individual files in your message, not one line pieces or other segments that have a few lines in it - we can't piece it together.
Hi S,
I've tried all you suggest, but can't post, MY CODE. Looking back at the posts, you can see I've returned a TXT file, so that one was ok, but it wasn't my CODE
C.
 

sagor

Joined Mar 10, 2019
903
Also remember that the default string length for Oshonsoft is 16 characters, including CR and LF. If your MSG1 is not declared larger and str_cnt is 3 digits, you will overflow that size in msg1.
 
Top