Using string function [SOLVED]

New to FreeBASIC? Post your questions here.
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Using string function [SOLVED]

Post by Trinity »

Hi ,
Sorry , I am completely new to FreeBASIC and all it's defining , declaring of this and that and so on, and it also seem as if I am having problems interpreting what is written in the manual itself , so I am asking for help (will most likely be back for help many times here before I understand FreeBASIC) .

As entry point I am trying to understand most basics like declaring variables, arrays and so on and using screen and i/O and for that I want to use among other strings and subs so I can call on stuff rather than having to rewrite stuff .

In the FBWiki it say on page : KeyPgStringFunction : https://www.freebasic.net/wiki/wikka.ph ... ngFunction
declare function String ( byval count as integer, byref ch as const string ) as string
So I have tried to adapt that code and put it into a sub program like this :

Code: Select all

sub subexample
Declare Function mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String
charstring="H"
count=5
print mystring1(count,charstring)
end sub 

But all I can get from compiler are these errors :
error 60: Illegal inside functions, found 'Declare' in 'Declare Function mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String'
error 41: Variable not declared, charstring in 'charstring="H"'
error 41: Variable not declared, count in 'count=5'
error 41: Variable not declared, mystring1 in 'print mystring1(count,charstring)'


I also consulted : FBWiki : KeyPgDeclare : https://www.freebasic.net/wiki/wikka.ph ... yPgDeclare
which says :
Declare Function name [ param_list ] [ Byref ] As return_type
Declare Function sum( As Integer, As Integer ) As Integer

which to me only show to support that ccde is OK

So I honestly do not understand all this since I copied from FBWiki and have tried my best to adapt .
I know that I must be look stupid but like I explained above I seem to have a problem understanding how to interpret the manual , so if someone could please point me to what I appear to not understand that I would be glad for the assistance.


EDIT ! :

OK , so with a little help from a friend a found out that I had misunderstood the manual .
I thought that when it said "Declare Function mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String" then it also declared "count As Integer" and "charstring As Const String"

but apparently not , so now my code looks like this :

Code: Select all

DIM charstring as String
DIM count as Integer
Declare Function mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String
charstring="H"
count=5
print mystring1(count,charstring)
And the only problem now is a freaking linking error , so I have to find out what and how to link .
( linking failed: 'C:\PROGRA~2\~1\~1\bin\win32\ld.exe' terminated with exit code 1 )

After spending a lot of time reading in the manual about header files and what to link that it looks as that part is going to be a major pain in the butt because I have not found anywhere any clear description of what to link to in header in which situation. I mean as far as I can see then one have to know in advance what to link when !!!! ?????

In this case I tried to use :
#include "string.bi"
#include "fbgfx.bi"


So code now looks like this :

Code: Select all

#include "string.bi"
#include "fbgfx.bi"

DIM charstring as String
DIM count as Integer
Declare Function mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String
charstring="H"
count=5
print mystring1(count,charstring)
but that gives same linking error anyway !!!! ???????
Last edited by Trinity on Sep 22, 2017 8:52, edited 1 time in total.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Using string function

Post by Josep Roca »

Use this and the linker won't complain:

Code: Select all

DIM charstring as String
DIM count as Integer
charstring="H"
count=5
print string(count,charstring)
Obviously, you don't have understood DECLARE. It is used to declare a prototype of a function or procedure.

With Declare Function mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String, you're defining a prototype for the function mystring1, but where is the code for that function?
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Using string function

Post by Josep Roca »

Just declaring a function does nothing. You also have to write code that implements that function, e.g.:

Code: Select all

Declare Function mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String

FUNCTION mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String
   FUNCTION = string(count, charstring)
END FUNCTION

DIM charstring as String
DIM count as Integer
charstring="H"
count=5
print mystring1(count,charstring)

PRINT
PRINT "Press any key..."
SLEEP
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Using string function

Post by Josep Roca »

BTW the names of the variables don't need to be the same that the parameters of the function. This also works.

Code: Select all

Declare Function mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String

FUNCTION mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String
   FUNCTION = string(count, charstring)
