Get Current UserID subroutine (EViews 7)

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Ben Brown (AUS)
Posts: 2
Joined: Sun Oct 27, 2013 6:38 pm

Get Current UserID subroutine (EViews 7)

Postby Ben Brown (AUS) » Sun Oct 27, 2013 7:02 pm

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Get Current UserID subroutine (EViews 7)

Postby EViews Gareth » Sun Oct 27, 2013 7:06 pm

Note that in EViews 8 there is the @env function that returns any Windows environment variable, including username:

Code: Select all

%name = @env("username")

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Get Current UserID subroutine (EViews 7)

Postby EViews Gareth » Sun Oct 27, 2013 7:08 pm

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}

Ben Brown (AUS)
Posts: 2
Joined: Sun Oct 27, 2013 6:38 pm

Re: Get Current UserID subroutine (EViews 7)

Postby Ben Brown (AUS) » Sun Oct 27, 2013 7:20 pm

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!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests