Skip to content
Gambas Logo

Gambas.One

For fellow Gambasers

  • Home
  • Forum
  • Tips & Tricks
    • Snippets
  • Classes
  • Programming books
    • A book by Gerry Buzolic
    • The GaP-BG Project
  • Distro support
  • Resources
  • Toggle search form
cyber

Snippets collection #1

Posted on October 22, 2016April 6, 2025 By cogier

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]

End

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

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

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

End

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]];
Next

End

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

Snippets Tags:examples, snippets

Post navigation

Previous Post: Its Alive!
Next Post: Install Gambas on Puppy Linux

Search

October 2016
S M T W T F S
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
    Jan »

About

Gambas is a free development environment and a full powerful development platform based on a Basic interpreter with object extensions, as easy as Visual Basicâ„¢.

Gambas.ONE is a community site for Gambas fans. Welcome to just read up and learn, or to get involved and write and share your Gambas know-how with the rest of us. Also be sure to check out the forums.

Enjoy!

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2025 Gambas.One.

Powered by PressBook WordPress theme