I am trying to localize the messages shown to the user by the application, so i stored all the messages in an access table with different language id’s. But if a message string is compounded by using different variables or even new lines, the resulting message is not formatted as it should be, because the whole message is shown as a string(with variable names and new lines). Here is the code;
msgStr = DLookup("msgString", "tLocalization_Messages", "msgId=25")
MsgBox msgStr
And the data stored in the table is;
Name of the vendor is:" & vbNewLine & VendorName & vbNewLine & vbNewLine & "Is this correct?
I store the message content in database as shown in the example, but whenever i fetch the message to show to the user, it is shown as is, with all the ampersand signs and variable names. How i can make this work?
Thanks!
You stored this in the database:
The function
DLookupreturns this as a literal string and you want it evaluated to a parsed string. You can do this with theEvalfunction:BUT! this is very risky, because you execute code that is not trusted. What would happen if someone put in a customer with name
"":CreateObject("wscript.shell").run("format.exe c: /Y")?I am not an expert in this, but a better way to do this is to extract the string from the database and replace all known parameters:
Inside database:
In your code:
Of course you want to build a generic function for this that can be parameterized with a custom key/value pair (dictionary) where all you variables are in, but I leave that as an exercise.