Snippets collection #1


We’ve gathered some useful snippets from the forum. Enjoy!

A neat way to split a string

Thanks to ‘jornmo’ for showing me this trick

Public Sub Form_Open()
Dim sString As String = "1920x1080"

Print Split(sString, "x")[0]
Print Split(sString, "x")[1]


Export html or php page directly to pdf from firefox command line

Thanks to ‘monteiro’ for this one

  1. Install cmdlnprint complement for firefox
  2. From your code:
Shell "firefox -print " & URL & " -print-mode pdf -print-file " & /file_path/file_name.pdf

A software I wrote creates a bank slip using php. The document is saved as pdf in order to be sent to the customer by email.

Eliminate all double spaces from a string

Public Sub Form_Open()
Dim sTemp As String = "This          is  a        very    badly         spaced        string"
Dim sCheck As String

 sCheck = sTemp
 Print sTemp
 sTemp = Replace(sTemp, "  ", " ")
Until sCheck = sTemp

sTemp = Replace(sTemp, " is", " WAS")
Print "\n" & sTemp


Display database data in a particular order

Public Sub Form_Open()
Dim sInputString As String[] = ["One ", "Three ", "Zero ", "Five", "Four ", "Two "]
Dim sOrder As Short[] = [2, 0, 5, 1, 4, 3]
Dim siCount As Short

For sicount = 0 To 5
 Print sInputString[sOrder[siCount]];


Try the following

Print "He" & " " & "was" & " " & "here!"
Print "He";; "was";; "here!"
Print "He", "was", "here!"

Here is a video on how to create a clock

(You only have to type 1 line of code!)

Do you want to turn a spreadsheet into a CSV file for easy manipulation in Gambas? It’s easy!

Dim sData as String
Dim sFolder as String = User.Home 'Change as necessary. The file name below in this case is temp.ods but could be Hello.xls

Shell "cd " & sFolder & " && " & "libreoffice --headless --convert-to csv temp.ods" Wait
sData = File.Load(sFolder &/ "temp.csv")

'You now have all the data from temp.ods in your variable sData!

NOTE: LibreOffice must NOT be open when you run your code or it may not work

Be the first to comment

Leave a Reply