Chaos Project

Game Development => Sea of Code => Topic started by: ShadowPierce on October 01, 2011, 01:36:42 pm

Title: Visual Basic Recordsets and ListView Searching
Post by: ShadowPierce on October 01, 2011, 01:36:42 pm
->I'm a Computer Science major, currently the project leader for our Computer Programming 3 thesis... Despite being the project leader, I do all the work... So             I came here to ask for some Visual Basic help... No advanced stuff please, we're still on the basics so my professor would probably get suspicious if I use some weird code....

Anyway, could anyone take a look at this code? I can't, for the love of Blizzard, seem to make it run properly... It always catches a different error every time I try to change it, specifically the Sub on the Textbox:
Spoiler: ShowHide


Sub FillListView()
    ListView1.ListItems.Clear
    dbConnect
        rs.Open "Select * from tblProducts", db, 1, 2
        Do Until rs.EOF = True
            Dim lst As ListItem
            Set lst = ListView1.ListItems.Add(, , rs!pID)
            lst.SubItems(1) = rs!pName
            lst.SubItems(2) = rs!pCategory
            lst.SubItems(3) = rs!pSubCategory
            lst.SubItems(4) = rs!pColor
            lst.SubItems(5) = rs!pSize
            lst.SubItems(6) = rs!pSizeType
            lst.SubItems(7) = rs!pPrice
            lst.SubItems(8) = rs!pSupplier
            lst.SubItems(9) = rs!pInStock
            lst.SubItems(10) = rs!pReorderQty
            lst.SubItems(11) = rs!pMiscDetails
            rs.MoveNext
        Loop
        rs.Close
    dbDisconnect
End Sub

Private Sub Form_Load()
cboSearchBy.AddItem "Product Name"
cboSearchBy.AddItem "Category"
cboSearchBy.AddItem "Color"
cboSearchBy.AddItem "Size Type"
cboSearchBy.AddItem "Supplier"
cboSearchBy.Text = "Product Name"
FillListView
End Sub

Private Sub txtKeyword_Change()
ListView1.ListItems.Clear
    dbConnect
        rs.Open "Select * from tblProducts where " & cboSearchBy.Text & " like '" & txtKeyword.Text & "%'", db, 1, 2
        Do Until rs.EOF = True
            Dim lst As ListItem
            Set lst = ListView1.ListItems.Add(, , rs!pID)
            lst.SubItems(1) = rs!pName
            lst.SubItems(2) = rs!pCategory
            lst.SubItems(3) = rs!pSubCategory
            lst.SubItems(4) = rs!pColor
            lst.SubItems(5) = rs!pSize
            lst.SubItems(6) = rs!pSizeType
            lst.SubItems(7) = rs!pPrice
            lst.SubItems(8) = rs!pSupplier
            lst.SubItems(9) = rs!pInStock
            lst.SubItems(10) = rs!pReorderQty
            lst.SubItems(11) = rs!pMiscDetails
            rs.MoveNext
        Loop
        rs.Close
    dbDisconnect
End Sub


Answers ASAP please... Thanks! :haha:


Title: Re: Visual Basic Recordsets and ListView Searching
Post by: ForeverZer0 on October 01, 2011, 01:58:14 pm
I would move this to Sea of Code, but for some strange reason Academics is like the one board I have no control of. I think Blizz is calling me stupid in some passive-aggressive type of way ;)

Unfortunately, Visual Basic is not my forte, so I am sorry that I cannot help a lot. I am unsure of the rules of VB, but I do know that most languages do not allow for modification of an Array/List during iteration. It appears that is what you are trying to do. What errors is it giving it you?

Title: Re: Visual Basic Recordsets and ListView Searching
Post by: Ryex on October 01, 2011, 01:59:51 pm
Well, I think your out of luck here man. I'm one of the few people here who has any experience with VB. in fact. I might be the only one. the only experience I have with VB is from back when I was helping JC with Pokemon Neon and he was writing a new engine in VB.

any way your using VB and MySQL if the SQL like query stings are any clue, and from my limited experience I see nothing wrong. I would help me to know what kind of errors you are getting or what isn't working, I could point you to potential problem sources then.
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: ShadowPierce on October 01, 2011, 02:06:59 pm
->I think I'm getting there, instead of taking the field name from the database itself, I assign it on a string first before using it in the recordset...

I'm getting various kinds of errors every time I change the code on the textbox, but this is the most common:

Quote
Runtime error '-2147217 (80040e14)'

Syntax error (missing operator) in query expression.


Any ideas as to why this happens?  :hm:


