Page 1 of 1

Get Current UserID subroutine (EViews 7)

Posted: Sun Oct 27, 2013 7:02 pm
by Ben Brown (AUS)
There doesn't appear to be any @CurrentUserID function that will return the current user's ID.

I have written a subroutine (EViews 7) that uses a Shell command and a temporary table to do just that:

Code: Select all

subroutine GetCurrentUserID(string %outValue) %value = "" %tmpTable = "tmpUserName" if @isobject(%tmpTable) then delete {%tmpTable} endif shell(out={%tmpTable}, t=1000) whoami %value = @upper({%tmpTable}(1,1)) if @isobject(%tmpTable) then delete {%tmpTable} endif %outValue = %value endsub
Here is some sample code that uses the GetCurrentUserID sub:

Code: Select all

%currentUserID= "" call GetCurrentUserID(%currentUserID) @uiprompt(%currentUserID)
Note: This requires an open workfile to write the temporary table to.

Re: Get Current UserID subroutine (EViews 7)

Posted: Sun Oct 27, 2013 7:06 pm
by EViews Gareth
Note that in EViews 8 there is the @env function that returns any Windows environment variable, including username:

Code: Select all

%name = @env("username")

Re: Get Current UserID subroutine (EViews 7)

Posted: Sun Oct 27, 2013 7:08 pm
by EViews Gareth
Also note that in both EViews 7 and 8,the lines:

Code: Select all

if @isobject(%tmpTable) then delete {%tmpTable} endif
can be replaced with a simple:

Code: Select all

delete(noerr) {%tmptable}

Re: Get Current UserID subroutine (EViews 7)

Posted: Sun Oct 27, 2013 7:20 pm
by Ben Brown (AUS)
Note that in EViews 8 there is the @env function that returns any Windows environment variable
Another reason to upgrade to EViews 8... thanks EViews Gareth!