What's wrong with this code?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

What's wrong with this code?

Post by shawnblc » Fri Jun 27, 2014 6:21 pm

What's wrong with this code? I'm getting 'verified' nearly all the time.

Code: Select all

on mouseUp
    put fld "fldReceipt" into tReceipt
    put word 4 of line 1 of URL "http://domain.com/app.php?receipt="&tReceipt&"" into tConfirmation
    
    if tConfirmation = tReceipt then
        put "Verified" into fld "fldReceipt" else
        put "Not Verified" into fld "fldReceipt"
    end if
end mouseUp

Klaus
Posts: 14205
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: What's wrong with this code?

Post by Klaus » Fri Jun 27, 2014 6:30 pm

Hi shawn,

did you verify that the webpage is loading correctly?

Try this:

Code: Select all

on mouseUp
    put fld "fldReceipt" into tReceipt
    put word 4 of line 1 of URL ("http://domain.com/app.php?receipt=" & tReceipt) into tConfirmation
    
    if tConfirmation = tReceipt then
        put "Verified" into fld "fldReceipt" 
    ELSE
        put "Not Verified" into fld "fldReceipt"
    end if
end mouseUp
You can also ANSWER tReceipt and tConfirmation, will cause the "AHA" effect most of the time :D
And "debugging" the script might also help 8)


Best

Klaus

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: What's wrong with this code?

Post by shawnblc » Fri Jun 27, 2014 7:30 pm

When I use the following, both match. Still everything is verified.

Code: Select all


answer tReceipt

Code: Select all

answer tConfirmation

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10335
Joined: Wed May 06, 2009 2:28 pm

Re: What's wrong with this code?

Post by dunbarx » Fri Jun 27, 2014 8:37 pm

Hi.

The code runs fine. What is in fld "tReceipt" at the getgo? I get "tReceipt" from the web page. In other words, what is being compared to what?

Craig

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: What's wrong with this code?

Post by magice » Fri Jun 27, 2014 10:51 pm

I'm not sure if this will help, but I have had trouble in the past with concatenating a string within a URL before. It was probably a problem with the quotation marks, but I fixed it by concatenating the URL string into a variable instead and then using just the variable within the put URL command. This gave me an opportunity to check the url with an answer command before retrieving the data.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10053
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: What's wrong with this code?

Post by FourthWorld » Fri Jun 27, 2014 11:52 pm

When the engine sees this:

Code: Select all

put word 4 of line 1 of URL "http://domain.com/app.php?receipt="&tReceipt&"" into tConfirmation
...it thinks:
1. Get the URL
2. Get line 1 of the value returned from the server
3. Get word 4 of that line
4. Append tReceipt to that
5. Put all that into tConfirmation

To help the engine understand that you want tReceipt appended to the URL rather than the result of the URL, try using parentheses for making the order of evaluation more explicit, as in:

Code: Select all

put word 4 of line 1 of URL ("http://domain.com/app.php?receipt="&tReceipt&"") into tConfirmation
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply