Board Logo
« Simple Database Framework - Sort by Name »

Welcome Guest. Please Login or Register.
Jan 18th, 2018, 3:56pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Simple Database Framework - Sort by Name  (Read 470 times)
tanger32au
Full Member
ImageImageImageImage


member is offline

Avatar



YIM YIM
Homepage PM

Gender: Male
Posts: 135
xx Simple Database Framework - Sort by Name
« Thread started on: Aug 17th, 2017, 7:03pm »

I have written a program which is based on the simple database framework, how would I get it to sort the records as they are entered to display by name on the main screen?

Paul
User IP Logged

http://launcestonanalyticalradioscanning.blogspot.com.au/

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Simple Database Framework - Sort by Name
« Reply #1 on: Aug 18th, 2017, 02:36am »

Hi Paul,

There is a Qsort sample I worked out for strings from the qsort.bas sample that came with JB here:
http://justbasic.conforums.com/index.cgi?board=code&action=display&num=1496023647
User IP Logged

B+
tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3636
xx Re: Simple Database Framework - Sort by Name
« Reply #2 on: Aug 18th, 2017, 1:48pm »

You need to add sorting array just after reading data
For SUB version that would be like this
Code:
sub ReadDB
    'get the number of records in the database
    '= length of database file divided by the record length
    TotalRecords = lof(#db)/150
 
    'check if the database is corrupted
    if TotalRecords <> int(TotalRecords) then
        notice "Database corrupted"; chr$(13); "Please check its contents!"
        TotalRecords = int(TotalRecords + .5)
    end if
 
    'dimension array to enable adding one record
    MaxItems = TotalRecords + 1
    redim items$(MaxItems)
 
    for Record = 1 to TotalRecords
        get #db, Record
 
        'fill the array with the data
        'separate fields by CHR$(0) to display only the first field in the listbox
        items$(Record) = trim$(ItemName$); chr$(0); ItemNumber; chr$(0); ItemPrize
    next
	'sort array
'added code: simple selection sort
'of cource qsort will be faster, but then it's bigger
	for i = 1 to TotalRecords
		minPos = i
		minVal$ = items$(i)
                            'select minimal item
		for j = i+1 to TotalRecords
			if items$(j) < minVal$ then
				minVal$ = items$(j)
				minPos = j
			end if
		next
                            'then swap it to i-th place
		tmp$=items$(minPos)
		items$(minPos)=items$(i)
		items$(i)=tmp$
	next
end sub 
« Last Edit: Aug 18th, 2017, 1:50pm by tsh73 » User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
tanger32au
Full Member
ImageImageImageImage


member is offline

Avatar



YIM YIM
Homepage PM

Gender: Male
Posts: 135
xx Re: Simple Database Framework - Sort by Name
« Reply #3 on: Aug 21st, 2017, 12:11am »

on Aug 18th, 2017, 1:48pm, tsh73 wrote:
You need to add sorting array just after reading data
For SUB version that would be like this


Thank you, that works very well.
User IP Logged

http://launcestonanalyticalradioscanning.blogspot.com.au/

tanger32au
Full Member
ImageImageImageImage


member is offline

Avatar



YIM YIM
Homepage PM

Gender: Male
Posts: 135
xx Re: Simple Database Framework - Sort by Name
« Reply #4 on: Dec 19th, 2017, 4:07pm »

Next question.

Can you add a notice, based on the contents of a field. As in when editing a record, if say the name filed of that record contains say "12/2017", it displays a notice?
User IP Logged

http://launcestonanalyticalradioscanning.blogspot.com.au/

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Simple Database Framework - Sort by Name
« Reply #5 on: Dec 19th, 2017, 7:48pm »

Yes, but can't tell by question where you want the notice.

Are you talking about using the NOTICE keyword to put up a message on screen when your code reads some que in file like the date?

Or are you talking about inserting something in records were your code reads some cue like date? That would require more information.
« Last Edit: Dec 19th, 2017, 7:48pm by bplus » User IP Logged

B+
tanger32au
Full Member
ImageImageImageImage


member is offline

Avatar



YIM YIM
Homepage PM

Gender: Male
Posts: 135
xx Re: Simple Database Framework - Sort by Name
« Reply #6 on: Dec 19th, 2017, 8:15pm »

Putting a notice on the screen if a given field contains given data, such as:

textbox #item.Name, 145, 42, 625, 25

If that field of that record contains "12/2017" then display a notice. How do I get it to check the contents of that field and display a notice based on it's contents?
User IP Logged

http://launcestonanalyticalradioscanning.blogspot.com.au/

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Simple Database Framework - Sort by Name
« Reply #7 on: Dec 19th, 2017, 8:55pm »

Code:
'from JB help
'print #handle.ext, "!contents? varName$";
'This retrieves the contents of the textbox and places them into the variable, varName$.

'so
#item.Name, "!content? checkDate$";   'this sets the variable's value to the textbox contents
if checkDate$ = "12/2017" then notice "item.name has date 12/2017"  'this checks the contents and issues NOTICE 


Set code like this at place in program where textbox control gets new contents like when displaying records.
« Last Edit: Dec 19th, 2017, 8:56pm by bplus » User IP Logged

B+
tanger32au
Full Member
ImageImageImageImage


member is offline

Avatar



YIM YIM
Homepage PM

Gender: Male
Posts: 135
xx Re: Simple Database Framework - Sort by Name
« Reply #8 on: Dec 19th, 2017, 10:50pm »

Thanks.

I my case I am not looking for if it equals 12/2017 but if that field contains that value?
User IP Logged

http://launcestonanalyticalradioscanning.blogspot.com.au/

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Simple Database Framework - Sort by Name
« Reply #9 on: Dec 20th, 2017, 12:01am »

You probably know INSTR but just in case:
Code:
if instr(checkDate$, "12/2017")<> 0 then notice "... 
« Last Edit: Dec 20th, 2017, 12:02am by bplus » User IP Logged

B+
Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3151
xx Re: Simple Database Framework - Sort by Name
« Reply #10 on: Dec 20th, 2017, 03:22am »

You already have the info in the field variable so you donít need to get it from the text box. But what sort of comparison do you want to make? It either equals the given date format or it does not.
User IP Logged

tanger32au
Full Member
ImageImageImageImage


member is offline

Avatar



YIM YIM
Homepage PM

Gender: Male
Posts: 135
xx Re: Simple Database Framework - Sort by Name
« Reply #11 on: Dec 22nd, 2017, 03:33am »

Thanks, that works if it is the ONLY data in that field.

I have some examples below of my data

Mt Artthur - 12/207
12/2017
Freelands - 12/2017
2/12/2017

What I want is to display a notice if the field contains 12/2017, even if it has other data before or after it in that field.
User IP Logged

http://launcestonanalyticalradioscanning.blogspot.com.au/

Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3151
xx Re: Simple Database Framework - Sort by Name
« Reply #12 on: Dec 22nd, 2017, 04:35am »

No, bplus showed you how to find 12/2017 anywhere within the field.

Code:
name$="Mt Artthur - 12/207 12/2017"
if instr(name$, "12/2017")<> 0 then print "yep we found 12/2017"
 


But the data you list contains line breaks. So we need to discuss what a field is. A field would not normally contain line breaks. Databases should contain well structured data and should not mix names and dates.

So if instr( does not solve the problem show us how you open the database and load the data into your field statement or array variable. The line break may be stopping the data being loaded.
User IP Logged

tanger32au
Full Member
ImageImageImageImage


member is offline

Avatar



YIM YIM
Homepage PM

Gender: Male
Posts: 135
xx Re: Simple Database Framework - Sort by Name
« Reply #13 on: Dec 23rd, 2017, 03:19am »

Thanks.

I found the best way was to restructure my data so that the date (12/2017) is the first data in that field.

Instead of:
Mt Arthur - 12/2017
I now use:
12/2017 - Mt Arthur

It works well now, thanks.
User IP Logged

http://launcestonanalyticalradioscanning.blogspot.com.au/

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Simple Database Framework - Sort by Name
« Reply #14 on: Dec 23rd, 2017, 1:50pm »

Hi tanger32au,

Sorry, I am curious, did you know that INSTR can find a string inside a string, so you could find the date in a longer string Data Field.

And you can also sort your data base file on any Data field, so you wouldn't have to rewrite the Data file.

BTW:
Code:
position = INSTR("tanger32au", "32au")
GoodAsGold$ = Mid$("tanger32au", 1, position - 1) + "79" + Right$("tanger32au", 2) 


;D
User IP Logged

B+
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls