Originally Posted by
rory
I don't understand your problem. As far as I can tell, you want a function to which you pass a string, it tries to look it up in a database to find a translation, and if it can't find it, it returns that original string. Where is the problem, given that the funciton was passed the information it needs in the first place? What did I miss?
I understand that what I am trying to say is difficult to express. And your remarks also showed me I made a mistake in an earlier explanation. So let me try again:
What you might have missed is the fact that the string I pass to the function is the name of a Constant (not its value like I indicated earlier). That Constant name is used as an identifyer to look up a corresponding translation from a table/array. If that table can not be referenced for whatever reason (e.g. no link to Access database because the file is not present) than the actual value of the constant should be returned.
To correct a previous explanation of the issue:
What I need is:
- To first provide the Constant name to a function (as a string) e.g. "gsSTATUS_RECALCULATING".
- If that function can not do anything based on this string value, the function should then be able to refer to the Constant itself. By referring to the Constant I can assign its value as a return value of the function, e.g. "Recalculating model" (which is the default English translation of the text I was trying to get a translation for).
Obviously the tricky part of my question is that I alternatively need to refer to both the (string) name (as argument of the function) and the Constant itself so I can retrieve its value within that function.
I have difficulty explaning it differently. Perhaps some extra code might help:
The following is part of a class module (mclsTranslate):
[vba]
'-------------------------------------------------------------------------------
' PROCEDURE : sGetVBAText
' Date : 17/01/2008
' Author : Bennie Douma
' Description : Retrieves the VBA text translation that corresponds to a KeyID.
' Returns :
' Parameters : sKeyID - The KeyID of the translation text that needs to be retrieved.
' The KeyID is the defined constant name within parenthesis!
' (e.g. '"gsSTATUS_LOADING_LANG_LABELS"')
'
' Notes : Two static arrays with KeyID's and text need to be loaded before
' this routine can work properly.
' The arrays are 0-based!!!
'
' Date Action
'-------------------------------------------------------------------------------
' 17/01/2008 Initial version
'
Public Function sGetVBAText(ByRef sKeyID As String, Optional ByRef vPlaceValues As Variant) As String
Dim lRecordNo As Long
Const sSOURCE As String = "sGetVBAText()"
On Error Resume Next
' Find the record number in which the KeyID can be found:
lRecordNo = Application.Match(sKeyID, mavVBAKeyIDs(), False)
If Err.Number = 0 Then
' Check if the entry actually does contain a translation:
If Not IsNull(mavVBAText(0, lRecordNo - 1)) Then
' Get the corresponding translation from the text array:
sGetVBAText = CStr(mavVBAText(0, lRecordNo - 1))
' Check if some place holders need to be replaced:
If Not IsMissing(vPlaceValues) Then
sGetVBAText = sReplaceHolders(sGetVBAText, vPlaceValues)
End If
Else
' No translation => Let the receiving routine know that no translation is available:
sGetVBAText = ""
' This is actually the place where I would like to refer to a Constant that is declared with the
'name that is the same as the sKeyID passed on to this function.
'If I can do this, I can let the function return the value of the Constant.
End If
Else
' Also here I would like to do the same as above.
' No matching KeyID => use the default text from the declared constant:
sGetVBAText = ""
Err.Clear
End If
ErrorExit:
Exit Function
ErrorHandler:
If Err.Number <> glHANDLED_ERROR Then Err.Description = Err.Description & " (" & sSOURCE & ")"
If bCentralErrorHandler(msMODULE, sSOURCE) Then
Stop
Resume
Else
Resume ErrorExit
End If
End Function[/vba]
The calling procedure could look like this:
[vba]
' Constant name is same as KeyID in table with translations, and stores default English translation as value:
Public Const gsYes as String = "Yes"
Public gsVBATrans As String
Public Sub sGetTranslatedText()
Dim sText as String
gsVBATrans = mclsTranslate.sGetVBAText("gsYes")
If gsVBATrans = "" Then gsVBATrans = gsYes
sText = gsVBATrans
MsgBox sText
End Sub
[/vba]
If the calling function could provide either the translated text or the default English text, than all my calls from the main code (a lot) could replace the construction above as following:
[vba]MsgBox mclsTranslate.sGetVBAText("gsYes", gsYes)[/vba]
But this would only work if the second parameter in the function could be declared as a constant. And that is not possible as far as I am aware. A workaround is something I am looking for.
Not sure if this makes things any clearer?