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

rocko sunblaster5 at ...626...
Thu Aug 9 21:22:27 CEST 2012


Ok I see, 
I've added FMain.xxxx
but now I'm getting "Driver name missing" at FMain.Open


On Thu, 2012-08-09 at 21:08 +0200, Olivier Cruilles wrote:
> Hello,
> 
> When you declare a variable as PUBLIC in a Form (Ex:  FMain) and if you want to access to this variable from another Form you need to rewrite the first Form like that:
> 
> 
> In the second Form use this:   FMain.$hConn    (But only if the variable is declared as PUBLIC, not PRIVATE)
> 
> 
> 
> Cordialement,
> 
> Olivier Cruilles
> Mail: linuxos at ...1896...
> 
> Le 9 août 2012 à 20:26, rocko <sunblaster5 at ...626...> a écrit :
> 
> > 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..
> > 
> > 
> > 
> > 
> > 
> > 
> > ------------------------------------------------------------------------------
> > Live Security Virtual Conference
> > Exclusive live event will cover all the ways today's security and 
> > threat landscape has changed and how IT managers can respond. Discussions 
> > will include endpoint security, mobile security and the latest in malware 
> > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> 
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and 
> threat landscape has changed and how IT managers can respond. Discussions 
> will include endpoint security, mobile security and the latest in malware 
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user






More information about the User mailing list