Title: Re: Visual Basic Recordsets and ListView Searching
Post by: Ryex on October 01, 2011, 02:09:58 pm
this error is telling you that your SQL query is malformed. somewhere in your iteration the query is generated with a missing operator.
to debug it have it generate the query as a string and print it before using it to query the database. the last string to get printed before the error gets raised is the one that is malformed.
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: ShadowPierce on October 01, 2011, 02:19:13 pm
->I tried redefining my queries but still no luck... :(



EDIT:
->Wait! Got it! It seems that my queries weren't matching with the string read by VB, so I just had to change those with my combobox so that they can work... Thanks Ryex! *hugs* :haha:

Resolved in less than an hour... :D


Title: Re: Visual Basic Recordsets and ListView Searching
Post by: Ryex on October 01, 2011, 02:26:04 pm
glad to be of help.
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: G_G on October 01, 2011, 02:37:03 pm
Quote from: Ryex on October 01, 2011, 01:59:51 pm
Well, I think your out of luck here man. I'm one of the few people here who has any experience with VB. in fact. I might be the only one. the only experience I have with VB is from back when I was helping JC with Pokemon Neon and he was writing a new engine in VB.

any way your using VB and MySQL if the SQL like query stings are any clue, and from my limited experience I see nothing wrong. I would help me to know what kind of errors you are getting or what isn't working, I could point you to potential problem sources then.


You wish! >:U The very first version of Cybele was coded in VB. In fact, I learned Visual Basic before C#. *goes back to doing chores because no one around this house has to do them ever*
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: ForeverZer0 on October 01, 2011, 04:44:13 pm
Quote from: Ryex on October 01, 2011, 01:59:51 pm
Well, I think your out of luck here man. I'm one of the few people here who has any experience with VB. in fact. I might be the only one. the only experience I have with VB is from back when I was helping JC with Pokemon Neon and he was writing a new engine in VB.


He never said he was the only one. Just saying. :V:
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: G_G on October 01, 2011, 04:52:41 pm
Quote from: Ryex on October 01, 2011, 01:59:51 pm
Well, I think your out of luck here man. I'm one of the few people here who has any experience with VB. in fact. I might be the only one. the only experience I have with VB is from back when I was helping JC with Pokemon Neon and he was writing a new engine in VB.


(http://forum.chaos-project.com/Smileys/default/sarcasm.gif)
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: Ryex on October 01, 2011, 05:45:27 pm
Quote from: Ryex on October 01, 2011, 01:59:51 pm
Well, I think your out of luck here man. I'm one of the few people here who has any experience with VB. in fact. I might be the only one. the only experience I have with VB is from back when I was helping JC with Pokemon Neon and he was writing a new engine in VB.


well that makes TWO people who know VB.

also when I was first looking at the code and asked for the error, I had a feeling that the error would be with the SQL and not the actual VB.
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: ForeverZer0 on October 01, 2011, 05:54:51 pm
lol

Zer0 = fail
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: Blizzard on October 02, 2011, 03:18:27 pm
Quote from: ForeverZer0 on October 01, 2011, 05:54:51 pm
lol

Zer0 = fail


But doesn't this mean you're not failing at all, because it's zero fail?

Spoiler: ShowHide
:troll:
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: ForeverZer0 on October 02, 2011, 08:31:14 pm
That means I am incapable of failure.

I like your reasoning.
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: winkio on October 02, 2011, 08:57:43 pm
You are incapable of being incapable.  Reasoning is broken.
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: ForeverZer0 on October 02, 2011, 09:14:49 pm
Being incapable does not necessarily mean failure, so win. :V:
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: ShadowPierce on October 15, 2011, 02:40:11 am
->Anyone willing to take a look at the system I did so far? It's still unfinished & missing a lot of things (will be passing it in 3 days) so please post bugs & errors here... :haha:

http://www.mediafire.com/?ts2wp12s91oq99k (http://www.mediafire.com/?ts2wp12s91oq99k)

NOTE: Requires VB and MS Access to open all files

I'd really appreciate it if you guys would help! ;)


Title: Re: Visual Basic Recordsets and ListView Searching
Post by: Ryex on October 15, 2011, 03:34:09 am
what are you trying to do again?
Title: Re: Visual Basic Recordsets and ListView Searching
Post by: ShadowPierce on October 15, 2011, 04:20:31 am
->Nothing, really... I just can't find a bug so I thought I'd ask someone to "beta-test" it in case I missed something... :P


Title: Re: Visual Basic Recordsets and ListView Searching
Post by: Ryex on October 15, 2011, 06:04:45 am
ah, makes sense. others can often find bugs you thought were impossible until they manifested themselves.