IfElse statement works on mac but not windows

In the following code the database server is returning “NewAccount” for the “status” key of the responseDictionary. So it should fall into the ElseIf section. It works on my mac in debug mode and built but when i build and deploy to windows it falls into the Else section. Notice that in an effort to help me debug I replaced all the code in the ElseIf section with a MsgBox and replaced the “fullName” value in the else setion with the “Status” value. I am displaying the UserFullName on the web page and it reads “NewAccount”. I copy and pasted everyhting not commented out. Any help is greatly appreciated.

John

[code] If responseDictionary.value(“status”)=“NoAccess” Then
//no access stuff

ElseIf responseDictionary.value(“status”)=“NewAccount” Then
//msgbox does hot display even though “status” = “NewAccount”
MsgBox “Here I am”
//new account stuff instead of the msgbox

else
Session.UserFullName = responseDictionary.value(“status”) // responseDictionary.Value(“fullName”)
//Session.UserFullName displayed on the web page = “NewAccount”
//initialization stuff

end if[/code]

Are you setting the encoding on those strings before you put them in the dictionary? Literal strings are UTF8 in the IDE and the values you get from the database may not be.

@Greg O’Lone I did not show it in my sample cade but befoe the If statement…

[code]data = socket1.Post(“http://”+Host+"/chaos/GetUserStatus?output=xml&site=xojo", 30)
data = defineEncoding(data, encodings.UTF8)

If InStr(data,"?xml") = 2 Then
Dim reader As New myXMLReader
Dim responseDictionary As New Dictionary
reader.Output = responseDictionary
reader.Parse(data)

If responseDictionary.value(“status”)=“NoAccess” Then …[/code]

That being said. The responseDictionary.value(“status”) does equal “NewAccount”. Copying it to a WebLabel on the web page where it says “NewAccount” I would think confirms that it is properly set and encoded. Also why does it work on the Mac and not Windows?

I have tried taking it out of the ElseIf and into an If statement by itself. Also tried assigning it to a newly dimmed string and test that string instead. Also tried changing the status to and testing for “notfound” instead of “NewAccount”. Nothing works.

This is the xml the database is returning…

[quote]<?xml version="1.0" encoding="UTF-8"?>

notfound
Stephen Sang
false
true
steve@bla.ccom
[/quote]

What does your code look like that is handling the text between the status elements?

Have you tried Select Case as an alternative to IfElse to see if it works on Windows?

[code]Select Case responseDictionary.value(“status”)
Case “NoAccess”
//no access stuff

Case “NewAccount”
//msgbox does hot display even though “status” = “NewAccount”
MsgBox “Here I am”
//new account stuff instead of the msgbox

Else
Session.UserFullName = responseDictionary.value(“status”) // responseDictionary.Value(“fullName”)
//Session.UserFullName displayed on the web page = “NewAccount”
//initialization stuff

End Select[/code]

I have removed all the extra code and replace it with MsgBoxes (see below). Turns out it always drops to the else section on windows.

[code]data = socket1.Post(“http://”+Host+"/chaos/GetUserStatus?output=xml&site=xojo", 30)
data = defineEncoding(data, encodings.UTF8)
MsgBox data

If InStr(data,"?xml") = 2 Then
Dim reader As New myXMLReader
Dim responseDictionary As New Dictionary
reader.Output = responseDictionary
reader.Parse(data)
Dim userStatus As String = responseDictionary.value(“status”)

MsgBox "reader done. Status: "+userStatus //looks good here

if userStatus = “NoAccess” then
MsgBox "If statement NoAccess. Status: "+userStatus //on mac NoAccess hits here

ElseIf userStatus = “notfound” then
MsgBox "If statement notfound. Status: "+userStatus //on mac notfound hits here

else
MsgBox "If statement ACCESS. Status: "+userStatus
//always hits here on windows, userStatus is correct. On Mac only hits here if status is not NoAccess and not notfound.

end if

end if[/code]

Just for grins maybe try ConvertEncoding on windows to something other than UTF8 in case there is some wired invisible character in the string being returned.

Dim userStatus As String = ConvertEncoding(responseDictionary.value(“status”), Encodings.WindowsANSI)

@Tom Dixon you hit the nail on the head. I just found that there is a line feed or carriage return at the end ot the status strings. I thought I had this taken care of in my myXMLReader code. Guess not.

Thanks to all who took a look at this. If you have any suggestions how to quickly handle this kind of problem, I am welcome to any suggestions.

John

Actually, it might not. You can set the text on a WebLabel without an encoding and if there aren’t any “special” characters it’ll probably still “look” right, even if it’s not.

Because the Mac uses UTF8 by default.

FWIW, If you’re bringing data in from any external source, whether it’s an HTTP request or a database or a file, you must set the encoding on the incoming text.

@Greg O’Lone good points. For me the database is mine and so I know what I am getting is UTF8, but just to be, as you point out, I am in the habit of always setting the encoding even with data from my own database.

BTW, I fixed the problem that is the subject of this thread in my XMLReader code. All is good again.