END FUNCTION

DIM s as String
DIM c as Integer
s="H"
c=5
print mystring1(c,s)

PRINT
PRINT "Press any key..."
SLEEP
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: Using string function

Post by Trinity »

Josep Roca wrote:Use this and the linker won't complain:

Code: Select all

DIM charstring as String
DIM count as Integer
charstring="H"
count=5
print string(count,charstring)
Obviously, you don't have understood DECLARE. It is used to declare a prototype of a function or procedure.

With Declare Function mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String, you're defining a prototype for the function mystring1, but where is the code for that function?
Thank you very much Joseph for helping me , I am very glad that you did , and YES , of course you are right that I do not understand DECLARE . But I am a total beginner at this dialect of BASIC (my experience has been TI-99/4A Extended BASIC) so all that I can do is use the manual for what I want to use and the manual for STRING (Function) uses DECLARE : (ref. https://www.freebasic.net/wiki/wikka.ph ... ngFunction ) :
Syntax : declare function String ( byval count as integer, byref ch as const string ) as string
in connection with example :
Examples:
Print String( 4, 69 ) '' prints "EEEE"
Print String( 5, "Indeed" ) '' prints "IIIII"
End 0


Sure I have a problem getting a full grasp of this but at least I use the manual/Wiki and at least I can see that I have a problem getting full advantage of the manual , but you know what , I had a C programmer look in the manual for me and he didn't catch the error either , so what am I supposed to do other than ask here ?

Anyway , I am *of course* very grateful for any help given , I would just like people to understand that maybe it is not so easy when confronted with this dialect of BASIC for the first time - I have been stuck with a much older BASIC for many years .

Thank you very much !
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: Using string function

Post by Trinity »

Josep Roca wrote:Just declaring a function does nothing. You also have to write code that implements that function, e.g.:

Code: Select all

Declare Function mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String

FUNCTION mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String
   FUNCTION = string(count, charstring)
END FUNCTION

DIM charstring as String
DIM count as Integer
charstring="H"
count=5
print mystring1(count,charstring)

PRINT
PRINT "Press any key..."
SLEEP
OK , thank you very much for that explanation :-)
And just to clarify , then did you forget to add the 1 in the FUNCTION = string(count, charstring) -> FUNCTION = string1(count, charstring) ?
And what is exactly the purpose of the use of the DECLARE Function as they use in the manual , if I do not have to use it ?
(yes , I did understand that you wrote Prototype , but they did not mention that in the manual for STRING (Function) and I searched the manual that comes with the compiler and the term Prototype does not show up ! ? ) (sorry if I seem very dense to you and others)
I am very grateful for you time and explanation , and I am eager to understand but you just told me that I did not have to use it ?
Josep Roca wrote:BTW the names of the variables don't need to be the same that the parameters of the function. This also works.

Code: Select all

Declare Function mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String

FUNCTION mystring1 ( ByVal count As Integer, ByRef charstring As Const String ) As String
   FUNCTION = string(count, charstring)
END FUNCTION

DIM s as String
DIM c as Integer
s="H"
c=5
print mystring1(c,s)

PRINT
PRINT "Press any key..."
SLEEP
Thank you for that explanation :-)
Just to clarify then in technical terms that means then variable names in the Function declaration are local variable names and not global ?
Last edited by Trinity on Sep 20, 2017 17:43, edited 1 time in total.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Using string function

Post by Josep Roca »

Declares are used to define prototypes for functions that you implement (with code) or to call external functions that reside in a DLL or library.

String is an intrinsic function implemented in the compiler. You don't have to write a declare to use it. The declare that appears in the documentation is for reference, to show you how to use it. I understand that this may be confusing for a beginner, but such is life. The beginnings are always difficult. If you persevere, one day you will laugh remembering it.
Just to clarify then in technical terms that means then variable names in the Function declaration are local variable names and not global ?
]

They are placeholders, not variables. Change them and it still will work, e.g.

Code: Select all

Declare Function mystring1 ( ByVal wall As Integer, ByRef street As Const String ) As String

