Useful UDF (User defined functions)

Source code related resources

Moderator: Rathinagiri

User avatar
sudip
Posts: 1444
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India
Has thanked: 4 times

Re: Useful UDF (User defined functions)

Post by sudip » Sun Apr 11, 2010 6:38 am

Hello All,

I just created a very simple function to get the selected item from a combobox of a grid. Here it is:

Code: Select all

function GetGridEditComboItem ( cGridName, cWindowName, nColIndex, nComboVal )
   local i := GetControlIndex ( cGridName, cWindowName )
   local aEditcontrols := _HMG_SYSDATA [ 40 ] [ i ] [ 2 ]
   
   if nComboVal >= 1 .and. nComboVal <= len(aEditControls[nColIndex][2])
      return (aEditControls[nColIndex][2][nComboVal])
   endif
return ""
Usage is like:

Code: Select all

 ...        mitemnm := GetGridEditComboItem ( 'proddtl', 'prod', 1, prod.proddtl.cell(i, 1))
         table := sql(mdb, "select rate, uom from item where itemnm = "+c2sql(mitemnm))...
I shall be very happy to receive any good suggestion from you :)

With best regards.

Sudip
With best regards,
Sudip

User avatar
bpd2000
Posts: 963
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 135 times
Been thanked: 43 times

Post by bpd2000 » Sun Sep 18, 2011 5:47 am

Dear All HMG Members

You all are talented persons to create UDF
But since long no new UDF
Please provide UDF used by you for users

Is ther function to retrive HD serial number and computer / Board ID / serial number

Thank you
BPD
Convert Dream into Reality through HMG

User avatar
bpd2000
Posts: 963
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 135 times
Been thanked: 43 times

Post by bpd2000 » Mon Sep 19, 2011 12:27 pm

Roman number related function

Download link

http://ifile.it/2hkav8f/Roman.prg
BPD
Convert Dream into Reality through HMG

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Wed Dec 28, 2011 2:29 pm

bpd2000 wrote:Roman number related function

Download link

http://ifile.it/2hkav8f/Roman.prg
Hi colleague ! Is there any way to put source-code because I can not dowload it.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
esgici
Posts: 4363
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 247 times
Been thanked: 91 times
Contact:

Post by esgici » Wed Dec 28, 2011 2:41 pm

Hi Pablo

You haven't download ticket ;)
Roman.zip
Roman.prg
(2.14 KiB) Downloaded 239 times
Saludos

--

Esgici
Viva INTERNATIONAL HMG :D

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Wed Dec 28, 2011 8:23 pm

Thank you, meritorious colleague Esgici !
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
Rathinagiri
Posts: 5181
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 142 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Fri Mar 23, 2012 6:29 am

Here is a HMG function for exporting arrays to csv files. That will be very much helpful in exporting a report to another software (like Excel)

Code: Select all

#include <hmg.ch>


function array2csv( aInData )

local filename := ""
local lines := 0
local i := 0
local count1 := 0
local linedata := {}
local aData := {}
local cdata := ""
local aclinedata := {}
local fhandle := 0
local linebreak := chr(13)
local aline := {}
local cline := ''

filename :=  PutFile ( {{"Comma Separated Value Files (*.csv)","*.csv"}} , "Export to text file (CSV)" ,  , .f. ) 
if len(alltrim(filename)) == 0
   return nil
endif

if at(".csv",lower(filename)) > 0
   if .not. right(lower(filename),4) == ".csv"
      filename := filename + ".csv"
   endif
else
   filename := filename + ".csv"
endif

if file(filename)
   if .not. msgyesno("Are you sure to overwrite?","Export to text file (CSV)")
      return nil
   endif
endif

fhandle := fcreate(filename)
if fhandle < 0
   msgstop("File "+filename+" could not be created!")
   return nil
endif

for count1 := 1 to len( aInData )
   asize( aclinedata, 0 )
   lineData := aInData[ count1 ]
   for count2 := 1 to len( linedata )
      do case
         case ValType(linedata[count2]) == "N"
            cdata := LTrim( Str( linedata[count2] ) )
         case ValType(linedata[count2]) == "D"
            cdata := dtoc( linedata[count2])
         case ValType(linedata[count2]) == "L"
            cdata := iif(linedata[count2],"TRUE","FALSE")
         otherwise
            cdata := linedata[count2]
      endcase
      aadd(aclinedata,cdata)
   next count2
   aadd(adata,aclone(aclinedata))
next count1
for count1 := 1 to len(adata)
   cline := ''
   aline := adata[count1]
   for count2 := 1 to len(aline)
      cline := cline + '"' + _parsequote(aline[count2]) + '"'
      if .not. count2 == len(aline)
         cline := cline + ','
      endif
   next count2
   cline := cline + linebreak
   fwrite(fhandle,cline)
next count1
if fclose(fhandle)
   msginfo("Exported Successfully!")
else
   msgstop("Error in saving!")
endif
return nil

function _parsequote(cdata)
local i := 0
local cout := ""
for i := 1 to len(cdata)
   if sub str(cdata,i,1) == '"'
      cout := cout + sub str(cdata,i,1) + '"'
   else
      cout := cout + sub str(cdata,i,1)
   endif
next i
return cout   

Remove the space between sub and str.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
mol
Posts: 2879
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 136 times
Been thanked: 72 times
Contact:

Post by mol » Fri Mar 23, 2012 11:03 am

Very fine, Rathi!

I want to post my very little function for gisplay debugging info - when you are debugging program, sometime is easy to display only few variables, not run whole debugger.
There is a little function doing it:

Code: Select all


function DebugMSG
	local i, aTemp := {}
	
	for i := 1 to pcount()
		aadd( aTemp, hb_PValue(i))
	next i
	msgbox(hb_valtoexp(aTemp), "Helpful informations")
 return
 
You can call DebugMSG with many parameters without carrying about their types.

Regards, Marek

User avatar
esgici
Posts: 4363
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 247 times
Been thanked: 91 times
Contact:

Post by esgici » Fri Mar 23, 2012 11:34 am

Thanks Rathi

Useful utilty, nice sample, good work :D

Regards

--

Esgici
Viva INTERNATIONAL HMG :D

User avatar
esgici
Posts: 4363
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 247 times
Been thanked: 91 times
Contact:

Post by esgici » Fri Mar 23, 2012 11:37 am

Thanks Mol

Good job :)

Regards

--

Esgici
Viva INTERNATIONAL HMG :D

Post Reply