-1

I cannot concatenate 2 strings. The first string is the result of StrConv(), and the second is just a simple string like "K".

These do not work:

MsgBox StrConv("O", vbUnicode) & "K"
MsgBox StrConv("O", vbUnicode) + "K"
MsgBox CStr(StrConv("O", vbUnicode)) & "K"
Dim g(1) As String
g(0) = CStr(StrConv("O", vbUnicode))
g(1) = CStr("K")
MsgBox Join(g(), vbNullString)

The expected result is "OK"

This is a simplified version of StrConv which is enough to see that concatenation is not working. However, my real case would be StrConv(ChrW$(240), 64, 1063)

4
  • Msgbox is not unicode-capable I think. Try Debug.Print as a comparison... Commented Oct 14, 2015 at 20:48
  • @TimWilliams has reason, but is rare that with left function, works, maybe because that left function Inherited from excel cells and all his capabilities. I want an explanation :) . Commented Oct 14, 2015 at 20:52
  • @TimWilliams - I will need MsgBox, because it asks for a response from users. Using the same StrConv line, Debug.Print shows different results on 2 separate machines, while MsgBox shows the same letter that I need. Commented Oct 14, 2015 at 20:55
  • Both answer below are completely wrong. "O" is already Unicode, StrConv("O", vbUnicode) is wrong. Your actual issue is that MsgBox does not support Unicode -- see ms access - How do I display a messagebox with unicode characters in VBA? - Stack Overflow Commented Oct 5, 2021 at 12:25

2 Answers 2

4

From: http://blog.nkadesign.com/2013/vba-unicode-strings-and-the-windows-api/

#If VBA7 Then
    Public Declare PtrSafe Function MessageBoxW Lib "user32" _
                                    (ByVal hwnd As LongPtr, _
                                     ByVal lpText As String, _
                                     ByVal lpCaption As String, _
                                     ByVal wType As Long) As Long
#Else
    Public Declare Function MessageBoxW Lib "user32" _
                    (ByVal hwnd As Long, _
                                 ByVal lpText As String, _
                                 ByVal lpCaption As String, _
                                 ByVal wType As Long) As Long
#End If

Sub tt()


    Dim g(1) As String, r
    g(0) = CStr(StrConv("O", vbUnicode))
    g(1) = "K"
    r = Join(g(), vbNullString)

    MessageBoxW 0, r, StrConv("test", vbUnicode), 0



End Sub
Sign up to request clarification or add additional context in comments.

4 Comments

I like really like the approach! It works with "OK". But for my real data StrConv(ChrW$(240), 64, 1063) returns ð instead of š in the MsgBox. I need š
I don't have anything else to offer - this is really not an area where I'm knowledgeable...
These unicode things are really complicated for me too. I come back to them time to time, but I still cannot build some lasting knowledge here. I really value your input. There is another machine where I have the most of problems of this kind. So maybe I would need to return to your solution and build something on top of it, if the Left method failed on that machine to return the letters I need. The referenced article is really nice too. Thanks!
The link is dead now. Web archive still have it web.archive.org/web/20180823033309/http://blog.nkadesign.com/… (actually that blog post only explain how to display message box with Unicode character. Just use ms access - How do I display a messagebox with unicode characters in VBA? - Stack Overflow instead)
2

There is an extra something being placed in the first string. This is what is not allowing the second part to be seen

Use

MsgBox left(StrConv("O", vbUnicode),1) & "K"

After some research it is placing a null character after each actual character.

So if you want more than one character at a time use this

Msgbox Replace(StrConv("O", vbUnicode),chr(0),"") & "K"

This will allow more than one character at a time.

2 Comments

Nice one. Could've thought about it myself, but i didn't :) I knew that Len of the string becomes 2 after using StrConv on one letter. Thanks!
@ZygD thanks, glad I could help. I did a little more research and found the actual problem. See the edit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.