?
Solved

Public Prodecure & Enum

Posted on 2006-04-25
5
Medium Priority
?
254 Views
Last Modified: 2010-05-01
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
Comment
Question by:thaburner
5 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 16537492
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
 
LVL 66

Expert Comment

by:Jim Horn
ID: 16537504
This may be it as well...

        reRS.Fields("LogType") = eLogTypes.LoggedIn  'Added .LoggedIn
0
 
LVL 13

Accepted Solution

by:
jmundsack earned 500 total points
ID: 16537840
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 16543049
when vb compiles, it will change all string to number. No way you can retrieve the string after compiled to exe format
0
 

Author Comment

by:thaburner
ID: 16543602
jmundsack i used your GetEnumMemberName Function that worked perfect ya it is a little tideous but it does the trick.
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question