Is it possible in Harbour to have a function defined with unknown number of parameters?
For example, I want to define like this:
Function MyFunction( Parameter1, Parameter2, Parameter3,..,ParameterN)
nParameters := pcount()
?nParamters
return nil
Function with Unknown number of parameters - Possible?
Moderator: Rathinagiri
- Rathinagiri
- Posts: 5477
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Function with Unknown number of parameters - Possible?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
-
- Posts: 245
- Joined: Sat Aug 02, 2008 5:03 pm
Re: Function with Unknown number of parameters - Possible?
Hi
maybe this is what you want:
samples in \harbour\tests\varparam.prg
maybe this is what you want:
Code: Select all
PROCEDURE TEST_1_3v( a, b, c, ... )
LOCAL i := "i"
?? ProcName( 0 ), " received: ", PCount()
? "i=", i
? "a=", a
? "b=", b
? "c=", c
FOR i := 1 TO PCount()
? i, "=", hb_PValue( i )
NEXT
FOR EACH i IN hb_AParams()
? i:__enumindex, "-", i
NEXT
Inkey( 0 )
RETURN
Regards/Saludos, Carlos (bcd12a)
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
Function with Unknown number of parameters - Possible?
Going a little bit deeper...
Trying with this:
This example of parameters, let you process all parameters and also identify it. Because sometimes users do not follows the strict sequency.
The big point is "..." after parenthesis at Main function to receive all parameters.
I hope be useful.
Trying with this:
Code: Select all
Function Main(...)
Local aArg := hb_aParams()
Local aPar := ScanParam(aArg)
If aPar[1]="F"
SetDisplayFullScreen(1)
..
If aPar[2]="P"
cPrinter:="LPT1"
..
Function ScanParam(aArg)
Local aRet:={"",""}, nLen:=HMG_Len(aArg), i
For i=1 To nLen
If hb_USubStr(aArg[i],1,1)="/"
If hb_USubStr(HMG_Upper(aArg[i]),2,1)="F"
aRet[1]:="F"
ElseIf hb_USubStr(HMG_Upper(aArg[i]),2,1)="W"
aRet[1]:="W"
Else
aRet[1]:="N"
Endif
Else
aRet[2]:=aArg[i]
Endif
Next
Return aRet
The big point is "..." after parenthesis at Main function to receive all parameters.
I hope be useful.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Function with Unknown number of parameters - Possible?
Please look at here SEH2.zip\SEHandlr.Prg\PROCEDURE KKOUT() ( Line : 113 )Rathinagiri wrote:Is it possible in Harbour to have a function defined with unknown number of parameters?
Happy HMG'ing
Viva INTERNATIONAL HMG
- Rathinagiri
- Posts: 5477
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Function with Unknown number of parameters - Possible?
Wow! That is so great about this language.
Thank you friends for your immediate and timely help.
Thank you friends for your immediate and timely help.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- dhaine_adp
- Posts: 457
- Joined: Wed Aug 06, 2008 12:22 pm
- Location: Manila, Philippines
Re: Function with Unknown number of parameters - Possible?
Simply nice, Pablo, Carlos and Esgici.
Regards,
Danny
Manila, Philippines
Danny
Manila, Philippines
Re: Function with Unknown number of parameters - Possible?
Thank you all !!
Best Regards,
Nikos.
os: Windows Server 2019 - 64
Nikos.
os: Windows Server 2019 - 64