Page 1 of 3

Lookup Table

Posted: Mon Nov 09, 2009 7:07 am
by Tristan
Hi All,

How to make lookup table, example if key F2 or klik button can display list of customer and when enter, cust id can display ?

In Clipper, I use SuperLib Library Function.

Best Regards,
Tristan

Re: Lookup Table

Posted: Mon Nov 09, 2009 8:17 am
by Rathinagiri
I think Sudip would be the right person to answer.

Re: Lookup Table

Posted: Mon Nov 09, 2009 9:53 am
by esgici
Hi Tristan
Tristan wrote:Hi All,

How to make lookup table, example if key F2 or klik button can display list of customer and when enter, cust id can display ?

In Clipper, I use SuperLib Library Function.

Best Regards,
Tristan
What is name of function you use from Superlib ?

Regards

--

Esgici

Re: Lookup Table

Posted: Mon Nov 09, 2009 10:24 am
by sudip
Hello Tristan,

I am only a learner of HMG :)
Some times ago I wrote a function which may solve your problem:
findform.jpg
findform.jpg (27.12 KiB) Viewed 6845 times
Following code may have bugs, but hope will help :)
wAcct.zip
(2.08 KiB) Downloaded 505 times
Please check FindRec() function :)
With best regards.
Sudip

Re: Lookup Table

Posted: Tue Nov 10, 2009 2:09 am
by Tristan
Hi Mr. Esgici,
I use smallkset and smalls function for lookup table.

Hi Mr. Sudip,
Thanks for example, but I get error when compile.

Thanks,
Tristan

Re: Lookup Table

Posted: Tue Nov 10, 2009 2:25 am
by sudip
Hello Tristan,

I didn't send the total source code. I only showed you how to do this :)

Please check following code snippet :

Code: Select all

Function FindRec()
	local mRecno, aAcctnm := {}, i :=0
	netselect("ACCT")
	set order to 2
	mRecno = iif(eof(), 0, recno())
	go top
	dbeval({|| aadd(aAcctnm, acct->acctnm)})
	
	if recno() <> 0
		go (mRecno)
	endif
	
	i := frmFind(aAcctnm)
	
	if i > 0
		netselect("acct")
		set order to tag acctnm
		seek upper(aAcctNm[i])
		RefreshData()
	endif
	
	return nil
	

Function FrmFind(aData)
private aTempData := {}, mPtr := 0

	aeval(aData, {|x| aadd(aTempData, x)})
	
	WinFrmFind()
	frmFind.Center
	frmFind.Activate
	Return (mPtr)


Static function InitFind()
	frmFind.lstFind.deleteallitems()
	aeval(aTempData, {|x| frmFind.lstFind.additem(x)})
	frmFind.lstFind.setfocus()
	return nil
			
	
	
Function WinfrmFind()	
	
DEFINE WINDOW AT 140 , 235 ;
	WIDTH 550 HEIGHT 394 ;
	TITLE "Find"
	MODAL ;
	ON INIT InitFind()

    DEFINE BUTTON cmdOk
           ROW    330
           COL    120
           WIDTH  100
           HEIGHT 28
           ACTION {mPtr := frmFind.lstFind.value, frmFind.release()}
           CAPTION "&Ok"
     END BUTTON  

    DEFINE BUTTON cmdCancel
           ROW    330
           COL    300
           WIDTH  100
           HEIGHT 28
           ACTION {mPtr = 0, frmFind.release()}
           CAPTION "&Cancel"
     END BUTTON  

     DEFINE LISTBOX lstFind
            ROW    0
            COL    0
            WIDTH  541
            HEIGHT 323
            ITEMS {""}
            VALUE 0
            FONTNAME "Lucida Console"
            FONTSIZE 10
            BACKCOLOR {253,254,199}
            ONDBLCLICK {frmFind.cmdOk.action()}
     END LISTBOX  

END WINDOW	
return nil
With best regards.

Sudip

Re: Lookup Table

Posted: Tue Nov 10, 2009 4:11 am
by Tristan
Hi Mr. Sudip,

Why use array not use direct table ? If use array all data should transfer to array, it takes time.

Regards,
Tristan

Re: Lookup Table

Posted: Tue Nov 10, 2009 7:34 am
by sudip
Tristan wrote: Why use array not use direct table ? If use array all data should transfer to array, it takes time.
Because,
1) I want to make the code generic (please check FrmFind() function onwords). This code can be used with any table :)
2) This code can be used with SQL tables also where we store data into array :)
3) Generally Lookup table (in old days we called Master table) is not so big comparing Transaction table :)
4) I am a great admirer of GRID :) Please check VIRTUAL property of GRID in the Reference regarding performance :)

But, I can't say that I am always correct, as I am learning HMG ;)

So, please send your comments regarding this :)

With best regards.

Sudip

Re: Lookup Table

Posted: Tue Nov 10, 2009 7:40 am
by Tristan
Hi Mr. Sudip :P ,

In array only support 4800 line, is it right ? What happen if table have more than 4800 record ?

Thanks for advance.

Regards,
Tristan

Re: Lookup Table

Posted: Tue Nov 10, 2009 8:56 am
by sudip
Tristan wrote: In array only support 4800 line, is it right ? What happen if table have more than 4800 record ?
I just tested to store some fields into an array of a table having 429712 records. It runs fine. So this array has 429712 rows and 3 columns :o

Code: Select all

...
...	
Function TestRecord()
	local i := 0, mTotRec
	aData := {}
	select saledtl
	mTotRec := reccount()
	go top
	main.progressbar_1.value := 0
	do while !eof()
		do events
		i++
		main.label_1.value := ltrim(str(i))+" / "+ltrim(str(mTotRec))
		main.progressbar_1.value := i/mTotRec*100
		aadd(adata, {saleid, styleid, sizeid})
		skip
	enddo
	msgbox("complete")
	go top
	return nil
Harbour is very powerful :D
With best regards.
Sudip