Can one call a program with a parameter

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

bluebird
Posts: 172
Joined: Wed Sep 28, 2016 3:55 am
DBs Used: DBF

Can one call a program with a parameter

Post by bluebird »

Dear Mentors

If I want to run my program with a parameter that tells it what I want included this run,
is that supported in HMG.

Ex.
Myprogram <WithDiagnostics> // this time collect test data

Local lTest:= .F. // no unless asked for by WithDiagnostics parameter
.
.
.
if WithDiagnostics
lTest:=.T.
Endif

....later on
If lTest
... etc.
EndIf
User avatar
dragancesu
Posts: 921
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: Can one call a program with a parameter

Post by dragancesu »

See function PCOUNT()
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Can one call a program with a parameter

Post by mol »

See my sample:

Code: Select all

function DebugMSG
	local i
	local cTemp := ""
	
	
	cTemp := "Call point: "+ ProcName(1)+"(" + alltrim(str(ProcLine(1)))+")" + chr(10)
	for i := 1 to pcount()
		cTemp += "TYPE:" +valtype(hb_PValue(i))+" ->"+hb_valtoexp(hb_PValue(i)) + "<-"+chr(10)
	next i
	msgbox(cTemp, "Debug Informations" )

 return
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Can one call a program with a parameter

Post by serge_girard »

Hi Bluebird,


I use this code for testing:

Code: Select all

PUBLIC XINP_PARAM   
IF PCOUNT() = 0
   XINP_PARAM := 'P'
ELSE
   XINP_PARAM := 'T'
	MSGINFO('TEST!!!!!' ,'XINP_PARAM')
ENDIF
And this program will start on double click in your folder without parameters.

To start with paramters I use a little batchfile:

Code: Select all

START drive:\folder\program T
Serge
There's nothing you can do that can't be done...
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Can one call a program with a parameter

Post by edk »

If you have only one parameter you can use:

Code: Select all

Function Main()
Para WithDiagnostics
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Can one call a program with a parameter

Post by serge_girard »

Hi Kryztof,

Can you please explain: Para WithDiagnostics

Where will input-parameter be stored and how to use it? This is completely new to me!

Thx, Serge
There's nothing you can do that can't be done...
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Can one call a program with a parameter

Post by edk »

Hi Serge.
It's easy, like parameters in functions. When a program is calling with parameters, the defined variables receive the values of those parameters. If there are no parameters, the variable gets Nil.

Here is an example:

Code: Select all

#include "hmg.ch"

Function Main()
PARAMETER FirstParameter, SecondParameter, ThirdParameter

MsgDebug ( FirstParameter, SecondParameter, ThirdParameter )

RETURN
Same functionality but otherwise written:

Code: Select all

#include "hmg.ch"

Function Main( FirstParameter, SecondParameter, ThirdParameter )

MsgDebug ( FirstParameter, SecondParameter, ThirdParameter )

RETURN
Try running an exe without parameters, then with one, two, and three parameters, and you'll see that the variables get their values as character variables.

PS. You can use PARAMETER and PARA interchangeably.

Regards, Edward ;)
User avatar
apais
Posts: 440
Joined: Fri Aug 01, 2008 6:03 pm
DBs Used: DBF
Location: uruguay
Contact:

Re: Can one call a program with a parameter

Post by apais »

Pls note that:
PARAMETETER variables have a scope equivalent to a PRIVATE variable
Variables within parenthesis eg: Main(param), have a scope equivalent to a LOCAL variable
So the PARAMETER sentence must be locate AFTER all local definitions.

HTH
Angel
Angel Pais
Web Apps consultant/architect/developer.
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Can one call a program with a parameter

Post by edk »

+1
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Can one call a program with a parameter

Post by serge_girard »

Thanks all!

Serge
There's nothing you can do that can't be done...
Post Reply