[Gambas-user] Second Form not reading Public variable from first form

rocko sunblaster5 at ...626...
Thu Aug 9 20:26:30 CEST 2012


If I declare a Public variable is it available across all Forms and
Modules??
I ask because I'm having difficulty with a $hConn variable

I have a FMain form that connects to an sqlite database when the form is
opened.
Public Sub Form_Open()
	$hConn = New Connection
	With $hConn
	 .Host = "path to database"
	and so on....
I have $hConn declared as Public at the top of the FMain.Class
This so far works fine, the form opens and I get the Message.Info 
"You are connected to the database"

It's when the second form loads, Have a 'Add New' button on FMain which
opens the FNew form which can be used to add a record to the database,
but I was getting an error when I click the 'Commit' button.

Something about rTable and $hConn being NULL Objects, so I added an 
$hConn = New Connection, but now I'm getting:
"Unknown Identifier" for $hConn.
here is the Code for the FNew form:

' Gambas class file

' 
Private rTable As Result

'Public $hConn As Connection

Public Sub btnCommit_Click()
 
  $hConn = New Connection
 ' $hConn.Open
  
  rTable = $hConn.Create("inventory")
  
  If rTable.Available Then
    rTable!name = txtName.Text
    rTable!type = txtType.Text
    Try rTable.Update
    If Error Then
      Print "Update failed"
      Message.Error(ERROR.Text)
      
      Endif
  Endif
    
  DB.Commit
  

End

Public Sub btnCancel_Click()

  FNew.Close

End

Was also getting an error on the rTable AS Result when I had in the Sub
as DIM rTable AS Result>>"Unexpected Dim"
So I moved to the top of the class, don't know if that was good Idea
though.
I thought if I declared $hConn as Public it would be available to the
Fnew form, but that doesn't seem to be the case
Any insight would be helpful..









More information about the User mailing list