Page 8 of 10

Re: Did you know?

Posted: Friday 19th February 2021 4:21am
by Got2BeFree
progger wrote: Thursday 18th February 2021 4:11pm If you create a comment that starts with "TODO:" then that comment shows up in you Notes list. This is a nice way to keep track of your ToDo-list :)
So will "FIXME:" and "NOTE:".

Re: Did you know? ...the Recent Projects screen

Posted: Tuesday 23rd February 2021 10:36am
by stevedee
I'm probably the last person to discover this, but I sometimes end up with 2 copies of a project in different folders, and then don't know which one to open from the Recent Projects screen.

I don't know why the project path is not shown on-screen, as there is plenty of space for it.

However, if you simply hold the mouse over the project icon, a tool-tip will pop-up and display the path.


Gambas_Recent_Projects.png
Gambas_Recent_Projects.png (228.18 KiB) Viewed 28477 times

Re: Did you know?

Posted: Tuesday 23rd February 2021 12:11pm
by cogier
No I did not know that one. Very useful as I also have run into the same issue. Thanks.

Re: Did you know?

Posted: Tuesday 23rd February 2021 2:42pm
by BruceSteers
I almost submitted a commit with a change to enable this and spotted it already does it when editing the code lol :D

had that issue soooo many times.

Re: Did you know? ...Basic declarations in C Libraries

Posted: Monday 8th March 2021 10:38am
by stevedee
level: Intermediate
category: External C Libraries
subject: Basic declarations in C Libraries


Not everyone would have learnt the C programming language on their path to Gambas greatness.

But when attempting to use a C library in Gambas, you need to understand how routines & functions are declared in C.

Here are a few examples taken from the RaspberryPi pigpio library:-

Code: Select all

int gpioRead(unsigned gpio)
This declaration literally means that "this function will return an integer (int) and requires an unsigned integer (unsigned) argument for a variable named gpio"

So we declare this in Gambas like this:-
Public Extern gpioRead(iPin As Integer) As Integer
...and execute this function in our Gambas code like this:-
intLevel = gpioRead(intPin)

Example 2:-

Code: Select all

int gpioInitialise(void)
In C the keyword "void" means nothing. So this declaration literally means that "this function will return an integer (int) and does not require any arguments (void)".

So we declare this in Gambas like this:-
Public Extern gpioInitialise() As Integer
...and execute this function in Gambas like this:-
intResult = gpioInitialise()
...and then check intResult to see if initialisation was a success or failure.


Example 3:-

Code: Select all

void gpioTerminate(void)
This declaration literally means that "this routine will not return anything (void) and does not require any arguments (void)".

So we declare this in Gambas like this:-
Public Extern gpioTerminate()
...and execute this routine in Gambas like this:-
gpioTerminate()

Re: Did you know?

Posted: Friday 19th November 2021 2:42pm
by carrollleigh
I didn't know

Did you know? - How to get a Random Word.

Posted: Tuesday 7th December 2021 11:00pm
by Quincunxian
You can use this function to get a random word from your preferred dictionary.
If you check the /usr/share/dict/ area, you can find other dictionaries you can use.
Please check the actual lines(word count) in the dictionary and adjust the WordCount variable accordingly.

UsedWords[ ] is a string array that holds words that have already been used. You should clear this when start a new sequence/game.
{Million to one chances happen one in ten times: Sir Terry Pratchett}
Private Function GetRandomWord(InMin as Integer, InMax as Integer) As String

  Dim TmpStr As String
  Dim NewWord As Boolean = False
  Dim ExecParam As String
  Dim WordCount as Integer = 101000
  Dim DictionaryName as string = "american-english" 
Repeat
    ExecParam = "awk -v lineno=" & Str(Rand(1, WordCount)) & " 'lineno==NR{print;exit}' /usr/share/dict/" & DictionaryName
    Shell ExecParam To TmpStr
    TmpStr = LCase(TmpStr)
    TmpStr = Replace(TmpStr, "'s", "") ' Many of the words in the dictionary have a plural suffix
    TmpStr = Replace(TmpStr, "\n", "") ' Remove the 'new line' characters

    If Not UsedWords.Exist(TmpStr) Then NewWord = True
    If ((Len(TmpStr) < InMin) Or (Len(TmpStr) > InMax)) Then NewWord = False
    
  Until NewWord

  UsedWords.Add(TmpStr)
  
  Return TmpStr

End

Re: Did you know?

Posted: Thursday 9th December 2021 11:47am
by PartierSP
DYK, that pressing [Ctrl] + H or [Ctrl] + J while editing a class will open a split screen. Comes in handy when you need to reference back to a different area of the class your working on which has scrolled off of your screen.

Re: Did you know?

Posted: Saturday 1st January 2022 4:00pm
by BruceSteers
PartierSP wrote: Thursday 9th December 2021 11:47am DYK, that pressing [Ctrl] + H or [Ctrl] + J while editing a class will open a split screen. Comes in handy when you need to reference back to a different area of the class your working on which has scrolled off of your screen.
OMG that's MASSIVELY useful :)

Thank you I had no idea it did that :)

Re: Did you know?

Posted: Friday 4th February 2022 6:44pm
by cage
Was playing around with passing variables between forms and discovered how to do it without using global variables. You need to make the text boxes public for this to work.
' Gambas class file
'Fmain Form

Public te As Boolean
Public TxOut As String

Public Sub Form_Open()
  
  FMain.Center
  TextBox1.SetFocus
  
End

Public Sub Button1_Click()
  ' Setup Variable to Pass to Form2
  TxOut = "Variable Sent To Form2"
  'Set Form2 Textbox1 to = TextBox1.Text
  Form2.TextBox1.Text = TextBox1.Text
  'Clear TextBox1 Text 
  TextBox1.Text = ""
  'Set Form2 variable of TxIn to TxOut
  Form2.TxIn = TxOut
  'Close the main from and open the second window
  Me.Close
  Form2.Show
  
End

Public Sub Button2_Click()
  
  Me.Close
  
End


**********************************************************
 'Gambas class file
 'Form2 Form

Public TxIn As String

Public Sub Form_Open()
  
  Form2.Center
  
End

Public Sub Button1_Click()
  
  'Assign the contents of FMain Textbox1 to
  'Form2 TextBox2
  FMain.TextBox2.Text = TextBox1.Text
  'Set FMain TextBox1 to returned text
  FMain.TextBox1.Text = "Text was sent and Returned"
  'Display the variable from FMain
  Message(TxIn)
  'Reopen FMain
  FMain.Show
  Me.Close
  
End