FUNCTION mystring1 ( ByVal trinity As Integer, ByRef trinitystring As Const String ) As String
   FUNCTION = string(trinity, trinitystring)
END FUNCTION

DIM s as String
DIM c as Integer
s="H"
c=5
print mystring1(c,s)

PRINT
PRINT "Press any key..."
SLEEP
And just to clarify , then did you forget to add the 1 in the FUNCTION = string(count, charstring) -> FUNCTION = string1(count, charstring) ?
No, I don't. The name of the FreeBasic intrinsic function is string, not string1.

As it is an intrinsic function implemented in the compiler, you don't need a declare to use it.

Code: Select all

DIM s as String
DIM c as Integer
s="H"
c=5
print string(c,s)

PRINT
PRINT "Press any key..."
SLEEP
or just

Code: Select all

print string(5,"H")

PRINT
PRINT "Press any key..."
SLEEP
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: Using string function

Post by Trinity »

Josep Roca wrote:Declares are used to define prototypes for functions that you implement (with code) or to call external functions that reside in a DLL or library.

String is an intrinsic function implemented in the compiler. You don't have to write a declare to use it. The declare that appears in the documentation is for reference, to show you how to use it. I understand that this may be confusing for a beginner, but such is life. The beginnings are always difficult. If you persevere, one day you will laugh remembering it.
Just to clarify then in technical terms that means then variable names in the Function declaration are local variable names and not global ?
]

They are placeholders, not variables. Change them and it still will work, e.g.

Code: Select all

Declare Function mystring1 ( ByVal wall As Integer, ByRef street As Const String ) As String

FUNCTION mystring1 ( ByVal trinity As Integer, ByRef trinitystring As Const String ) As String
   FUNCTION = string(trinity, trinitystring)
END FUNCTION

DIM s as String
DIM c as Integer
s="H"
c=5
print mystring1(c,s)

PRINT
PRINT "Press any key..."
SLEEP
And just to clarify , then did you forget to add the 1 in the FUNCTION = string(count, charstring) -> FUNCTION = string1(count, charstring) ?
No, I don't. The name of the FreeBasic intrinsic function is string, not string1.

As it is an intrinsic function implemented in the compiler, you don't need a declare to use it.

Code: Select all

DIM s as String
DIM c as Integer
s="H"
c=5
print string(c,s)

PRINT
PRINT "Press any key..."
SLEEP
or just

Code: Select all

print string(5,"H")

PRINT
PRINT "Press any key..."
SLEEP
Thank you very much for all your clarifications :-)

Excerpt :
Josep Roca wrote: I understand that this may be confusing for a beginner, but such is life. The beginnings are always difficult. If you persevere, one day you will laugh remembering it.
Yes , you are right , but is only through the patience and generous contributions from others such as yourself that one will ever get a chance of understanding stuff like this if one starts from where I do. (Believe it or not but my experience in TI-99/4A Extended BASIC has been far above average - I even found a logic execution error in the language that no one else had found through many years - but none of that helps me here as it is in a ball game that has little reference here)

But I am very grateful for you taking your time to contribute to my education in FreeBASIC here .
Thank you :-) , I will do my best to see that your time has not been wasted :-)
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Using string function

Post by MrSwiss »

A simple example to show two methods, to declare the same Function (or Sub for that matter):
1) with identifiers:

Code: Select all

Declare Function Add2(ByVal df1 As Double, ByVal df2 As Double) As Double
2) without identifiers:

Code: Select all

Declare Function Add2(ByVal As Double, ByVal As Double) As Double
They are one and the same, to the compiler, it only needs to know the Type(s) of the variables used.
(btw: ByVal is default passing method, this means, you don't have to write it explicitly, however, it is
considered good practice, to write them out. Prevents compiler warnings also ...)

And following is a possible implementation (which must have the identifiers, always):

Code: Select all

Function Add2(ByVal df1 As Double, ByVal df2 As Double) As Double
    Return df1 + df2    ' or one of the alternatives, below (currently "commented out") 
    'Function = df1 + df2    ' or the Functions *Name*
    'Add2 = df1 + df2
