String get cut - Why?

craigachan

Registered User.
Local time
Today, 01:36
Joined
Nov 9, 2007
Messages
285
I have the following code that creates a long string that works most of the time but sometimes gets cut short. I can't understand why it does this. When it cuts the string short it cuts it short in the same place. Everything gets in the string up to/or about the following code '</Practice Name>'

This string is needed to upload info to a server.

Can anyone explain why this works sometimes and sometimes not? thank you.

Code:
dim msg as string

msg = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbCrLf & _
"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & vbCrLf & _
"  <soap:Body>" & vbCrLf & _
"    <UpdateDataForScreens xmlns=""http://mdtoolboxrx.com/"">" & vbCrLf & _
"      <PatientObj>" & vbCrLf & _
"        <ID>" & strPID & "</ID>" & vbCrLf & _
"        <MRN></MRN>" & vbCrLf & _
"        <LastName>" & strLN & "</LastName>" & vbCrLf & _
"        <FirstName>" & strFN & "</FirstName>" & vbCrLf & _
"        <MiddleName>" & strMiddle & "</MiddleName>" & vbCrLf
msg = msg & "        <Gender>" & strGender & "</Gender>" & vbCrLf & _
"        <SSN></SSN>" & vbCrLf & _
"        <DOB>" & strDOB & "</DOB>" & vbCrLf & _
"        <Addr1>" & strAdd1 & "</Addr1>" & vbCrLf & _
"        <Addr2></Addr2>" & vbCrLf & _
"        <City>" & strCity & "</City>" & vbCrLf & _
"        <State>" & strState & "</State>" & vbCrLf & _
"        <Zip>" & strZip & "</Zip>" & vbCrLf & _
"        <HomePh>" & strHomePh & "</HomePh>" & vbCrLf & _
"        <WorkPh></WorkPh>" & vbCrLf & _
"        <CellPh></CellPh>" & vbCrLf
msg = msg & "        <Email></Email>" & vbCrLf & _
"      </PatientObj>" & vbCrLf & _
"      <AccountObj>" & vbCrLf & _
"        <AccountId>" & strAcctID & "</AccountId>" & vbCrLf & _
"        <AccountAuthKey>" & strAcctauthkay & "</AccountAuthKey>" & vbCrLf & _
"        <PracticeId>" & strPractID & "</PracticeId>" & vbCrLf & _
"        <PracticeName>" & strPractName & "</PracticeName>" & vbCrLf & _
"        <UserId>" & strUserID & "</UserId>" & vbCrLf & _
"      </AccountObj>" & vbCrLf & _
"    </UpdateDataForScreens>" & vbCrLf & _
"  </soap:Body>" & vbCrLf & _
"</soap:Envelope>"
 
My guess is you have a value with a character that breaks your xml.

My guess is its a slash (/), double quote ("), single quote ('), a greater than (>) or a less than (<) symbol. Test your data to see if any of your variables every contain one of those characters.
 
Thanks for your insight, but the field just has upper/lower case letters and period after a middle initial. I also have noticed that some days it only displace a portion of the string that fills Practice name. Anything else?
 
Make sure you have no variable that can chop the string.
Something like in strPractName.
A weired character in one of the names might chop it.
 
Could it be you are exceeding the maximum length of a string?

How many characters is it getting chopped at (i.e. len)
 
Thank you everyone.

It seems to chop the end off when string gets to about 1200, but its not consistent. Could be 1125 or 1157

I've tried removing lines with the variables that have no info such as

'" <MRN></MRN>" & vbCrLf & _
'" <SSN></SSN>" & vbCrLf & _

and I can get more info in the msg but it still chops off the end.


Hard coding it with patient info, but it still chops around the end.

The above two changes it will include a little bit more of the code, somtimes up to

<userid>FieldInfo</userid>

and sometimes it will end up like <userid>Fiel and sometimes like

<userid>FieldInfo<use
or
<userid>FieldInfo<useri

It does seem to be acting like I've hit the limits of the length of string, but I thought a string could be 2G. Am I missing something here?
 
I think you have too many string concatenations.

Use interim strings.

Strg = strg & newstrg.
Etc


[edit]
I was posting from a tablet and was struggling to reply. I think too many & vbcrlf in one expression causes the problem. Break into sections.

so

strg = somestuff & somestuff & somestuff
strg = strg & somestuff & somestuff & somestuff
strg = strg & somestuff & somestuff & somestuff

then you shouldn't have any problems.
 
Last edited:
****SOLVED*****Thank you, thank you. That did it. Your post always solve my problems. There is nothing like experience. Thanks again everyone for your input.
 
I dont see how the line continuations would be a problem, unless the long string being build is actually the problem... thus the one last "effective" line going beyond some limit and not the whole thing....

Intresting thing though that that would fix it
 
I dont see how the line continuations would be a problem, unless the long string being build is actually the problem... thus the one last "effective" line going beyond some limit and not the whole thing....

Intresting thing though that that would fix it

Strange result, isn't it.
I've had the same problem previously with too many continuations though.

maybe the whole string is too long for the compiler, so it drops part of it.
 

Users who are viewing this thread

Back
Top Bottom