I have another problem. I have since updated to gambas3 btw, 3.11.

I have made another form,(FNew), basically moved the addNew procedure
to the new form. 
The addNew btn on the FMain form just opens the new form(FNew.Show).

I have a "Commit" button that use the same code the addNew one did form
the FMain form.
All the code is the same.
But I'm  getting an error: "Null Object in FNew"

Should I have made the new from a child of the FMain??
If so How?
BTW I wasn't sure of starting a new thread or just continue with the old
one, if I should start a new one just let me know.

The offending CODE:
 rTable = $hConn.Create("inventory")

Entire CODE from FNew:

' Gambas class file

Public $hConn As Connection
Public Sub btnCommit_Click()

  Dim rTable As Result
  
  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


On Wed, 2012-08-08 at 20:59 +0200, Olivier Cruilles wrote:
> So to be exact, it's the same mecanism for all other database.
> 
> If you declare a variable (as $hConn) in a PUBLIC SUB, the variable is local 
> of this PUBLIC SUB
> so if you want to use a variable in all a Form or Module or Class, you need 
> to declare your variable at the beginning of this Form and not in a PUBLIC SUB
> 
> When you use a Connection object to open a database, after initialized it and 
> opened it, the object Connection keep connected to the database, so you just 
> need to use it.
> 
> Cordialement,
> 
> Olivier Cruilles
> Mail: linu...@club-internet.fr
> 
> Le 8 août 2012 à 20:51, rocko <sunblast...@gmail.com> a écrit :
> 
> > Thank you sir;
> > You get a cookie :)
> > Your example works fine.
> > 
> > 'Public' instead of 'Private' for the $hConn as Connection was the key I
> > believe, as was a few other small syntax related items.
> > The E-Book I was following(Much older version of gambas) I don't think
> > even mentions declaring it as either.
> > 
> > I'm new to sqlite and gambas, I mostly deal with perl and mysql.
> > 
> > Thanks to all who replied to my questions and gave examples.
> > The community here has always been very helpful.
> > 
> > 
> > 
> > 
> > On Wed, 2012-08-08 at 20:31 +0200, Olivier Cruilles wrote:
> >> Hello,
> >> 
> >> I think your problem is that you don't understand how to use sqlite 
> >> database..
> >> 
> >> You don't renew a connection every time you want to use it.
> >> 
> >> - You open the database at the beginning of your program
> >> - You work with it by updating it
> >> - Before you close you program, you close the database
> >> 
> >> So to do that use it like that:
> >> 
> >> --------------------------------------------
> >> 
> >> PUBLIC $hConn AS Connection <=  Error corrected
> >> 
> >> btnConnect CODE:
> >> 
> >> PUBLIC SUB btnConnect_Click()
> >> 
> >> $hConn = NEW Connection     <=  line added
> >> 
> >> $hConn.Host = "/home/rocko/DataBases"
> >> $hConn.Name = "my_test.sqlite"
> >> $hConn.Type = "sqlite"
> >> $hConn.Open
> >> 
> >> btnAdd CODE:
> >> 
> >> PUBLIC SUB btnAdd_Click()
> >> 
> >> DIM rTable AS Result
> >> 
> >> rTable = $hConn.Create("inventory")        <=  Error corrected
> >> 
> >> IF rTable.Available THEN 
> >>   rTable!name = txtName.Text
> >>   rTable.Update
> >>   TRY rTable.Update
> >>   IF ERROR THEN 
> >>     PRINT "Update failed"
> >>     Message.Error(ERROR.Text)
> >> 
> >>     ENDIF 
> >> ENDIF 
> >> 
> >> DB.Commit
> >> 
> >> btnClose CODE:
> >> PUBLIC SUB btnClose_Click()
> >> 
> >> $hConn.Close
> >> FMain.Close
> >> 
> >> 
> >> 
> >> 
> >> Cordialement,
> >> 
> >> Olivier Cruilles
> >> Mail: linu...@club-internet.fr
> >> 
> >> Le 8 août 2012 à 20:13, rocko <sunblast...@gmail.com> a écrit :
> >> 
> >>> Is it DB.Create/DB.Commit?? I was using $hConn.Create and so on.
> >>> 
> >>> I'm  getting 'Connection Not Opened" error when click the Add_new btn.
> >>> 
> >>> 
> >>> btnConnect CODE:
> >>> PRIVATE $hConn AS Connection
> >>> PUBLIC SUB btnConnect_Click()
> >>> 
> >>> DIM $hConn AS NEW Connection
> >>> 
> >>> $hConn.Host = "/home/rocko/DataBases"
> >>> $hConn.Name = "my_test.sqlite"
> >>> $hConn.Type = "sqlite"
> >>> $hConn.Open
> >>> 
> >>> btnAdd CODE:
> >>> 
> >>> PUBLIC SUB btnAdd_Click()
> >>> 
> >>> DIM $hConn AS NEW Connection 
> >>> DIM rTable AS Result
> >>> 
> >>> rTable = DB.Create("inventory")
> >>> 
> >>> IF rTable.Available THEN 
> >>>   rTable!name = txtName.Text
> >>>   rTable.Update
> >>>   TRY rTable.Update
> >>>   IF ERROR THEN 
> >>>     PRINT "Update failed"
> >>>     Message.Error(ERROR.Text)
> >>> 
> >>>     ENDIF 
> >>> ENDIF 
> >>> 
> >>> DB.Commit
> >>> 
> >>> btnClose CODE:
> >>> PUBLIC SUB btnClose_Click()
> >>> 
> >>> $hConn.Close
> >>> FMain.Close
> >>> 
> >>> On Wed, 2012-08-08 at 19:48 +0200, Fabien Bodard wrote:
> >>>> Private $hConn as New Connection
> >>>> Public sub _New()
> >>>> $hConn .Host = "dir of bdd"
> >>>> $hConn.Name = "MyBdd"
> >>>> $hConn.Type = "sqlite"
> >>>> $hConn.Open
> >>>> 
> >>>> End
> >>>> 
> >>>> 
> >>>> PUBLIC SUB btnAdd_Click()
> >>>> 
> >>>> DIM rTable AS Result
> >>>> 
> >>>> rTable = DB.Create("inventory")
> >>>> 
> >>>>  rTable!name = txtName.Text
> >>>> 
> >>>>   TRY rTable.Update
> >>>>   IF ERROR THEN
> >>>>     PRINT "Update failed"
> >>>>     Message.Error(ERROR.Text)
> >>>>     return
> >>>>   ENDIF
> >>>> 
> >>>> 
> >>>> DB.Commit
> >>>> 
> >>>> end
> >>>> 
> >>>> Public SUb Form_Close
> >>>> $hConn.CLose
> >>>> end
> >>>> 
> >>>> 
> >>>> 
> >>>> 
> >>>> 
> >>>> 
> >>>> 
> >>>> 
> >>>> 
> >>>> 
> >>>> 2012/8/8 rocko <sunblast...@gmail.com>
> >>>> 
> >>>>> Im now getting error's.
> >>>>> I was getting a "connection not opened" error message, so I add
> >>>>> a $hConn.Open before the $hConn.Begin.
> >>>>> I'm now getting a "Driver name missing" error.
> >>>>> 
> >>>>> CODE:
> >>>>> PUBLIC SUB btnAdd_Click()
> >>>>> 
> >>>>> DIM $hConn AS NEW Connection
> >>>>> DIM rTable AS Result
> >>>>> $hConn.Open
> >>>>> $hConn.Begin
> >>>>> '$hConn.Exec("INSERT INTO inventory VALUES(name), txt.Name")
> >>>>> '$hConn.Commit
> >>>>> rTable = $hConn.Create("inventory")
> >>>>> 
> >>>>> IF rTable.Available THEN
> >>>>>   rTable!name = txtName.Text
> >>>>>   rTable.Update
> >>>>>   TRY rTable.Update
> >>>>>   IF ERROR THEN
> >>>>>     PRINT "Update failed"
> >>>>>     Message.Error(ERROR.Text)
> >>>>> 
> >>>>>     ENDIF
> >>>>> ENDIF
> >>>>> 
> >>>>> $hConn.Commit
> >>>>> $hConn.Close
> >>>>> 
> >>>>> On Wed, 2012-08-08 at 19:17 +0200, Fabien Bodard wrote:
> >>>>>> 2012/8/8 rocko <sunblast...@gmail.com>
> >>>>>> 
> >>>>>>> Is there anyway to translate that??
> >>>>>>> 
> >>>>>> google ?
> >>>>>> 
> >>>>>> 
> >>>>>>> 
> >>>>>>> On Wed, 2012-08-08 at 19:01 +0200, Fabien Bodard wrote:
> >>>>>>>> it's in french but ...
> >>>>>>>> 
> >>>>>>>> 
> >>>>> http://www.gambasforge.org/code-56-apprehender-sqlite-avec-gambas.html
> >>>>>>>> 
> >>>>>>> 
> >>>>> ------------------------------------------------------------------------------
> >>>>>>>> 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@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@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@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@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@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@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@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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to