End Function
Many ways to skin a cat ;-)
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: Using string function

Post by Trinity »

MrSwiss wrote:A simple example to show two methods, to declare the same Function (or Sub for that matter):
1) with identifiers:

Code: Select all

Declare Function Add2(ByVal df1 As Double, ByVal df2 As Double) As Double
2) without identifiers:

Code: Select all

Declare Function Add2(ByVal As Double, ByVal As Double) As Double
They are one and the same, to the compiler (it only needs to know the Type(s) of the variables used.
(btw: ByVal is default passing method, this means, you don't have to write it explicitly, however, it is
considered good practice, to write them out. Prevents compiler warnings also ...)

And following is a possible implementation (which must have the identifiers, always):

Code: Select all

Function Add2(ByVal df1 As Double, ByVal df2 As Double) As Double
    Return f1 + df2    ' or one of the alternatives, below (currently "commented out") 
    'Function = f1 + df2    ' or the Functions *Name*
    'Add2 = f1 + df2
End Function
Many ways to skin a cat ;-)
Thank you very much for your kind help.
I must confess that I feel a bit overwhelmed and that the whole concept of declaring functions is bit above me now , and I am still struggling with stuff even more basic to me. but I have saved your code to drive and will use it as help when I reach the point of being able to work with declaring functions :-)
Thank you very much :-)
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Using string function

Post by MrSwiss »

Trinity wrote:I must confess that I feel a bit overwhelmed and that the whole concept of declaring functions ...
The concept is easy to understand, if you consider the fact that FB's (short for FreeBASIC) compiler does only one pass (single pass compiler).
Therefore, whenever you are calling the Sub/Function (in code, e.g. Main) before it is implemented, you're forced to write a *forward reference*, aka: a "Define" above the code, making the first call (to it). This enables you to implement procedures (Sub or Function) after Main-code ...
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: Using string function

Post by Trinity »

MrSwiss wrote:
Trinity wrote:I must confess that I feel a bit overwhelmed and that the whole concept of declaring functions ...
The concept is easy to understand, if you consider the fact that FB's (short for FreeBASIC) compiler does only one pass (single pass compiler).
Therefore, whenever you are calling the Sub/Function (in code, e.g. Main) before it is implemented, you're forced to write a *forward reference*, aka: a "Define" above the code, making the first call (to it). This enables you to implement procedures (Sub or Function) after Main-code ...
Thank you !
Yes between your explanation and Joseph's in my "Help using On...Goto and Select Case and SUB needed" thread then the concept of the necessity of a *forward reference* in the manner you describe has become much more clear :-)
But my "problem" with being "overwhelmed" by Function and Declare is more a simple matter of having to understand what they are and what they are used for. (insert one of those little icons that tells that I am confused , here)

The path I am taking trying to learn FreeBasic (which I by the way mainly do because I discovered the locate command - and later saw a lot of other nice features) is a path where I try to learn what I consider the most basic first (above baby stuff like e.g. print and Hello World of course) , and that is for me first and foremost most basic use of variables and I/O using screen and to be able to write any real programs I also have had to try to understand the most basic program control other that IF THEN (which I frankly hardly have bothered to look at yet as I consider it a lesser problem) - referring to my venture into trying to get a better grasp of using On...Goto and Select Case and SUB , which for me are very needed skills .
I will also soon have to look at DATA , READ and RESTORE......
Of course I understand if other people could possibly find room for criticizing my learning priorities but while I will happily accept comments and help on understanding what ought to be priorities then of course it is I that are going to do the stuff at my dwelling and not others so as starting point I am trying to find my way as best I can :-)

Anyway , while being forced to deal with Function and Declare then it is not stuff that I shall pretend to really understand much of what is yet.

But thank you very much , I will keep your explanations for when I am forced to take a closer look at Function and Declare :-) (which could be any time really - I mean I understand so little about FB that I do not know what I do not know or what I have to know when ;-) :-D
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Using string function

Post by MrSwiss »

