mcqueccu Expert Licensed User Longtime User Jan 9, 2021 #1 Formerly I don't have to worry so much about data type as IDE takes care of it for me, Example if i have string variable = "2" and i have integer variable = 2 and I compare, i will get true but no more. Here are two scenarios where that no longer work: I have a php script PHP: echo "failed"; then I also have B4A using okhttputils to get the result B4X: Dim ok As HttpJob ok.Initialize("",Me) ok.Download(mhyurl) Wait For Jobdone (ok As HttpJob) If ok.Success Then Dim res As String res = ok.GetString If res = "failed" Then Log("yes") Else Log("no") End If End If But then I was getting No. I had to do res.trim before the comparism worked and I dont know why because the php does not have any space anywhere in the echo statement Today too I have this scenario. I have some few labels and i set tag for them in the designer as 1,2,3 with same event name i have this code in a label click event B4X: Private Sub lblLeftMenu_Click Dim l As B4XView = Sender Log(l.Tag) Select l.Tag Case 1 Log("1 here") Case 2 Log("2 here") Case 3 Log("3 here") End Select End Sub But then it was also NOT working, when i check the type for l.tag it gives string, so have to declare another integer variable and cast the l.tag before it worked
Formerly I don't have to worry so much about data type as IDE takes care of it for me, Example if i have string variable = "2" and i have integer variable = 2 and I compare, i will get true but no more. Here are two scenarios where that no longer work: I have a php script PHP: echo "failed"; then I also have B4A using okhttputils to get the result B4X: Dim ok As HttpJob ok.Initialize("",Me) ok.Download(mhyurl) Wait For Jobdone (ok As HttpJob) If ok.Success Then Dim res As String res = ok.GetString If res = "failed" Then Log("yes") Else Log("no") End If End If But then I was getting No. I had to do res.trim before the comparism worked and I dont know why because the php does not have any space anywhere in the echo statement Today too I have this scenario. I have some few labels and i set tag for them in the designer as 1,2,3 with same event name i have this code in a label click event B4X: Private Sub lblLeftMenu_Click Dim l As B4XView = Sender Log(l.Tag) Select l.Tag Case 1 Log("1 here") Case 2 Log("2 here") Case 3 Log("3 here") End Select End Sub But then it was also NOT working, when i check the type for l.tag it gives string, so have to declare another integer variable and cast the l.tag before it worked
agraham Expert Licensed User Longtime User Jan 9, 2021 #2 mcqueccu said: I dont know why because the php does not have any space anywhere in the echo statement Click to expand... I think echo appends a newline character to the string. mcqueccu said: when i check the type for l.tag it gives string, so have to declare another integer variable and cast the l.tag before it worked Click to expand... That is expected in some situations, as an example a string "2.0" does not match an integer 2 in a string comparison as the integer 2 is converted to "2". It is always best to do comparisons in the correct type to get the required result. Upvote 0
mcqueccu said: I dont know why because the php does not have any space anywhere in the echo statement Click to expand... I think echo appends a newline character to the string. mcqueccu said: when i check the type for l.tag it gives string, so have to declare another integer variable and cast the l.tag before it worked Click to expand... That is expected in some situations, as an example a string "2.0" does not match an integer 2 in a string comparison as the integer 2 is converted to "2". It is always best to do comparisons in the correct type to get the required result.