|
Post by Rod on Jul 6, 2022 11:48:06 GMT -5
My most recent need for local arrays was the recursive chess program. It was supposed to pass an array each time it was called. I solved that by using a two dimensional array, one dimension for each recursion. Not terribly intuative but it worked.
So yes local arrays and passing arrays would be useful. My first priority is multi columnar sorting, conditional selection to create a new set and then maths.
I agree that the sorting “should” sort the same way each time but I can see why it currently does not. Since the rest of the record is hidden from the sort, sorting what it sees is what I might expect. I have no expectation that stuff excluded from the sort will be in any order.
|
|
|
Post by bushrat on Oct 12, 2022 22:09:04 GMT -5
I'm not trying to denigrate Liberty Basic it's a great programming language which I've had a lot of fun with. But let's not get defensive just because it doesn't cover everything for the coder.
I thought maybe over time new stuff was introduced into the language? Hey, I was just curious what people think, so I asked.  As you say, over time new stuff gets introduced. Perhaps that will include more array operators. I have a new problem now. I did pay for an upgrade for version 4.5.1? sometime around Feb '22 but due to various circumstances never actually downloaded it.
My problem now is that a Basic program I've been using for years no longer runs. It just stops in its tracks at various points - no error messages and nothing in the 'error log'.
Possibly the application has become corrupted and I need to uninstall/reinstall Liberty Basic.
Since I did pay for an upgrade what's the best way to organise reinstallation? Order no. was 777906423.
Thanks
|
|
|
Post by Rod on Oct 13, 2022 1:55:38 GMT -5
First off try downloading and installing v4.5.1 from the Liberty BASIC home page. If you have a paid for compatible version it will open with your name at the top of the ide and you won’t even need to use your reg code.
If not and it installs as a trial version you will need to enter your reg code that was sent when you made the initial purchase.
If you don’t have the reg code then email Carl privately with the details of your original purchase specifically the email thst was used for delivery.
Upgrading from v4 to 4.5.1 was free older versions required a small additional payment. If you are on v3 there are coding differences that can catch you out on upgrade.
use the debugger and animate till your program halts, it will stop on the offending line and should give a clue about what is failing.
Start a new thread.
|
|
|
Post by bushrat on Oct 14, 2022 5:01:03 GMT -5
First off try downloading and installing v4.5.1 from the Liberty BASIC home page. If you have a paid for compatible version it will open with your name at the top of the ide and you won’t even need to use your reg code. If not and it installs as a trial version you will need to enter your reg code that was sent when you made the initial purchase. If you don’t have the reg code then email Carl privately with the details of your original purchase specifically the email thst was used for delivery. Upgrading from v4 to 4.5.1 was free older versions required a small additional payment. If you are on v3 there are coding differences that can catch you out on upgrade. use the debugger and animate till your program halts, it will stop on the offending line and should give a clue about what is failing. Start a new thread. yeah, already tried that but still got unexplained runtime halts. Really frustrating.
|
|
|
Post by Rod on Oct 14, 2022 9:43:21 GMT -5
How does it halt when you run in the debugger? Click the ladybug, click run in the debugger window. What does the debugger tell you?
|
|
|
Post by badbug on Nov 23, 2022 8:09:47 GMT -5
After reading about Arrays(), why is it better than SQLite. It seems to do everything you suggest. Is there an example where SQLite can't do what an array can do, or an array can do it better? Is memory the problem? Seems like it takes less memory especially for large arrays.
|
|
|
Post by Rod on Nov 23, 2022 10:48:55 GMT -5
You presume we all know SQLite, for most BASIC coders that's not the case. SQLite requires a new language be learned. BASIC coders do know about arrays and so these improvements to array handling will be easily understood and implemented inside the environment we know now. Memory and speed are not really the issue, especially if we could load and save arrays directly to file.
|
|
|
Post by badbug on Nov 23, 2022 13:11:55 GMT -5
Thanks Rod, I'm new to LB so did not know. Why learn something new when the old way has worked from the beginning of Basic. Actually it's not like learning a language, There are only a very few simple commands in SQL. Maybe someone could create a post doing something in arrays and comparing the same thing in SQL.
|
|
|
Post by Rod on Nov 24, 2022 7:35:42 GMT -5
I learned DBaseIII, not much use now! A tutorial on SQL would be good. I have started the SQL tutorial more than once but it still seems pretty foreign to me. Folks forget how much effort they put into learning what they know.
|
|
|
Post by badbug on Nov 25, 2022 4:53:43 GMT -5
To match what arrays do, you would only have to know a few commands. 1. First you need to open or create the db. sqliteconnect #handle, "file" will open the db. If it does not exist it will create it. So; sqliteconnect #handle,"c:\ary.db" will open ary.db or create it if it does not exist You can work in memory without a hard file using the command sqliteconnect #handle,":memory:"
2. You need to create a file layout. SQL refers to files as tables, and fields as rows. To create a file simply use the SQL CREATE command. To create a person file you could use a command like; x$ = "CREATE TABLE person(perNum,fName,mName,lName,addr,city,state,zip,eMail,phone)" to execute the create use the #handle execute(x$) This just created a table or file layout with the person's number, name, address, email, and phone.
3. To place data into the db use the INSERT command. All fields are separated with commas.Character fields are enclosed in quotes. SQL does not care if you insert characters into a numeric field or numbers into character fields. x$ = "INSERT INTO person(1,'Bob','B','Baker','123 Main','Los Angeles','CA',92020,'myEmail@gmail.com','203-123-4567')" #handle execute(x$) will place it into the db.
4 To delete a file use the DELETE command. x$ = "DELETE FROM person WHERE perNum = 1" #handle execute(x$) This will delete the person with perNum = 1. You can clear the table or file with x$ = "DELETE FROM person" You could delete all persons with the first name of John with x$ = "DELETE FROM person WHERE fName = 'John'" You could delete all persons whose last name starts with 'A' using x$ = "DELETE FROM person WHERE lName LIKE 'A%' Or to delete all persons whose last name ends with 'G' use x$ = "DELETE FROM person WHERE lName LIKE '%G'" Or delete all persons whose last name contains a "L' with x$ = "DELETE FROM person WHERE lName LIKE '%L%'"
5 Sorting is done with the ORDER BY command. To sort the file with first and middle name sorted within last name use x$ = "SELECT * FROM person ORDER BY lName,fName,mName" Here we used the SELECT *. The * tells it to select all fields. You could only select certain fields as in SELECT fName,mName,lName,city,state
6 Grouping stuff together. If you have duplicates you can group them To find out how many people have common first names you could use x$ = "SELECT count(*) as tot,* FROM person GROUP BY fName"
Here is a try at an example of array processing in SQL. Can someone show how to do this using arrays.
sqliteconnect #sql, ":memory:" ' this connects to memory with a handle #sql sql$ = "CREATE TABLE ary(flda,fldb,fldc)" ' command to create a table (file) called ary with 3 fields flda,fldb,fldc #sql execute(sql$) ' execute the command to create in memory table(file)
' make some random numbers for flda,fldb, and fldc ' this is really small with only 1000 records or rows. Make it as big as you like for i = 1 to 1000 ' flda = int(rnd(1) * 200) fldb = int(rnd(1) * 300) fldc = int(rnd(1) * 400) x$ = x$ + ",(";flda;",";fldb;",";fldc;")";chr$(13) next i
begTime = time$("ms") sql$ = "INSERT INTO ary VALUES ";mid$(x$,2) ' INSERTs all 10000 rows (records) into table (file) ary #sql execute(sql$) ' execute the insert command endTime = time$("ms") ' all 10000 rows (records) are in memory print "Total Time:";endTime - begTime;"ms"
begTime = time$("ms")
' we want to find multiple occurances of flda sql$ = " SELECT count(*) as tot,flda FROM ary GROUP BY flda HAVING tot > 1 ORDER BY tot,flda" #sql execute(sql$) WHILE #sql hasanswer() #row = #sql #nextrow() flda = #row flda() tot = #row tot() print tot;chr$(9);flda WEND endTime = time$("ms") print "Total Time : ";endTime - begTime;"ms"
' List everything in roder by flda,fldb,fldc with a count ' finding duplicate flda and fldb sql$ = " SELECT count(*) as tot,* FROM ary GROUP BY flda,fldb HAVING tot > 1 ORDER BY tot,flda,fldb" print sql$ #sql execute(sql$) WHILE #sql hasanswer() #row = #sql #nextrow() flda = #row flda() fldb = #row fldb() fldc = #row fldc() tot = #row tot() print tot;chr$(9);flda;chr$(9);fldb;chr$(9);fldc WEND
#sql disconnect() end
Here we get a count and give it a name tot, and group it by first name.
|
|
|
Post by tsh73 on Nov 25, 2022 8:28:47 GMT -5
1) does this code actually work in some version of LB, may be RB? 2) SQL and arrays are just *different* things build for *different* tasks Sure some of tasks overlap
Thing I could say about array is that index - row number - in array routinely used, while in SQL row number/row order are said to be not garanteed
|
|
|
Post by Rod on Nov 25, 2022 10:12:07 GMT -5
We will have a go at doing this in Liberty arrays. But it isn't really a race about time or memory use, its about functionality, native functionality.
|
|
|
Post by Rod on Nov 25, 2022 14:12:17 GMT -5
Can you explain the 1000,10000 references We seem to start with 1000 records with fields a,b,c what does the 10000 imply?
|
|
|
Post by pierre on Nov 25, 2022 14:36:44 GMT -5
seems to be just a typo. database contains 1000 records. code runs in RunBasic and LB5 alpha.
|
|
|
Post by badbug on Nov 26, 2022 1:28:57 GMT -5
Yes I'm using LB5 alpha and RunBasic. I guess the reason I use SQL instead of arrays is because of the power, functions, ease of use, and native interface. I agree speed isn't everything, but it sure don't hurt when you can get quick results. Even bringing in a CSV file or creating one is simple in SQL. And when you disconnect the DB all your data is on file and up to date. Before LB5 alpha, I admit it was kind of a mess. I usually test in RunBasic because it's easier to develope in RunBasic, and then bring it over to LB5 alpha.
Since I'm not a expert in arrays, I'd like to see how the above example is done using arrays so I can compare.
|
|