New topic: Filling Web List box, only get a single record.
<http://forums.realsoftware.com/viewtopic.php?t=37723> Page 1 of 1 [ 6 posts ] Previous topic | Next topic Author Message tseyfarth Post subject: Filling Web List box, only get a single record.Posted: Fri Feb 18, 2011 7:01 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 98 Hello all. I am trying to fill a list box with all records available from a given DB. Using Postgre tools, I know there are 3 records in the database. However each time I try, I only get the last record, never all three showing up in the list box. Here is the code: This code calls the class Method from within a Form Method Code: remotes.Module_Type_No = 4 'Access Result = remotes.GetEqualKey6 This is the code within the class Methods Code: dim osql as new cSmartSQL Dim ssql as String Dim msg as String Dim sMod_typeNo as String RecordCount = 0 sMod_typeNo = cstr(Module_Type_No) osql.StatementType = eStatementType.Type_Select osql.AddTable"remotes" osqL.AddFieldS "address","slot","module_type_no","module_device_no","module_type_name","remote_name","priority","relay_slot","relay_no","slave","maddress","mslot","mtype","mmodule_device_no","commformat","disable_tamper","commfailure","function","relay_on_time" osql.ClearWhereClause osql.AddSimpleWhereClause "module_type_no", smod_typeNo,"remotes" ', eClauseOp.Equal msg = osql.SQL RsRemotes = db.SQLSelect(osql.SQL) if db.Error = true then dbMessage = db.ErrorMessage Return db.ErrorCode end if 'RsRemotes.Field("remote_type" not used yet RecordCount = 0 dbMessage= db.ErrorMessage RsRemotes.MoveFirst while Not RsRemotes.EOF RecordCount = RecordCount +1 RsRemotes.MoveNext wend Return db.ErrorCode WebListbox Code Code: RsRemotes.MoveFirst do until RsRemotes.EOF Remotes.address = RsRemotes.Field("address").IntegerValue Remotes.Remote_Name=RsRemotes.Field("remote_name").StringValue Remotes.Priority=RsRemotes.Field("priority").IntegerValue Remotes.Slave=RsRemotes.Field("slave").IntegerValue Remotes.MasterAddress=RsRemotes.Field("maddress").IntegerValue Remotes.MasterSlot=RsRemotes.Field("mslot").IntegerValue Remotes.MasterType=RsRemotes.Field("mtype").IntegerValue Remotes.CommFormat=RsRemotes.Field("commformat").IntegerValue Remotes.Tamper_Disabled=RsRemotes.Field("disable_tamper").IntegerValue Remotes.Funct= RsRemotes.Field("function").StringValue Remotes.Relay_OnTime= RsRemotes.Field("relay_on_time").IntegerValue 'Fun= RsRemotes.Field("function").StringValue OnTime= Cstr(RsRemotes.Field("relay_on_time").IntegerValue) Slave = "No" if Remotes.Slave = 1 then Slave ="Yes" Tamper = "No" If Remotes.Tamper_Disabled = 1 then Tamper = "Yes" lstAccessControls.AddRow Cstr(Remotes.Address),Remotes.Remote_Name,Fun, OnTime, Cstr(Remotes.Priority),Cstr(Remotes.CommFormat),Tamper ,Cstr(Remotes.MasterAddress),Cstr(Remotes.MasterSlot),Cstr(Remotes.MasterType) RsRemotes.MoveNext loop Can anyone tell me where I've messed up? It seems also, the debugger crashes (windows reports this) while stepping through the Form Method where the WebListBox code resides. Thank you Tim Top timhare Post subject: Re: Filling Web List box, only get a single record.Posted: Fri Feb 18, 2011 8:19 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 9237 Location: Portland, OR USA MoveFirst is not valid for postgre databases. According to the docs under RecordSet.MoveFirst: Quote:Supported only for the REALSQLdatabase data source. Your initial code loops through the recordset and counts the records into RecordCount. At that point, the recordset is done. It's stuck on the last record and pretty much useless. Top timhare Post subject: Re: Filling Web List box, only get a single record.Posted: Fri Feb 18, 2011 8:37 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 9237 Location: Portland, OR USA BTW, you asked previously about using a class vs. a structure to interact with database values. Given this usage presented here, neither are appropriate. You'd be better off with local variables, at least in this scenario. There are other scenarios where using a class to hold the values would be of use. If your code is of this form, though, a class is overkill. Just FYI. Top tseyfarth Post subject: Re: Filling Web List box, only get a single record.Posted: Fri Feb 18, 2011 9:00 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 98 Hi again Tim. With regard to structures etc, am still getting the know the beast. In this case, it does not use a structure, but rather Global Properties of the class clsRemotes. The reason(s) to use the class, are to A) become familiar with them and how they might be beneficial B) try to get that encapsulation going C) not have to write each var every time. As for the recordset, there is no way to "re-use" that? What would be the appropriate handling so as not to have to go out and grab the record set everytime. I guess I thought it remained in memory until the object was destroyed or went out of focus. Tim Top timhare Post subject: Re: Filling Web List box, only get a single record.Posted: Fri Feb 18, 2011 11:01 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 9237 Location: Portland, OR USA Right, but a RecordSet really isn't a data container, per se. It's more of an interface tool. With most db's it's use once and discard. Do you really need to know the count beforehand? If not, dump that code and you should be fine. Otherwise, you could make use of your class and read the recordset into an array of class objects (inside the loop where you're counting RecordCount). Then the window code can traverse the array instead of the recordset. Top tseyfarth Post subject: Re: Filling Web List box, only get a single record.Posted: Sat Feb 19, 2011 12:26 am Joined: Sat Dec 04, 2010 9:14 pm Posts: 98 No, I don't need to know all, just thought that it was a container.... For the last 10 years, I write to the micro kernel. Either with a get first, then move forward or get a match, or get first but with the keys being matched, then moving forward, again with the keys matched. That would likely be the best way. But here again, I thought the RS was a container and would eliminate the extra code. Can you suggest a good source for SQL command list - like that get first, get next and so on? Thanks again! Tim Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 6 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]
