Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing the computer name

Status
Not open for further replies.

FoxEgg

Programmer
Joined
Mar 24, 2002
Messages
749
Location
AU
I have a networked FPD2.6 application which works well (Most machines are running XPPro one is running W2000).

As the administrator, I have a couple of procedure files that I want to allow to be seen on my machine (called XPSERVER) but not on others....

Is there a way I can ask the question

Code:
if this machine is XPSERVER
then 
do x && x is the subroutine I want to run
return

In short ... can I query the name of the machine ?

Thanks in advance


John Fox
 
FoxEgg,
may try GETENV()
Tesar
 
Sys(0) does the trick that I need.

Code:
IF SUBSTR(sys(0), 1, 8) = "XPSERVER"
etc etc

does it all

I think GETENV() is way too clever for this little black duck.

Thank you both VERY MUCH.


FoxEgg
 
FoxEgg,
Be careful of using an explicit offset. I use:
Code:
lcMachine = ""
lcNetUser = ""
IF TYPE("SYS(0)") = "C"
	lcNetTemp = SYS(0)
	lnSep = AT("#", lcNetTemp)
	IF lnSep > 0
		lcMachine = ALLTRIM(LEFT(lcNetTemp, lnSep-1))
		lcNetUser = ALLTRIM(SUBSTR(lcNetTemp, lnSep+1))
	ENDIF
ENDIF
Rick
 
Thanks Rick... Excuse my ignorance...

What is an 'explicit offset', and what is the danger ?

In my situation I used

IF SUBSTR(sys(0), 1, 8) = "XPSERVER"
do something
else
return
endif

Return

JF

Is an explicit offset the designation of naming the computer; in my case 'XPSERVER' ?

Thanks



 
What is an 'explicit offset', and what is the danger ?

The offset is the number of characters you are counting and "explicit" means that you are stating that figure in the code. The danger is that you're assuming that the name will always be 8 characters long. Rick's version will carry on working if the name is a different length.

On the other hand, Rick has quoted "#" as an explicit seperator and one could argue that it too ought to be defined as a constant. There is always a trade off to be made between writing code quickly and writing code that is flexible. Fox has used the "#" character as a seperator for at least 15 years so I think Rick's safe doing this.

Geoff Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top