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 :
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.
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
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
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
PRINT "Press any key..."
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 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 :-) )