Author Topic: Gambas  (Read 13012 times)

0 Members and 1 Guest are viewing this topic.

John Spikowski

  • Guest
Gambas
« on: June 09, 2008, 09:55:02 PM »
I have been working with Gambas under Linux and just wanted to mention that it is an outstanding VB look-a-like and easy to program in. I couldn't be happier. It's a bit of work installing the needed dependencies if you want to compile the current source (2.6.0) but well worth the effort. The author has done a great job with this VB like language.

http://gambas.sourceforge.net/


John

Offline Donald Darden

  • Sr. Member
  • ****
  • Posts: 389
Re: Gambas
« Reply #1 on: June 09, 2008, 10:55:14 PM »
I decided to take a quick look at the Gambas link and status today.  Some of the key elements I picked up on are:

VB style -- that isn't necessarily what I'm looking for, but should please some people.

Interpreter -- again, that is not ideal, but on a quick PC this could still work out pretty well.

Ubuntu status:  Good -- now that I am committed to working just with Ubuntu, it is good to know that it will compile and work on this platform.

Windows status:  Bad -- problem getting it to work with GUI, so at present it is not really functioning well under Windows.

Bottom line then is that you can have a VB-style BASIC on your Linux distro right now, but as an interpreter rather than compiled language, and you will have to wait a bit before you can also enjoy it in its entirety in Windows.  And you have to be prepared to build it on your PC, because it does not appear that they are distributing a ready-made binary that you can just download and use.

It's anybody's and everybody's choice about what to do at this point.  Gambas may be just what someone is looking for, and of course it is free.  But I've been spoiled by the lightning speed of the PowerBasic compilers for so long that I really have a strong preference for something beyond an interpreter.  Still, someone's experience with getting and compiling Gambas would be beneficial, as well as any comments after the install about how well it works, what can be done with it, and sample code would be welcomed.

John Spikowski

  • Guest
Re: Gambas
« Reply #2 on: June 10, 2008, 12:51:06 AM »
I wouldn't discount Gambas or ScriptBasic just because they are interpreters. Both are written in C and very fast and extensible. I wrote a utility for removing old photos from a real estate search I host in PowerBASIC and needed to move the operation to a Linux server. I rewrote the program in ScriptBasic and it finished within a minute of my compiled PB version. Before giving Gambas the thumbs down, I would give it a spin and then tell me what you think.

VB is now free (VS2005 / VS2008) and Windows is flooded with wantabe (Delphi, PowerBASIC conversion project, ...) languages. I think there is a huge opportunity for business applications under Linux and I plan to fill a few of those niches with Linux native solutions. (Gambas & ScriptBasic)

John

Here is a one of the database examples in Gambas.



Code: [Select]
' Gambas class file

PRIVATE $hConn AS Connection

PUBLIC SUB btnConnect_Click()

  DIM sName AS String
  DIM hTable AS Table

  TRY $hConn.Close
  '$hConn = NEW Connection

  sName = txtName.Text

  WITH $hConn
    .Type = cmbType.Text
    .Host = txtHost.Text
    .Login = txtUser.Text
    .Password = txtPassword.Text
    .Name = ""
  END WITH

  IF chkCreate.Value THEN

    $hConn.Open
    IF NOT $hConn.Databases.Exist(sName) THEN
      $hConn.Databases.Add(sName)
    ENDIF
    $hConn.Close

  ENDIF

  $hConn.Name = sName
  $hConn.Open

  'FOR EACH hTable IN $hConn.Tables
  '  PRINT hTable.Type
  'NEXT

  frmDatabase.Enabled = TRUE
  frmRequest.Enabled = TRUE

CATCH

  Message.Error(DConv(Error.Text))

END

PUBLIC SUB btnCreate_Click()

  DIM hTable AS Table

  hTable = $hConn.Tables.Add("test")

  hTable.Fields.Add("id", db.Long)
  hTable.Fields.Add("color", db.Integer,, 1)
  hTable.Fields.Add("firstname", gb.String, 16)
  hTable.Fields.Add("name", gb.String, 32)
  hTable.Fields.Add("birth", gb.Date)
  hTable.Fields.Add("active", gb.Boolean)
  hTable.Fields.Add("salary", gb.Float)
  hTable.Fields.Add("comment", gb.String)

  hTable.PrimaryKey = ["id"]

  hTable.Update

  hTable = $hConn.Tables.Add("color")

  hTable.Fields.Add("color", db.Serial)
  hTable.Fields.Add("name", gb.String, 32)
  hTable.Fields.Add("french", gb.String, 32)

  hTable.PrimaryKey = ["color"]

  hTable.Update

CATCH

  Message.Error(DConv(Error.Text))

END

PUBLIC SUB btnDelete_Click()

  TRY $hConn.Tables.Remove("test")
  TRY $hConn.Tables.Remove("color")

END

PUBLIC SUB btnFill_Click()

  DIM iInd AS Integer
  DIM rTest AS Result
  DIM rColor AS Result
  DIM sColor AS String
  DIM aName AS String[] = ["Paul", "Pierre", "Jacques", "Antoine", "Mathieu", "Robert", "Stéphane", "Yannick", "Frédéric"]
  DIM aFrench AS String[] = ["Noir", "Blanc", "Rouge", "Vert", "Bleu", "Jaune", "Transparent"]
  INC Application.Busy

  $hConn.Begin

  rColor = $hConn.Create("color")

  FOR EACH sColor IN ["Black", "White", "Red", "Green", "Blue", "Yellow", "Transparent"]

    rColor!name = sColor
    rColor!french = aFrench[iInd]
    INC iInd
    rColor.Update
 
  NEXT

  rTest = $hConn.Create("test")

  FOR iInd = 1 TO txtCount.Value

    rTest!id = iInd
    rTest!color = Int(Rnd(6)) + 1
    rTest!firstname = aName[Int(Rnd(aName.Count))]
    rTest!name = "Name #" & iInd
    rTest!birth = CDate("01/01/1970") + Int(Rnd(10000))
    rTest!active = Int(Rnd(2))
    rTest!salary = Round(Rnd(1000, 10000), -2)

    rTest.Update

  NEXT

  $hConn.Commit

