New topic: OutofBoundsException when trying to read from MySQL database
<http://forums.realsoftware.com/viewtopic.php?t=32453> Page 1 of 1 [ 4 posts ] Previous topic | Next topic Author Message Kuroto Post subject: OutofBoundsException when trying to read from MySQL databasePosted: Thu Feb 11, 2010 4:10 am Joined: Mon Feb 18, 2008 2:56 pm Posts: 20 Hi all, I'm having an issue when trying to read and update a row in a MySQL database. Here's the code: Code: for CntRows = 0 to wndPOS.lstBill.ListCount RSArticle = App.SQLDataBase.SQLSelect("SELECT * from kassa_artikelen WHERE id = '" + wndPOS.lstBill.Cell(CntRows, 0) + "'") CurStock = RSArticle.Field("stock") App.SQLDataBase.SQLExecute("UPDATE kassa_artikelen SET stock=" + CurStock + " WHERE id = '" + wndPOS.lstBill.Cell(CntRows, 0) + "'") Next What i'm trying to do is actually update a field so i can see what's still in stock. I'm getting an OutofBoundsException on the RSArticle = App.SQLDataBase... row. Thanks in advance! -Steve Top jefftullin Post subject: Re: OutofBoundsException when trying to read from MySQL databasePosted: Thu Feb 11, 2010 4:11 am Joined: Wed Nov 15, 2006 3:50 pm Posts: 1290 to wndPOS.lstBill.ListCount -1 Top Kuroto Post subject: Re: OutofBoundsException when trying to read from MySQL databasePosted: Thu Feb 11, 2010 4:25 am Joined: Mon Feb 18, 2008 2:56 pm Posts: 20 Hey Jeff, I did that, and the exception is gone, but now it won't do anything. Here's the complete code: Code: me.FillColor=rgb(83,188,39) rectCheckOut2.FillColor=rgb(83,188,39) dim PrinterInitString As String dim PrinterCenterText As String Dim PrinterLogo As String Dim PrinterCutPaper As String Dim PrinterKickDrawer As String Dim PrinterLeftText As String Dim PrinterRightText As String Dim ArtString As String Dim ArtPriceString As String Dim NumArt As Integer Dim ArtQtyString As String Dim CntRows As Integer Dim RSArticle As RecordSet Dim CurStock As String 's = s + chr(27) + "@" + chr(27) + "@" //initialize printer need it twice for some reason 's = s + chr(27) + chr(97) + chr(49) //50 = right // 49 = center // 48 = left 's = s + chr(27) + "Some Text" + chr(10)//Write some text 's = s + chr(27) + chr(32) + "0"//adjust right side line spacing 's = s + chr(27) + chr(33) + "1" //make text really big 's = s + chr(27) + chr(33) + chr(128) //Underline text 's = s + chr(27) + chr(33) + chr(8) //make text bold 's = s + chr(27) + chr(33) + chr(16) //make text double height 's = s + chr(27) + chr(33) + chr(32) //make text double width 's = s + chr(27) + chr(45) + chr(49) //underline thin = 49 thick = 50 's = s + chr(27) + chr(112) + chr(48) //////DRAWER KICK 's = s + chr(29) + chr(86) + chr(66) + chr(255) /// auto feed & partial cut 255= max feed amount if prefs.root.GetString("TicketPrinterType") = "tmt88" Then PrinterInitString = ChrB(27)+ "@" + chr(27) + "@" PrinterCenterText = chr(27) + chr(97) + chr(49) //50 = right // 49 = center // 48 = left PrinterLeftText = chr(27) + chr(97) + chr(48) //50 = right // 49 = center // 48 = left PrinterRightText = chr(27) + chr(97) + chr(50) //50 = right // 49 = center // 48 = left PrinterLogo = chrb(27)+chrb(97)+chrb(1)+chrb(28)+chrb(112)+chrb(1)+chrb(0)+chrb(27)+chrb(97)+chrb(0) PrinterCutPaper = chr(29) + chr(86) + chr(66) + chr(255) /// auto feed & partial cut 255= max feed amount PrinterKickDrawer= chr(27) + chr(112) + chr(48) //////DRAWER KICK ElseIf prefs.root.GetString("TicketPrinterType") = "cbm1000" Then PrinterInitString = ChrB(27)+"@" PrinterCenterText = chrb(27)+"a"+chrb(01) PrinterLogo = chrb(27)+chrb(97)+chrb(1)+chrb(28)+chrb(112)+chrb(1)+chrb(0)+chrb(27)+chrb(97)+chrb(0) PrinterCutPaper = ChrB(27)+"V"+ChrB(66)+ChrB(0) PrinterKickDrawer= ChrB(27)+ChrB(112)+ChrB(0)+ChrB(50)+ChrB(250) Else // Geen printer End If srlPrinter.SerialPort = System.SerialPort(prefs.root.GetString("DevicePOSPrinter")) srlPrinter.Baud = 9600 if App.SQLDataBase.Connect = True Then Rec = New DatabaseRecord Rec.Column("artikelen") = replaceall(wndPOS.lstBill.Cell(wndPOS.lstBill.ListIndex, 1), chr(9), "<br />") Rec.Column("totaal") = edf2Pay.Text Rec.Column("gebruiker") = "Point of Sale" Rec.Column("klant") = "Cold Sell" Rec.Column("betaalwijze") = "Cash" Rec.Column("factuur") = "0" Rec.Column("voldaan") = "1" App.SQLDataBase.InsertRecord("kassa_verkoop", Rec) App.SQLDataBase.Commit for CntRows = 0 to wndPOS.lstBill.ListCount -1 RSArticle = App.SQLDataBase.SQLSelect("SELECT * from kassa_artikelen WHERE id = '" + wndPOS.lstBill.Cell(CntRows, 0) + "'") CurStock = RSArticle.Field("stock") App.SQLDataBase.SQLExecute("UPDATE kassa_artikelen SET stock=" + CurStock + " WHERE id = '" + wndPOS.lstBill.Cell(CntRows, 0) + "'") Next if srlPrinter.Open = True Then srlPrinter.Write(PrinterInitString) srlPrinter.Write(PrinterLogo) srlPrinter.Write(PrinterCenterText) srlPrinter.Write(prefs.root.GetString("Header1") + chr(10)) srlPrinter.Write(prefs.root.GetString("Header2") + chr(10)) srlPrinter.Write(chr(10) + chr(10)) srlPrinter.Write(chr(27) + chr(97) + chr(48) + "Art. Pr.St. Tot." + chr(10)) For NumArt = 0 to wndPOS.lstBill.ListCount -1 if Len(wndPOS.lstBill.Cell(NumArt, 1)) = 1 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 2 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 3 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 4 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 5 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 6 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 7 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 8 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 9 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 10 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 11 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 12 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 13 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 14 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) = 15 Then ArtString = wndPOS.lstBill.Cell(NumArt, 1) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 1)) > 15 Then ArtString = Left(wndPOS.lstBill.Cell(NumArt, 1), 12) + "... " End If If Len(wndPOS.lstBill.Cell(NumArt, 4)) = 1 Then ArtPriceString = wndPOS.lstBill.Cell(NumArt, 4) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 4)) = 2 Then ArtPriceString = wndPOS.lstBill.Cell(NumArt, 4) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 4)) = 3 Then ArtPriceString = wndPOS.lstBill.Cell(NumArt, 4) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 4)) = 4 Then ArtPriceString = wndPOS.lstBill.Cell(NumArt, 4) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 4)) = 5 Then ArtPriceString = wndPOS.lstBill.Cell(NumArt, 4) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 4)) = 6 Then ArtPriceString = wndPOS.lstBill.Cell(NumArt, 4) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 4)) = 7 Then ArtPriceString = wndPOS.lstBill.Cell(NumArt, 4) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 4)) = 8 Then ArtPriceString = wndPOS.lstBill.Cell(NumArt, 4) + " " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 4)) = 9 Then ArtPriceString = wndPOS.lstBill.Cell(NumArt, 4) + " " End If If Len(wndPOS.lstBill.Cell(NumArt, 3)) = 1 Then ArtQtyString = wndPOS.lstBill.Cell(NumArt, 3) + "x " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 3)) = 2 Then ArtQtyString = wndPOS.lstBill.Cell(NumArt, 3) + "x " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 3)) = 3 Then ArtQtyString = wndPOS.lstBill.Cell(NumArt, 3) + "x " ElseIf Len(wndPOS.lstBill.Cell(NumArt, 3)) = 4 Then ArtQtyString = wndPOS.lstBill.Cell(NumArt, 3) + "x " End If srlPrinter.Write(chr(27) + chr(97) + chr(48) +ArtQtyString + ArtString + ArtPriceString + wndPOS.lstBill.Cell(NumArt, 5) + chr(10)) Next srlPrinter.Write(chr(27) + chr(97) + chr(49) + "------------------------------------------" + chr(10)) srlPrinter.Write(chr(27) + chr(97) + chr(50) + "Subtotaal: " + str(app.BillTotal) +chr(10) + chr(10)) srlPrinter.Write(PrinterCenterText) srlPrinter.Write(prefs.root.GetString("Footer1") + chr(10)) srlPrinter.Write(prefs.root.GetString("Footer2") + chr(10)) srlPrinter.Write(chr(10) + chr(10)) srlPrinter.Write(PrinterCutPaper) wndCash.Close wndPOS.lstBill.DeleteAllRows if prefs.root.GetBoolean("KickDrawer") = True Then srlPrinter.Write(PrinterKickDrawer) End If End If Else Dim d as New MessageDialog //declare the MessageDialog object Dim b as MessageDialogButton //for handling the result d.icon=MessageDialog.GraphicCaution //display warning icon d.ActionButton.Caption="Setup" d.CancelButton.Visible= True //show the Cancel button d.CancelButton.Caption="Afsluiten" d.Message="De databaseserver kan niet bereikt worden." d.Explanation="Wilt u Setup starten of het programma afsluiten?" b=d.ShowModal //display the dialog Select Case b //determine which button was pressed. Case d.ActionButton wndSettings.Show wndPOS.Close Case d.CancelButton Quit End select End If Top brisance Post subject: Re: OutofBoundsException when trying to read from MySQL databasePosted: Thu Feb 11, 2010 4:38 am Joined: Tue Oct 06, 2009 2:38 am Posts: 153 Your multiple Len() function calls within If-Else loops are slowing your code down. What you should do is store the output of Len() in a variable then use a select...case block to test against it. Ideally, use a Dictionary, it will give you much faster performance. _________________ HOWTO: RB Feedback Utility Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 4 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
