Using string function [SOLVED]

New to FreeBASIC? Post your questions here.
BasicCoder2
Posts: 3955
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Using string function

Post by BasicCoder2 »

Trinity wrote:I am first and fore most here (at FreeBasic.net) because of FreeBasics "console" capabilities and because for me then true freedom as a "high level" programmer is only available in console programming - otherwise one is just caught up in a lot of "Windows".
It depends on what you want to program. For my hardware projects FB gave me the speed and low level programming environment I was used to using on the old machines. It allowed me to program as if I was still using the old machines but one with lots of memory and speed. Although on the old machines I used to write most of my programs using Assembler for speed, until I learnt to program in C, I see no real value in using Assembler today. I don't usually use the C like abilities of FreeBASIC.
.
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: Using string function

Post by Trinity »

BasicCoder2 wrote:For my hardware projects FB gave me the speed and low level programming environment I was used to using on the old machines.
<SNIP>
I see no real value in using Assembler today. I don't usually use the C like abilities of FreeBASIC.
.
Well, that sounds so cool :-)
I myself simply "can't wait" for the day when I hopefully will master FreeBASIC including all it's cool aspects :-)
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Using string function

Post by MrSwiss »

Trinity wrote:I am first and fore most here (at FreeBasic.net) because of FreeBasics "console" capabilities and because for me then true freedom as a "high level" programmer is only available in console programming - otherwise one is just caught up in a lot of "Windows".
Well, in FB you can also do 2D graphics without struggling with "Windows", it contains its
own (built in) graphics library (fbGFX2) which is compatible with QBASIC's built in graphics.

Refer to graphic keyword's list in the manual, for more information ...
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: Using string function

Post by sancho2 »

Trinity wrote: because I am used to that what is described as the correct syntax for using something *is* the correct syntax for using something - if you know what I mean.....
Besides the Usage section which is immediately below the syntax section, there is also the example code which shows how to use the function.
For example the Abs function in the manual:

First from the usage section (its very straight forward):

Code: Select all

result = Abs( number )

Next from the example code (Agains this is very straight forward):

Code: Select all

Print Abs( -1 )
I think if you hang in there you will have not much problems learning FB.
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: Using string function

Post by Trinity »

MrSwiss wrote: Refer to graphic keyword's list in the manual, for more information ...
Funny you bring that up because I was thinking yesterday and today that I needed to learn even more about I/O on screen and graphics and keyboard :-)
Thank you very much :-)
sancho2 wrote: I think if you hang in there you will have not much problems learning FB.

I am very appreciative of the friendly environment that I m experiencing here as well as of your kind encouragement to me :-)
Thank you very much :-)
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Using string function [SOLVED]

Post by grindstone »

Hello Trinity!

As far as I can see, you don't understand what the declaration of a function is for (correct me, if I'm wrong). So let me try to show you in a little plain example:

Code: Select all

Function threefold(value As Integer) As Integer
	Return value * 3
End Function

Print threefold(1)
Sleep
will work, because you implemented the function prior to its first call, so the compiler "knows" what you want it to do.
In contrast to this

Code: Select all

Print threefold(1)
Sleep

Function threefold(value As Integer) As Integer
	Return value * 3
End Function
will throw a compiler error:
  • error 41: Variable not declared, threefold in 'Print threefold(1)'
because the compiler encounters the term "threefold" without knowing what to do with it. So, if you want to place the function's code behind its first call, you have to declare it:

Code: Select all

Declare Function threefold(value As Integer) As Integer

Print threefold(1)
Sleep

Function threefold(value As Integer) As Integer
	Return value * 3
End Function
Regards
grindstone
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: Using string function [SOLVED]

Post by Trinity »

grindstone wrote:Hello Trinity!

As far as I can see, you don't understand what the declaration of a function is for (correct me, if I'm wrong). So let me try to show you in a little plain example:

<SNIP>

Regards
grindstone
Hi grindstone :-)

That was very kind of you.
Yes , I have had a huge problem trying to "wrap my head around" the whole Declare Function - especially because it is put before all built-in functions as *correct syntax* in the manual which simply didn't compute for me , but as it happens then that is not syntax after all except apparently for if wanting to overload compiler and I had a really hard time understanding that the Declare Function had to be thrown away for built-in Functions when in manual as syntax - but that is sorted and understood now - I think ;-)...
But your explanation sort of encapsulates the solution to the other part of the problem I had to really get to use functions which was how to use correct in program.
So thank you very much for explaining and showing :-)
Post Reply