Trinity wrote:But my "problem" with being "overwhelmed" by Function and Declare is more a simple matter of having to understand what they are and what they are used for.
OK, look at something simple to start with:

Code: Select all

' program to display current time (on console, no graphics)
Locate 1, 72    ' right/top corner
Print Time    ' outputs a string (currert Time in HH:MM:SS)
Sleep    ' prevent immediate closing of console, until you press a key (any numeric/character)
However, this works only once. The Time doesn't ever update ...

Second try update the Time in a loop:

Code: Select all

' program to display current time (on console, no graphics)
' we need a string variable to check for change (and initialize it straight away)
Dim As String cTime = Time    ' Time is a KeyWord (built in Function) outputs a string

' output without waiting for change (once only)
Locate 1, 72    ' right/top corner
Print cTime    ' outputs a string (current Time in HH:MM:SS)

' start main-loop
Do
    If cTime <> Time Then    ' only executed on change
        cTime = Time    ' fetch updated Time (and store it)
        Locate 1, 72    ' right/top corner
        Print cTime    ' outputs a string (current Time in HH:MM:SS)
    End If
    Sleep 100, 1    ' wait 100mS
Loop Until Len(InKey)    ' if user presses a key ... program ends
Sub(s)/Function(s) as well as Macros etc. are either FB *KeyWords*, which give in return a specified result
(for all those, consult the manual). You should start by learning those first.

Alternative: your own, self written procedures, that are used to *extend the FB-Language*.
You are in full control of: what goes in (parameters) and what comes back (Functions mostly).
A Sub differs in that it normally isn't producing a result (apart from e.g. prints something to screen).
There are exclusions to the rules (but that would go to deep, currently).

Please don't repost the whole lot, just the relevant parts of it (saving Forum space).
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: Using string function

Post by Trinity »

MrSwiss wrote:
Trinity wrote:But my "problem" with being "overwhelmed" by Function and Declare is more a simple matter of having to understand what they are and what they are used for.
OK, look at something simple to start with:

Code: Select all

Code removed to save forum space as requested !
However, this works only once. The Time doesn't ever update ...
Second try update the Time in a loop:

Code: Select all

