Did you know?

Post your Gambas programming questions here.
User avatar
Got2BeFree
Posts: 91
Joined: Saturday 26th November 2016 2:52am
Location: Lost

Re: Did you know?

Post 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:".
sholzy

I'm wondering around lost in the past, not knowing where the present is.
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

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

Post 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 27915 times
User avatar
cogier
Site Admin
Posts: 1117
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Did you know?

Post by cogier »

No I did not know that one. Very useful as I also have run into the same issue. Thanks.
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Did you know?

Post 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.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

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

Post 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()
carrollleigh
Posts: 1
Joined: Friday 19th November 2021 2:36pm

Re: Did you know?

Post by carrollleigh »

I didn't know
User avatar
Quincunxian
Posts: 171
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

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

Post 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
Cheers - Quin.
I code therefore I am
PartierSP
Posts: 57
Joined: Tuesday 30th November 2021 12:14am
Location: Canada
Contact:

Re: Did you know?

Post 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.
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Did you know?

Post 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 :)
If at first you don't succeed , try doing something differently.
BruceS
cage
Posts: 123
Joined: Monday 2nd September 2019 5:47am
Location: Phoenix Arizona

Re: Did you know?

Post 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
Post Reply