Hello there.
I am trying to convert value from a remote server to string, then display it on one of the fields inside a form, but unfortunately, I cannot seem to do the conversion even after using Cstr. I have checked the code using the debugger. After using a variant to extract the value in the remote view, I tried assigning a string variable (answer) to the variant using Cstr, but the value couldn’t be assigned. In the Notes Debugger, the value from the view is successfully assigned to the variant, but not from the variant to the string. I wonder what could be wrong? Here’s a portion of the code:-
Sub Click(Source As Button)
Dim s As New NotesSession
Dim sourceDb As NotesDatabase
Dim workspace As New NotesUIWorkspace
Dim destPath As String
Dim serialNo As String
Dim uidoc As NotesUIDocument
Dim view As NotesView
Dim doc As NotesDocument
Dim col As NotesViewColumn
Dim item As Variant
Dim colvals As Variant
Dim answer As String
Set uidoc = workspace.CurrentDocument
serialNo =uidoc.FieldGetText("serialNum")
Set sourceDb = s.GetDatabase("database-name-here")
Set view = sourceDb.GetView("01. Staff \ 01. By Name")
Set doc = view.GetNthDocument(5)
Set col = view.Columns(2)
item = col.ItemName
colvals = doc.GetItemValue(item)
answer = Cstr(colvals)
Call uidoc.FieldSetText("answer", answer)
End Sub
Subject: Cannot convert variant to string
It might be that the line:colvals = doc.GetItemValue(item)
is returning an array and not a single value. In this case You should convert the first index of the array:
answer = Cstr(colvals(0))
Or why do You perform the conversion at all? Why not simply push the value from the item directly into the field “answer”? Like:
Call uidoc.FieldSetText(“answer”,doc.GetItemValue(item))
Is there anything else that is done between the lines that You haven’t included? If so, I can understand the possible need for conversion…
hth
Subject: RE: Cannot convert variant to string
Correct me, if I’m wrong, but FieldSetText expects a String as the second parameter, not an array.
Unless there is any special reason not to do so (like AutoReload being disabled for the NotesUIDocument), you could create a NotesDocument from the UI document and use
Call docCurrent.ReplaceItemValue(“answer”, doc.GetItemValue(item))
or if you prefer to stick with front-end code join the array into a string:
Call uidoc.FieldSetText(“answer”, Join(doc.GetItemValue(item)))
If there could be multiple values in item, you could specify an appropriate separator.
Subject: RE: Cannot convert variant to string
You are absolutely correct - my mistake! Forgot a vital thing about FieldSetText… duh Even the name would/should give me a hint of what it’s doing!
Subject: RE: Cannot convert variant to string
I tried using the Join function and it works perfectly! Thank you very much! 
Subject: RE: Cannot convert variant to string
I tried pushing the value instantly but it didn’t work, but I know how now.
But anyway, thank you so much for the help 