INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Formula Help

Two simple UFL functions to return username and machinename by ScottWebb
Posted: 20 Nov 01

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-------

'********************************************************
'** 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
'********************************************************



Back to Business Objects: Crystal Reports 1 Formulas FAQ Index
Back to Business Objects: Crystal Reports 1 Formulas Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close