Code removed to save forum space as requested !
First of all thank you very much for your very kind and generous attitude and for the annotated code (I consider it very generous to take the time to feed a new user annotated code that is explained line by line - I don't know if it were a copy and paste job or written from scratch but I appreciate it the same anyway , thank you !) .

Your annotated code was very clearly described and very easy to understand and explained the code in a manner that most people that are willing to do an effort themselves ought to understand.

So let me see.... It ought to be clear to anyone that I am grateful for the help that I receive and I do not want to be impolite nor do I want to put you down but I have to point out to you that while the code you wrote was extremely clear to me then your motive for code block 1 vs code block 2 are less clear to me. Yes! , I did gather that Time is a *KeyWord*" for a "Function" in FB and your code also gives a very accessible and clear demo of the function Time which in turn gives an entry way to getting to understand the FB Function time.
But if you wanted to teach me or bring anything else to my attention besides that then it might have escaped me (?).
MrSwiss wrote:Sub(s)/Function(s) as well as Macros etc. are either FB *KeyWords*, which give in return a specified result
(for all those, consult the manual). You should start by learning those first.
Hmmm , I know the the name that per standard are used for a number of "built in" functions which helps me when I have to try to adapt to FB , here is a list of functions of which I used to use some regularly and the other I knew of :

Code: Select all

The following briefly discusses each built-in function.
( Ref. :   http://www.99er.net/files/TI%20Extended%20Basic%20-%20Linked.pdf   )
Function                            Value Returned and Comments
ABS  :  Absolute value of a numeric expression.
ASC  :  The numeric ASCII code of the first character of a string expression.
ATN  : Trigonometric arctangent of a numeric expression given in radians.
CHR$ : Character that corresponds to an ASCII code.
COS  :  Trigonometric cosine of a numeric expression given in radians. 
EOF  : End-of-file condition of a file.
EXP   : Exponential value (e^x) of a numeric expression.
INT  :  Integer value of a numeric expression.
LEN  : Number of characters in a string expression.
LOG   : Natural logarithm of a numeric expression.
MAX : Larger of two numeric expressions.
MIN  : Smaller of two numeric expressions.
PI  :  p with a value of 3.141592654.
POS  :  Position of the first occurrence of one string expression within another.
REC  :  Current record position in a file.
RND  : Random number from 0 to 1.
RPT$  : String expression equal to a number of copies of a string expression concatenated together.
SEG$  :  Substring of a string expression, starting at a specified point in that string and ending after a certain number of characters. 
SGN   : Sign of a numeric expression.
SIN  :  Trigonometric sine of a numeric expression given in radians. 
SQR  :  Square root of a numeric expression.
STR$  :  String equivalent of a numeric expression.
TAB   :  Position for the next item in the print-list of PRINT, PRINT...USING, DISPLAY, or DISPLAY...USING.
TAN   : Trigonometric tangent of a numeric expression given  in radians.
VAL  :  Numeric value of a string expression which represents a number.
OK , that I have worked with that short list from an around 35 year old back then extremely powerful BASIC language does not mean that I can not adapt lightning fast to using new commands or names of functions. But let me take a practical example to show why I have grievances or problems when it comes to understanding the FB manual and Declarations and Functions .
Lets take ABS as an example . it's a short and simple Function ! , in the manual of TI-99/4A Extended basic it looks like this :
ABS :
Format
ABS( numeric-expression)
Description
The ABS function gives the absolute value of numeric-expression. If numeric-expression is positive, ABS gives the value of numeric expression. If numeric-expression is negative, ABS gives its negative (a positive number). If numeric-expression is zero, ABS returns zero. The result of ABS is always a non-negative number.
Examples
PRINT ABS(42.3) prints 42.3. , >100 PRINT ABS(42.3)
VV = ABS( - 6.124) sets VV equal to 6.124. , >100 VV=ABS(6.124)


In FreeBASIC manual explanation is like this :
ABS
Calculates the absolute value of a number
Syntax:
declare function Abs ( byval number as integer ) as integer
declare function Abs ( byval number as uinteger ) as uinteger
declare function Abs ( byval number as double ) as double
Usage:
result = Abs( number )


Now , forget the byval and type variable definitions , I mean I get that Syntax defines the number "number" that is the object of the operation as e.g. integer and also that the declaration of Function ABS apparently also needs to tell compiler that function Abs is e.g. integer ,
But : what I don't understand is this part : declare function Abs , or for that matter : "declare function Time ( ) as string" ( https://www.freebasic.net/wiki/wikka.ph ... =KeyPgTime )
As I wrote :
But my "problem" with being "overwhelmed" by Function and Declare is more a simple matter of having to understand what they are and what they are used for.
And while you certainly both showed an example of use of Function Time *AND* explained it then the core of the matter - in that case the "declare function Time " were not touched (???)
Also you didn't use it , so I am still trying to understand Function and Declare / Declare Function especially since you didn't use it in your example and it is in the manual !? .
Now , your patience with me is probably wearing very thin - if you have any left , and for that I am sorry but I do not understand it.
The only way that something like Syntax: declare function Abs ( byval number as integer ) as integer / uinteger / double would make sense to me is if it is only there because the compiler per standard will assign a certain data type to the ABS function itself (not talking about x as in (ABS(x) ) , but ABS function itself and if the "declare function Abs" part is something that is used only when one wants to assign another data type to the ABS function itself other than what the compiler assigns it as standard !!????

Anyway , to make matters worse then if I take a look at Joseph's example above with respect to Function and Declare then it gets completely unhinged , I will comment on Joseph's code in the code Window :

Code: Select all

Declare Function mystring1 ( ByVal wall As Integer, ByRef street As Const String ) As String    '  I do not understand the whole Declare Function itself but this actually kind of makes sense to me since from what I can see it's in in this particular case used because I as a user am defining my own function "mystring1" and tell compiler that it is of type String with two "reference values" (?) of type integer and String constant.

FUNCTION mystring1 ( ByVal trinity As Integer, ByRef trinitystring As Const String ) As String   '  Not sure sure why this suddenly is there unless that that is because that after the declaration of the mystring one function on another line above then on this line we are defining the function itself  ????
   FUNCTION = string(trinity, trinitystring)  '   Here it gets completely unhinged for me because there is suddenly no trace of reference to mystring1 and it just says FUNCTION !!! ???? , I mean , I  *could* guess , but it would be purely guessing not that that I shall pretend to really  understand it anyway , here goes : it looks as if FUNCTION here is "placeholder" for the string by the name "mystring1" and that there is carried out an operation that makes mystring1=string(trinity, trinitystring)   ,  whatever that function then does !!!????
END FUNCTION    '   that must be the end of what started at the line starting with FUNCTION mystring1 , like if it had been a SUB

'  Rest of program is not something that needs commenting ! :-) 
DIM s as String
DIM c as Integer
s="H"
c=5
print mystring1(c,s)

PRINT
PRINT "Press any key..."
SLEEP

Anyway , if you have read this far then you might understand that I have some problems understanding the whole "declare function" thing - sorry ....

Anyway , I spent a lot of time again looking at the manual - and I am NOT meaning to criticize and I understand that a lot of people already have done a lot of work but ; I didn't find a any reference on FBWiki : DocToc ( https://www.freebasic.net/wiki/wikka.php?wakka=DocToc ) or on FBWiki : CatPgProgrammer ( https://www.freebasic.net/wiki/wikka.ph ... Programmer ) of the following topics :
--List of Functions (found Keywords - Alphabetical , Keywords - Functional)
--USER Function description (my guess is that Procedure FUNCTION is describing "USER Function" declaration , and "hold on to your hat and glasses" because on that page the syntax doesn't mention "Declare" at all as it does with built-in functions - ???)(it's in example but not in Syntax) : https://www.freebasic.net/wiki/wikka.ph ... PgFunction
--Procedure - description of what is , found "Keywords that work with procedures" - but not the same in my mind

As for the list of Function Keywords , then it really does not matter that much because I couldn't possibly sit down and learn them all by heart as you want me to as the first there are too many Keywords in FB for that. I will have to settle for trying to learn Keywords as I go along and hope that I don't screw up too much (I do however exercise a certain amount of caution in general , so if I am naming then I try to evaluate if I think that it sounds as a Keyword and if then alter or add to it....
MrSwiss wrote: Alternative: your own, self written procedures, that are used to *extend the FB-Language*.
You are in full control of: what goes in (parameters) and what comes back (Functions mostly).
A Sub differs in that it normally isn't producing a result (apart from e.g. prints something to screen).
There are exclusions to the rules (but that would go to deep, currently).
Hmmmm , this is really funny , actually , when I started writing this forum post for you then I did not understand why the heck you suddenly wrote about "self written procedures" , but now , thanks to all my reading manual to able to communicate with you then I suddenly know that that is because that a Function is a Procedure in FB ;-) :-) :-D

With the "There are exclusions to the rules (but that would go to deep, currently)" then it makes you sound as you have no idea about TI-99/4A Extended BASIC and my doings on that ;-)
TI-99/4A Extended Basic manual page 182 (to 187) , (ref. : http://www.99er.net/files/TI%20Extended ... Linked.pdf )
SUB
Format
SUB subprogram-name [(parameter-list)]

TI-99/4A Extended basic is about 35 (or more) years old (take that! :-D ) , and my use of SUB on that were for the greater part all producing results :-)

By the way , while I have composing this post (most of the day then) then I noticed something funny , I think that in this post viewtopic.php?p=236391#p236382 then for some reason something were cut out of the code (I do not think that it's me - could be the browser though as I cannot tell if done by browser or server) , in the last code window it says "Return f1 + df2" , where it should say "Return df1 + df2" .... (as I remember I just clicked quote and tapped along on the keyboard - writing my post not editing your post then :-) )
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Using string function

Post by fxm »

This page can help you:
Functional Keyword List
Post Reply