Page 3 of 4

Re: Useful UDF (User defined functions)

Posted: Sun Apr 11, 2010 6:38 am
by sudip
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

Re: Useful UDF (User defined functions)

Posted: Sun Sep 18, 2011 5:47 am
by bpd2000
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

Re: Useful UDF (User defined functions)

Posted: Mon Sep 19, 2011 12:27 pm
by bpd2000
Roman number related function

Download link

http://ifile.it/2hkav8f/Roman.prg

Re: Useful UDF (User defined functions)

Posted: Wed Dec 28, 2011 2:29 pm
by Pablo César
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.

Re: Useful UDF (User defined functions)

Posted: Wed Dec 28, 2011 2:41 pm
by esgici
Hi Pablo

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

--

Esgici

Re: Useful UDF (User defined functions)

Posted: Wed Dec 28, 2011 8:23 pm
by Pablo César
Thank you, meritorious colleague Esgici !

Re: Useful UDF (User defined functions)

Posted: Fri Mar 23, 2012 6:29 am
by Rathinagiri
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.

Re: Useful UDF (User defined functions)

Posted: Fri Mar 23, 2012 11:03 am
by mol
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

Re: Useful UDF (User defined functions)

Posted: Fri Mar 23, 2012 11:34 am
by esgici
Thanks Rathi

Useful utilty, nice sample, good work :D

Regards

--

Esgici

Re: Useful UDF (User defined functions)

Posted: Fri Mar 23, 2012 11:37 am
by esgici
Thanks Mol

Good job :)

Regards

--

Esgici