Did you know?

Post your Gambas programming questions here.
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: Did you know?

Post by thatbruce »

gb.db can use inequalities and wildcards.

For example, to find all people whose surname starts with "S" you can use something like

Code: Select all

searchstr="S%"
rlt = Conn.Find("people","surname ilike &1",searchstr)
The example is for PostgreSQL, other databases might use different wildcard characters. Also "ilike" is PostgreSQL for a case independent search.

This is just the beginning!

Code: Select all

startdate=date(2000,1,1)
rlt=Conn.Find("people","birthdate < &1",startdate)
gives me everyone born in the last century.

It :shock: :o :? me that I have only discovered this today. I thought that it could only use equality search terms, like "surname = &1".
Have you ever noticed that software is never advertised using the adjective "spreadable".
dockfo
Posts: 7
Joined: Monday 7th March 2022 5:38pm

Re: Did you know?

Post by dockfo »

... a shortcut to if...then...else... statment
If ( Test AS Boolean , TrueExpression , FalseExpression )
it is like conditional (ternary) operator in php, js and other languages ... :geek:
Last edited by dockfo on Monday 26th December 2022 7:47pm, edited 1 time in total.
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: Did you know?

Post by grayghost4 »

Not quite the same .... it is a function, that returns a value.

 y = If(x, "true", "false")
User avatar
Quincunxian
Posts: 171
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: Did you know?

Post by Quincunxian »

Curious: I wonder if the IIf is somehow different or a duplication of function?
TestStr = IIf(X = Y, "Yes", "No")

I tend to use this to convert Boolean values to string when reading data and displaying for a specific view control.
Cheers - Quin.
I code therefore I am
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: Did you know?

Post by grayghost4 »

Quincunxian wrote: Monday 19th December 2022 1:22am Curious: I wonder if the IIf is somehow different or a duplication of function?
TestStr = IIf(X = Y, "Yes", "No")

I tend to use this to convert Boolean values to string when reading data and displaying for a specific view control.
From My testing it seems to be the same ;)
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: Did you know?

Post by thatbruce »

I believe it is syntactical "sugar" i.e. the functions If( ) == IIf( ).
But it sure is handy filling gridviews, etc:

Code: Select all

Gridview1.Add(datum.this, 
	datum.that,
	IIf(datum.other,datum.other,"Unknown"),
	datum.etc)
Have you ever noticed that software is never advertised using the adjective "spreadable".
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Did you know?

Post by BruceSteers »

Mid() and String.Mid() can be used to insert text into another with the syntax

Mid(TextToEdit, PositionToStart, CharsToRemove) = "TextToInsert"