FINALLY

  DEC Application.Busy

CATCH

  $hConn.Rollback
  Message.Error(DConv(Error.Text))

END

PUBLIC SUB btnRun_Click()

  DIM rData AS Result
  DIM hForm AS FRequest

  rData = $hConn.Exec(txtRequest.Text)
  hForm = NEW FRequest($hConn, rData)
  hForm.Show

CATCH

  Message.Error(DConv(Error.Text))

END

PUBLIC SUB Form_Open()

  $hConn = NEW Connection

END

PUBLIC SUB Form_Close()

  $hConn.Close

END

PUBLIC SUB chkDebug_Click()

  DB.Debug = chkDebug.Value

END

PUBLIC SUB btnTest_Click()

  FTest.Show

END



Code: [Select]
' Gambas class file

PRIVATE $hConn AS Connection
PRIVATE $rData AS Result
fine AS Boolean
cur AS Integer


PUBLIC SUB _new(hConn AS Connection, rData AS Result)

  $hConn = hConn
  $rData = rData

  RefreshTitle

  ReadData

  ME.Move(Int(Rnd(Desktop.W - ME.W)), Int(Rnd(Desktop.H - ME.H)))

END


PRIVATE SUB RefreshTitle()

  DIM sTitle AS String

  sTitle = ("SQL request") & " - " & $hConn.Name

  ME.Title = sTitle

END


PRIVATE SUB ReadData()

  DIM hTable AS Table
  DIM hField AS ResultField
  DIM sField AS String
  DIM iInd AS Integer
  DIM iLen AS Integer

  INC Application.Busy

  tbvData.Rows.Count = 0

  tbvData.Columns.Count = $rData.Fields.Count

  FOR EACH hField IN $rData.Fields

    WITH hField

      'PRINT .Name; ": "; .Type; " "; .Length

      tbvData.Columns[iInd].Text = .Name
      tbvData.Columns[iInd].Width = WidthFromType(tbvData, .Type, .Length, .Name)

    END WITH

    INC iInd
  NEXT
' ODBC Changes
  IF $rData.Count = -1 THEN
    tbvData.Rows.Count = rowcount()
'      $rData.Count

  ELSE
  tbvData.Rows.Count = $rData.Count
  ENDIF

FINALLY

  DEC Application.Busy

CATCH

  Message.Error("Cannot exec request." & "\n\n" & DConv(Error.Text))

END


PUBLIC SUB tbvData_Data(Row AS Integer, Column AS Integer)

  $rData.MoveTo(Row)

  tbvData.Data.Text = Str($rData[tbvData.Columns[Column].Text])
  tbvData.Data.Background = Color.RGB((Row MOD 31) * 8, (Row MOD 17) * 15, (Row MOD 13) * 21)
  tbvData.Data.Foreground = Color.White

END


PRIVATE FUNCTION WidthFromType(hCtrl AS control, iType AS Integer, iLength AS Integer, sTitle AS String) AS Integer

  DIM iWidth AS Integer

  SELECT CASE iType

    CASE gb.Boolean
      iWidth = hCtrl.Font.Width(Str(FALSE)) + 32

    CASE gb.Integer
      iWidth = hCtrl.Font.Width("1234567890") + 16

    CASE gb.Long
      iWidth = hCtrl.Font.Width("12345678901234567890") + 16

    CASE gb.Float
      iWidth = hCtrl.Font.Width(CStr(Pi) & "E+999") + 16

    CASE gb.Date
      iWidth = hCtrl.Font.Width(Str(Now)) + 16

    CASE gb.String
      IF iLength = 0 THEN iLength = 255
      iLength = Min(32, iLength)
      iWidth = hCtrl.Font.Width("X") * iLength + 16

  END SELECT

  iWidth = Max(iWidth, hCtrl.Font.Width(sTitle) + 8)

  RETURN iWidth

END

PRIVATE FUNCTION rowcount() AS Integer

  DIM rows AS Integer

  rows = 0
  DO
    $rData.MoveTo(rows)
   INC rows
  LOOP

CATCH

  RETURN rows

END

Bound control example with program generated data.



Code: [Select]
' Gambas class file

'PRIVATE $hConn AS NEW Connection

PUBLIC SUB Form_Open()

  WITH DataBrowser2.GridView
    .Columns[0].Text = "Color"
  END WITH
 
  WITH DataBrowser1.GridView
    .Columns[0].Text = "Id"
    .Columns[0].Width = 48
    .Columns[1].Text = "Active"
    .Columns[2].Text = "Name"
  END WITH
 
END

PUBLIC SUB DataControl6_Validate(Value AS Variant)

  IF IsNull(Value) THEN RETURN
  IF Value < 0 OR Value > 10000 THEN
    STOP EVENT
  ENDIF

END
« Last Edit: June 10, 2008, 03:45:00 AM by John Spikowski »

John Spikowski

  • Guest
Re: Gambas
« Reply #3 on: June 23, 2008, 11:50:53 AM »



Gambas 2.7.0 has been released.

Change Log