• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

Public Prodecure & Enum

When I use the insertlog prod. it puts the Number of the Enum ex. LoggedIn = 0 so it saves the Log Type as 0 and not LoggedIn. How can I fix this so it will put logged in and not 0?

Public Enum LogTypes
    LoggedIn
    LoggedOut
    ClientError
    ServerError
    SignOff
    EmployeeControl
    HR_Employees
    Password_Changed
    Other
    Delete_Que
    Customer
    Vendor
    CreatedNewHazMat
    'Add New Logtypes in the frmLog_Delete form
End Enum

Public Function InsertLog(eLogTypes As LogTypes, strDescription As String, Optional bInsertInStatusBar As Boolean)
On Error Resume Next
On Error GoTo errHandler
Dim reRS As MYSQL_RS
Dim reConn As MYSQL_CONNECTION
Set reRS = New MYSQL_RS
Set reConn = New MYSQL_CONNECTION

    If PingServer = True Then
          reConn.OpenConnection strSvrAddress, strMySQLUsername, strMySQLPassword, strSvrSchema, strSvrPort
          reRS.OpenRs "SELECT * FROM log_database", reConn
    Else
        RBox ServerNotFound_Ping
    End If

    reRS.AddNew
        reRS.Fields("LogType") = eLogTypes
        reRS.Fields("EmployeeID") = CurrentUser.UserInfo_EmployeeID
        reRS.Fields("EmployeeName") = CurrentUser.UserInfo_FullName
        reRS.Fields("Date") = Format(Date, "mmm. dd/yyyy")
        reRS.Fields("Time") = Format(Time, "hh:mm:ss")
        reRS.Fields("Description") = strDescription
    reRS.Update
   
    If bInsertInStatusBar = True Then
        Status strDescription
    End If
   
    reRS.CloseRecordset
    reConn.CloseConnection
    Set reRS = Nothing
    Set reConn = Nothing

errHandler:
    If Err.Number <> 0 Then
    EBox Err.Number, Err.Description, Sql, "SQLGetData #" & Erl, "MySQL_Mod.", "GetData"
    End If
End Function
0
thaburner
Asked:
thaburner
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
I'm really not sure if this helps you, but with a function you have to define it AS a variable, then you can set it to whatever in your code...

Public Function InsertLog(eLogTypes As LogTypes, strDescription As String, Optional bInsertInStatusBar As Boolean) As Boolean

'Your Code

'If something then
  InsertLog = True
'else
  InsertLog = False
'End If

End Function
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
This may be it as well...

        reRS.Fields("LogType") = eLogTypes.LoggedIn  'Added .LoggedIn
0
 
jmundsackCommented:
It sounds like you want to access the textual name of the enum member, and I'm afraid you cannot do this.  You would need to supply a translation function that returns the textual name in place of the enum value (which is internally just a Long Integer).  Something like:

Private Function GetEnumMemberName(ByVal Value As LogTypes) As String
    Dim strResult As String
    Select Case Value
        Case LoggedIn: strResult = "LoggedIn"
        ' etc...
        Case Else: Err.Raise 9
    End Select
    GetEnumMemberName = strResult
End Function

This is quite tedious, I know, but if I read your question correctly it's the only way.  You might consider doing something with a collection.  At the start of the program fill up a collection with the textual names in the exact order of the enum values.  Like so:

(global declarations)
Global gEnumMemberNames As Collection

(program startup)
    Set gEnumMemberNames = New Collection
    gEnumMemberNames.Add "LoggedIn"
    ' etc.

(anywhere in code)
    Debug.Print gEnumMemberNames(LoggedIn - 1)
    ' note: need the -1 because the enum base is 0, but the collection base is 1

Alternatively, you could set the enum base to 1 by specifying it explicitly on the first member of the enum:

Public Enum LogTypes
    LoggedIn = 1
    LoggedOut     ' the rest will be incrementally above 1
    ClientError
    ServerError
    ' etc.
End Enum

Then you could access the collection items without the -1, like so:

(anywhere in code)
    Debug.Print gEnumMemberNames(LoggedIn)

HTH -Jon
0
 
EDDYKTCommented:
when vb compiles, it will change all string to number. No way you can retrieve the string after compiled to exe format
0
 
thaburnerAuthor Commented:
jmundsack i used your GetEnumMemberName Function that worked perfect ya it is a little tideous but it does the trick.
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now