Like this...
(don't forget Mid() uses 1 as 1st position not 0)


Dim sText As String = "At my House"

' insert "Sally's" into sText at position 4 removing 2 of the chars (my)
Mid(sText, 4, 2) = "Sally's"

Print sText


Prints..
At Sally's house

See
https://gambaswiki.org/wiki/lang/mid Mid$ (assignment)
If at first you don't succeed , try doing something differently.
BruceS
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

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

Post by JumpyVB »

stevedee wrote: Tuesday 23rd February 2021 10:36am 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.
BruceSteers wrote: Tuesday 23rd February 2021 2:42pm I almost submitted a commit with a change to enable this. Had that issue soooo many times.
The space is reserved for "Project Properties" > "Description".

I just got this idea. If you don't use the project description field at all, then you could do something like this. Add this Sub for every project and call it from a convenient spot such as Form_Open:

Public Sub UpdateProjectPathToProjectDescription()
  Dim PathForDotProject As String = Application.Path &/ ".project"
  Dim ContentsOfDotProject As String[] = Split(File.Load(PathForDotProject), gb.NewLine, "", True)
  Dim NoDescriptionYeat As Boolean = True
  Dim i As Integer
  For i = 0 To ContentsOfDotProject.Length - 1
    If String.Left(ContentsOfDotProject[i], 11) = "Description" Then 
      ContentsOfDotProject[i] = "Description=" & String.Chr(34) & Application.Path & String.Chr(34)
      NoDescriptionYeat = False
    Endif
  Next
  If NoDescriptionYeat Then 
    ContentsOfDotProject.Add("Description=\"" & Application.Path & "\"")
  Endif
  Dim NewContents As String = ""
  For i = 0 To ContentsOfDotProject.Length - 1
    NewContents = NewContents & ContentsOfDotProject[i] & gb.NewLine
  Next
  File.Save(PathForDotProject, NewContents)
End


Then when ever you move your code the path shown in the description gets updated once the code gets run for the first time. Or maybe this example of mine gets your minds thinking of even better iterations of this crude idea. Happy coding you all!
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

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

Post by BruceSteers »

JumpyVB wrote: Friday 24th March 2023 8:06am
stevedee wrote: Tuesday 23rd February 2021 10:36am 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.
BruceSteers wrote: Tuesday 23rd February 2021 2:42pm I almost submitted a commit with a change to enable this. Had that issue soooo many times.
The space is reserved for "Project Properties" > "Description".

I just got this idea. If you don't use the project description field at all, then you could do something like this. Add this Sub for every project and call it from a convenient spot such as Form_Open:

Then when ever you move your code the path shown in the description gets updated once the code gets run for the first time. Or maybe this example of mine gets your minds thinking of even better iterations of this crude idea. Happy coding you all!
Aah , You're a bit late fella , Benoit made a change so the bottom part of the space shows the path (trimmed) and if you hover the mouse over the lower part the full file path shows in the tooltip. :)
If at first you don't succeed , try doing something differently.
BruceS
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

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

Post by JumpyVB »

BruceSteers wrote: Friday 24th March 2023 10:21am Aah , You're a bit late fella , Benoit made a change so the bottom part of the space shows the path (trimmed) and if you hover the mouse over the lower part the full file path shows in the tooltip. :)
I have the "latest" gambas3 from a fresh Linux Mint installation using Software Manager / default Repository which is 3.16.3-3 from Sep 15 2021 :o

I managed to update gambas to the latest version 3.18.90 and can confirm that the project directories are shown on the select project dialog.

PS: I followed the installation instructions on https://gambaswiki.org/wiki/install#t14 Apparently Linux Mint 21 is based on Ubuntu 22.04.

Code: Select all

$ cd ~

$ git clone --depth=1 https://gitlab.com/gambas/gambas.git

$ sudo apt-get install -y build-essential g++ automake autoconf libtool libbz2-dev libzstd-dev libmysqlclient-dev unixodbc-dev libpq-dev libsqlite0-dev libsqlite3-dev libglib2.0-dev libgtk2.0-dev libcurl4-gnutls-dev libgtkglext1-dev libpcre3-dev libsdl-sound1.2-dev libsdl-mixer1.2-dev libsdl-image1.2-dev libxml2-dev libxslt1-dev librsvg2-dev libpoppler-dev libpoppler-private-dev libpoppler-glib-dev libpoppler-cpp-dev libasound2-dev libdirectfb-dev libxtst-dev libffi-dev libglew-dev libimlib2-dev libv4l-dev libsdl-ttf2.0-dev libgdk-pixbuf2.0-dev linux-libc-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libcairo2-dev libgsl-dev libncurses5-dev libgmime-3.0-dev llvm-dev llvm libalure-dev libgmp-dev libgtk-3-dev libsdl2-dev libsdl2-mixer-dev libsdl2-ttf-dev libsdl2-image-dev sane-utils libdumb1-dev libssl-dev libqt5opengl5-dev libqt5svg5-dev libqt5webkit5-dev libqt5x11extras5-dev qtbase5-dev qtwebengine5-dev libwebkit2gtk-4.0-dev git

$ cd gambas

$ ./reconf-all

$ ./configure -C --disable-keyring --disable-qt4

# If everything is configured without error, then run this command to compile the program:

$ make -j $(nproc)

# If everything compiles without error, then enter this command to install everything:

$ sudo make install

Post Reply