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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two simple UFL functions to return username and machinename

Formula Help

Two simple UFL functions to return username and machinename

by  ScottWebb  Posted    (Edited  )
With Crystal Reports it is possible to write your own functions within a library, Crystal refers to these as UFL's. One approach is to write your function within Visual Basic and make the resulting DLL available to Crystal. The following link provides further information as to how a UFL should be written.

http://support.crystaldecisions.com/communityCS/TechnicalPapers/scr_user_defined_functions.pdf.asp

Two common functions that I use, are to insert in a report the username and PC name of the person who is running a report.

-------include the all the code below within a single class module-------
[color red]
Code:
'********************************************************
'** API DECLARATIONS ************************************
'********************************************************
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" ( _
ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) _
As Long

'**********************************************************
'** Function gets the machinename from win95             **
'** or winNT process	                                 **
'**********************************************************
Function GetNTmachinename() As String
  Dim Buffer As String, size As Long, iret As Long
  Buffer = Space(255)
  size = 255
  iret = GetComputerName(Buffer, size)
  GetNTmachinename = Left$(Buffer, size)
End Function

'*********************************************************
'** Function gets the username from win95               **
'** or winNT process	                                **
'*********************************************************
Function GetNTUser() As String
  Dim sName As String
  Dim lNameLen As Long
  Dim lReturn As Long
    
  lNameLen = 255
  sName = Space(256)
  lReturn = GetUserName(sName, lNameLen)
  If sName = "" Then
      GetNTUser = "(Unknown)"
  Else
      GetNTUser = Left$(sName, InStr(sName, Chr$(0)) - 1)
  End If
End Function
'********************************************************
[/color]

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top