Hi All,
I am creating a generic save method for my editable list boxes. It involves scanning each cell row by row and column by column. All goes well until I try to run the program and get a " parameters not compatible with this function" error on the following line;
rec.Column(x)=lb.Cell(ctr,x) where x,ctr are declared integers.
lb.cell(ctr,x) is a listbox passed by ref. If I use a string reference to the column e.g.: rec.Column(“code”) it compiles without error, but this type of specific column reference defeats the purpose of my generic save routine. I have another program I was using as a testbed to learn Xojo’s DB functions, but when I cut and pasted the working method, magically it now produces an error. I read in the forum that somebody else had the same problem. Am I missing something? According to the online language reference, I am doing nothing wrong.
.Column()
is 1-based index and .Cell()
is 0-based index. Maybe that is the issue? i.e. do:
rec.Column(x + 1) = lb.Cell(ctr, x)
and see if that solves your problem. I am not sure, just taking a guess.
Hi Jeremy,
Actually, I missed that inconsistency between objects in Xojo. I tried your suggested code, but still the same deal. Its looking like time to get out the big mallet. This takes me back to when I got my first copy of VB1.
[quote=92991:@Chris Benton]Hi Jeremy,
Actually, I missed that inconsistency between objects in Xojo. I tried your suggested code, but still the same deal.[/quote]
Zero-based indexing across the board is coming. It is a pain for sure sometimes, but you begin to pick it up.
Did you step through it with the debugger and see what value being assigned is the actual issue? After that I am not sure. Was just guessing the zero-based index was the issue. Sorry about that, was really hoping it was.
This is not a runtime error, but a compile error, so I cant really monitor or test variables if I cant run the compiled program. No need for apologies. Any suggestion is better that me cursing my Mac and condemning Xojo to eternal damnation.
Unfortunately the docs were wrong (since 2011, it appears!).
You cannot use an index with the Column method to set a column value. You have to provide the column name.
That makes perfect sense, didn’t even think through the real application here. What is Column(1)
on a brand new record? I suppose InsertRecord
could first look at the table structure and assign 1
to the first field in the table, but coding like that is problematic. Generally index based db access is problematic because whenever a SQL statement changes, new field added, etc… there go all of your indexes, and what does 1
mean anyway?
Now, Chris… To solve your problem, you could do the query yourself to get the database structure if that’s the route you really want to go. Just store the field names in an array and use:
rec.Column(fieldName(x)) = lb.Cell(ctr, x)
It works!!!
Mega thanks to Paul and Jeremy. God knows what newbies like me would do without the diligence and intervention of guys like yourselves. I figure that Xojo inc owes me about 500,000 strands of hair that I pulled out while reading incorrect docs over and over again.
Thanks again guys.