index dbf character numbers

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: index dbf character numbers

Post by franco »

I have revised EDK`s sample. It is what my problem is.
I changed the starting number with 99999. When starting to enter numbers in text box it does not search one number.
When you hit 9 nothing happens. No scan search.

Code: Select all

#include "hmg.ch"

Function Main


SET CENTURY ON
SET DATE TO ANSI

DEFINE WINDOW test AT 0 , 0 WIDTH 400 HEIGHT 600 TITLE "Demo" MAIN NOSIZE NOMAXIMIZE;
	ON INIT PrepareDBF()

	@ 20,10 TEXTBOX tSeek WIDTH 120 VALUE "" INPUTMASK "9999999999" ;
        ON CHANGE Iif( ! Empty( test.tSeek.Value ) ,  (DBSEEK ( VAL ( test.tSeek.Value )), test.Browse_1.Value := RecNo()) , Nil )
		
	@ 70,10 BROWSE Browse_1 ; 
      OF test ; 
      WIDTH 350 ; 
      HEIGHT 430 ; 
      FONT "Arial" ; 
      SIZE 9 ; 
      HEADERS { "Invoice #","Date", "Customer" } ; 
      WIDTHS { 120,80, 120 } ; 
      WORKAREA INVOICE ; 
      FIELDS { "INV_NUMBER", "INV_DATE", "CustomerID" } ; 
      ON GOTFOCUS Nil;
      ON CHANGE Nil ; 
      ON DBLCLICK Nil ; 
      JUSTIFY { 0,0, 0 } 
	
	
END WINDOW

CENTER WINDOW test
ACTIVATE WINDOW test

Return Nil

***********************************
Function PrepareDBF()
Local aStru := { {"INV_NUMBER", "C", 10, 0}, {"INV_DATE", "D", 8, 0}, {"CustomerID", "N", 10, 0 } }
Local i, k := 99999  
IF ! FILE ( "Invoice.dbf" )
	WAIT WINDOW "Preparing invoice.dbf, please wait ..." NOWAIT
	DBCREATE( "Invoice.dbf", aStru )
	USE Invoice.dbf NEW
	*FOR i := 122222 TO 1 STEP -1
for i := k to 999999
		*IF i % 100 = 0
			k++
		*ENDIF
		DO EVENTS
		APPEND BLANK
		REPLACE inv_number WITH AllTrim( Str ( i ) )
		REPLACE inv_date WITH Date() - k
		REPLACE CustomerId WITH hb_RandomInt ( 1, 1000 )
	NEXT i
	WAIT CLEAR

	CLOSE DATA
ENDIF

IF ! FILE ( "Invoice.ntx" )
	USE Invoice.dbf NEW
	WAIT WINDOW "Preparing invoice.ntx, please wait ..." NOWAIT
	INDEX ON Val ( inv_number ) TO Invoice.ntx
	CLOSE DATA
	WAIT CLEAR
ENDIF

SELECT 1
USE Invoice.dbf Index Invoice.ntx

RETURN
All The Best,
Franco
Canada
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: index dbf character numbers

Post by AUGE_OHR »

hi franco,
franco wrote: Fri Jun 11, 2021 4:14 pm I have revised EDK`s sample. It is what my problem is.
can you provide a small DBF, not Code, so we got "same DBF" Sample to talk

---

you want to search in BROWSE ... how :?:
... do you want to search "increment" :idea:

---

let say cPrefix is 555B and you press 999
normal Index work ASCENDING ...

Code: Select all

555Bxxx999YYYYMMDD
555Bxx999xYYYYMMDD
555Bx999xxYYYYMMDD
555B999xxxYYYYMMDD
but sometimes it is better to use DESCENDING while "last" have bigger Number
have fun
Jimmy
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: index dbf character numbers

Post by franco »

The code above is similar. In my system I do index descending. I have button to reindex. If ascending index descending and vice versa.
My problem is when index is numeric it looks good but can not seek one number at a time.
I think this is incremental search numeric.
All The Best,
Franco
Canada
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: index dbf character numbers

Post by AUGE_OHR »

hi,
franco wrote: Fri Jun 11, 2021 7:22 pm My problem is when index is numeric it looks good but can not seek one number at a time.
I think this is incremental search numeric.
i had look at my Sample and saw that BROWSE

need SET BROWSESYNC ON
have no ONKEY :o

so how to get "input" for "increment search" when have no ONKEY for BROWSE :idea:

Sample for BROWSE using SCOPE and FILTER
viewtopic.php?f=5&t=6940
have fun
Jimmy
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: index dbf character numbers

Post by franco »

I find you can not seek part of a numeric value only all of the value.
if value of textbox is 1. if there is not a value of 1 in table, it will not find and changes the textbox value back to " ".
I am going to work on the substr(alltrim( and see what I get.
All The Best,
Franco
Canada
edk
Posts: 997
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: index dbf character numbers

Post by edk »

franco wrote: Fri Jun 11, 2021 4:14 pm I have revised EDK`s sample. It is what my problem is.
I changed the starting number with 99999. When starting to enter numbers in text box it does not search one number.
When you hit 9 nothing happens. No scan search.
Check this code:
test.7z
(1.35 KiB) Downloaded 103 times
franco.gif
franco.gif (178.22 KiB) Viewed 1330 times
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: index dbf character numbers

Post by franco »

Edk, I spent some time trying to get your program to set focus to text box directly after search so it goes right to number and is ready for
another entry. It would speed up the search.
like enter 9 then 9 so seek would be 99, then enter 1 seek would be 991 automatically without pressing button. Then by pressing enter or dblclick grid to set the table for a calling program to make use of.
Also it would be goo if we could make the grid veiw to be substr(inv_number,5,8 ).
All The Best,
Franco
Canada
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: index dbf character numbers

Post by AUGE_OHR »

hi,
franco wrote: Sun Jun 13, 2021 11:24 pm Edk, I spent some time trying to get your program to set focus to text box directly after search so it goes right to number and is ready for another entry. It would speed up the search.
this is IHMO not the Way.
you need ONKEY with GRID

do you want to work with DBF or ARRAY ?
Edward show you a "virtual" GRID which need Array
franco wrote: Sun Jun 13, 2021 11:24 pm like enter 9 then 9 so seek would be 99, then enter 1 seek would be 991 automatically without pressing button.
so what is your Problem

Code: Select all

LOCAL xValue := HMG_GetLastVirtualKeyDown()
LOCAL Old_Value := SEEKNUM.Text_1.VALUE
      cValue := CHR(xValue)
      IF cValue $ "0123456789"
         Old_Value := Old_Value + cValue
         SEEKNUM.Text_1.VALUE := Old_Value
         Do_Seek(.T.)
franco wrote: Sun Jun 13, 2021 11:24 pm Then by pressing enter or dblclick grid to set the table for a calling program to make use of.
remember navigation in "virtual" GRID does not move Record Pointer of DBF
franco wrote: Sun Jun 13, 2021 11:24 pm Also it would be goo if we could make the grid veiw to be substr(inv_number,5,8 ).

Code: Select all

      ELSEIF xValue = VK_BACK .or. xValue = VK_DELETE
         IF LEN(Old_Value) > 0
            Old_Value := SUBSTR(Old_Value,1,LEN(Old_Value)-1)
            SEEKNUM.Text_1.VALUE := Old_Value
         ELSE
            SEEKNUM.Text_1.VALUE := ""
         ENDIF
         Do_Seek(.T.)
have fun
Jimmy
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: index dbf character numbers

Post by franco »

Thank you all for the help.
I am using browse not grid.
We have spent enough time on this. I am going to leave as it was for now.
It is inconvenient to see list.
1000
10001
1001
10002
1002
It is what it is.
Thanks again
Franco
All The Best,
Franco
Canada
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: index dbf character numbers

Post by AUGE_OHR »

hi
franco wrote: Tue Jun 15, 2021 4:53 pm It is inconvenient to see list.
1000
10001
1001
10002
1002
It is what it is.
Numeric are right align while Character are left align
when using Numeric as Character you must right align to get sort Order

---

if you have a "Prefix" i recommend to use seperate FIELD
it make it more easy to work with SCOPE, FILTER and OrdwildSeek()

SCOPE work on Index for Prefix
FILTER can be very slow ... but with SCOPE Data are reduce
OrdWildSeek() work like LOCATE but on Index so it is faster

Code: Select all

   SEEK( cPrefix )
   IF FOUND()
      SET SCOPEBOTTOM TO ( cPrefix )
      SET SCOPETOP TO ( cPrefix )
   ENDIF

Code: Select all

   IF !EMPTY( cFilter )
      GO TOP
      * LOCATE FOR cFilter $ LTRIM( STR( SEEKNUM->INVOICE ) )
      cSeek := cPrefix
      cSeek += "*" + cFilter + "*"
      OrdWildSeek( cSeek )
      SET FILTER TO ( cFilter $ LTRIM( STR( SEEKNUM->INVOICE ) ) )
   ELSE
      SET FILTER TO
   ENDIF
have fun
Jimmy
Post Reply