I don't understand this error I'm getting

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
DavJans
Posts: 240
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

I don't understand this error I'm getting

Post by DavJans » Wed Jul 10, 2019 4:29 pm

I have a datagrid and a button. In the daragrid I have about 9 rows of data that i need to work with. in the putton is the following script

Code: Select all

on mouseUp
   if cutlist_ItemStatus = "Cut" then
      answer "Already Cut"
      BREAK
   end if   
   --lock screen
   put the dgHilitedLines of group "DataGridPartsCutList" into theLines
   repeat for each item tLine in theLines
      put the dgDataOfLine[tLine] of group "DataGridPartsCutList" into theDataA
      put theDataA["id"] into cutlist_tID
      put theDataA["qt"] into cutlist_tQT
      put theDataA["weight"] into cutlist_tWeight
      put theDataA["Piece_mark"] into cutlist_tPcMk
      answer cutlist_tWeight
      put cutlist_tWeight / cutlist_tQT into cutlist_tWeight  ----This line is where the error happens
      if cutlist_tID is not empty then
         if cutlist_tQT <> "1" then
            answer "How many did you cut?" & cr & "PcMk: " & cutlist_tPcMk with "All" and "Some"
            if it is "Some" then
               ask "How many did you cut? (MAX: " & cutlist_tQT - 1 & ")"
               put it into tNumberToCut
               if tNumberToCut > cutlist_tQT - 1 then
                  answer "Invalid Quantity"
                  BREAK
               else
                  send dbOpen to stack "MFC Tracking System"
                  put cutlist_tQT - tNumberToCut into tLeftToCut
                  Put "SELECT material_group, job, lot, sequence, piece_mark, weight, qt, shape, main_mark, dimension, width, grade, length, station, item_status, cutlist_done, material_group_comment, pcmk_comment FROM parts_cutlist WHERE id = '" & cutlist_tID & "'" into tSQL
                  put revDataFromQuery(comma, cr, gConnectionID, tSQL) into tLeftToCut2
                  put tLeftToCut into item 7 of tLeftToCut2
                  put tLeftToCut * cutlist_tWeight into item 6 of tLeftToCut2
                  replace "," with "','" in tLeftToCut2 
                  put "INSERT INTO parts_cutlist (material_group, job, lot, sequence, piece_mark, weight, qt, shape, main_mark, dimension, width, grade, length, station, item_status, cutlist_done, material_group_comment, pcmk_comment) VALUES ('" & tLeftToCut2 & "')" into tSQL
                  revExecuteSQL gConnectionID, tSQL
                  put "UPDATE parts_cutlist SET item_status = 'Cut', qt = '" & tNumberToCut & "', weight = '" & tNumberToCut * cutlist_tWeight & "' WHERE id = '" & cutlist_tID & "'" into tSQL
                  put "SELECT count(id) FROM parts_cutlist WHERE lot = '" & tSL & "' and item_status <> 'Cut'" into cSQL
                  put "INSERT INTO parts_cutlist_log (cutlistID, user, action, dateandtime) VALUES ('" & cutlist_tID & "', '" & qcUser & "', 'Cut', now());" into lSQL
                  revExecuteSQL gConnectionID, tSQL
                  put revDataFromQuery(tab, cr, gConnectionID, cSQL) into tData
                  revExecuteSQL gConnectionID, lSQL
                  if tData = 0 then
                     put "UPDATE parts_cutlist SET cutlist_done = '1'  WHERE lot = '" & tSL & "'" into cdSQL
                     revExecuteSQL gConnectionID, cdSQL
                  end if
                  send dbClose to stack "MFC Tracking System"
               end if
            else
               send dbOpen to stack "MFC Tracking System"
               put "UPDATE parts_cutlist SET item_status = 'Cut' WHERE id = '" & cutlist_tID & "'" into tSQL
               put "SELECT count(id) FROM parts_cutlist WHERE lot = '" & tSL & "' and item_status <> 'Cut'" into cSQL
               put "INSERT INTO parts_cutlist_log (cutlistID, user, action, dateandtime) VALUES ('" & cutlist_tID & "', '" & qcUser & "', 'Cut', now());" into lSQL
               revExecuteSQL gConnectionID, tSQL
               put revDataFromQuery(tab, cr, gConnectionID, cSQL) into tData
               revExecuteSQL gConnectionID, lSQL
               if tData = 0 then
                  put "UPDATE parts_cutlist SET cutlist_done = '1'  WHERE lot = '" & tSL & "'" into cdSQL
                  revExecuteSQL gConnectionID, cdSQL
               end if
               send dbClose to stack "MFC Tracking System"
            end if
         end if
      end if
   end repeat
   put empty into cutlist_tID
   send updateDGCutList to card "parts cutlists"
   send updateDGPartsCutList to card "parts cutlists"
   unlock screen
end mouseUp
I'm getting this error
button "Cut": execution error at line 25 (Operators /: error in left operand), char 1

If you look in the script there is this line:
answer cutlist_tWeight
and it answers with the correct number.

Now. If I click the button again without selecting new line I don't get the error and it works as intended.

Am I missing something obvious or is this a bug, I am still running LiveCode 8.1.10
Attachments
LC Error.JPG
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm"

DavJans
Posts: 240
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: I don't understand this error I'm getting

Post by DavJans » Wed Jul 10, 2019 5:28 pm

I tested this in LiceCode 9.0.4 and get the same error.
In the Screen shot I attached the variables have data in them and 12 / 1 shouldn't be a problem the first time, its not the second time
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm"

DavJans
Posts: 240
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: I don't understand this error I'm getting

Post by DavJans » Wed Jul 10, 2019 9:20 pm

More information on this, I threw in the following script to check a hunch and I was right.

Code: Select all

 if cutlist_tWeight is a number then
         answer "It is a number"
      end if
For some reason it doesn't think its a number. but after the script errors out and I stop it and then click the button again, now it thinks its a number. But that explains why the math fails.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm"

sritcp
Posts: 368
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

Re: I don't understand this error I'm getting

Post by sritcp » Thu Jul 11, 2019 3:47 am

Try inserting

Code: Select all

put cutlist_tWeight + 0 into cutlist_tWeight
before the failing line.

Sri

DavJans
Posts: 240
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: I don't understand this error I'm getting

Post by DavJans » Thu Jul 11, 2019 2:16 pm

Unfortunately that just moved the error up to that line.
Attachments
LC Error.JPG
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm"

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5105
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: I don't understand this error I'm getting

Post by jacque » Thu Jul 11, 2019 4:15 pm

I don't see anything really wrong except for the nonstandard BREAK command. Do you mean for the handler to exit at that point? If so, what happens if you change it to "exit mouseUp"?

Breaks are generally confined to switch constructs, maybe that's confusing the engine for some reason. It's a stretch, but the only thing I noticed after a quick look.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

DavJans
Posts: 240
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: I don't understand this error I'm getting

Post by DavJans » Thu Jul 11, 2019 5:07 pm

Thank you jacque. I didn't even know about that. I've been using BREAK instead of exit mouseUp for 5 years :)

Alas it did not make a difference, however I did some more digging and if I go into the datagrid property inspector contents tab and I manually replace the numbers for the weight column with the same numbers. effectively replacing the data that came from the database with the same data just manually entered it works as expected. So in my mind it tells me that somehow this script is turning an int value in mySQL into a not int even tho it looks like a number...?

Code: Select all

on updateDGPartsCutList
   put the dgVScroll of group "DataGridPartsCutList" into vvscroll
   if the label of btn "StationMenu" <> "All" then
      put the label of btn "StationMenu" into tStationName
      put "SELECT id, job, lot, sequence, piece_mark, weight, qt, shape, main_mark, dimension, grade, FORMAT((length/304.8),3) as length, station, item_status, cutlist_done, pcmk_comment, width from parts_cutlist WHERE lot = '" & tSL & "' AND  job = '" & tSJ & "' AND material_group = '" & tSMG & "' AND station = '" & tStationName & "'" into tQuery
   else
      put "SELECT id, job, lot, sequence, piece_mark, weight, qt, shape, main_mark, dimension, grade, FORMAT((length/304.8),3) as length, station, item_status, cutlist_done, pcmk_comment, width from parts_cutlist WHERE lot = '" & tSL & "' AND  job = '" & tSJ & "' AND material_group = '" & tSMG & "'" into tQuery
   end if
   send dbOpen to stack "MFC Tracking System"
   put revQueryDatabase( gConnectionID, tQuery ) into theCursor
   if item 1 of theCursor = "revdberr" then
      answer error "There was a problem querying the database:" & cr & theCursor
   end if
   if theCursor is an integer then
      ConvertSQLCursorToArray theCursor, theDataGridArray
      put the result into theError
      
      if theError is empty then
         ## The cursor was successfully converted to an array.
         ## Assign it to the data grid. The 'firstname' and 'lastname' columns
         ## from the database cursor will appear in the matching columns
         ## in the data grid.
         set the dgData of group "DataGridPartsCutList" to theDataGridArray
      end if
      
      ## Close the database cursor 
      revCloseCursor theCursor
   end if
   send dbClose to stack "MFC Tracking System"
   set the dgVScroll of group "DataGridPartsCutList" to vvscroll
end updateDGPartsCutList
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm"

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5105
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: I don't understand this error I'm getting

Post by jacque » Thu Jul 11, 2019 5:31 pm

Is the database using UTF-8? If so, maybe you need to textDecode it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

DavJans
Posts: 240
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: I don't understand this error I'm getting

Post by DavJans » Thu Jul 11, 2019 6:47 pm

Collation: utf8_general_ci, is this what you are talking about?

I don't Ill look into textDecode, but I have never had issues like this before. with this very same database
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm"

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5105
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: I don't understand this error I'm getting

Post by jacque » Thu Jul 11, 2019 8:46 pm

Yes, that's UTF-8. In general, when moving data in/out of LC you need to textDecode/textEncode because almost all databases are UTF-8 and LC uses UTF-16. I'm not sure that will fix your problem but it isn't hard to do that and it might tell you something.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

DavJans
Posts: 240
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: I don't understand this error I'm getting

Post by DavJans » Thu Jul 11, 2019 10:23 pm

Thank you jacque, That did the trick. But still not sure why it has never come up in the last 5 years on the same database. also why it would work if you just clicked the button a second time.

Gold star for you, you taught me 2 things today.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm"

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5105
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: I don't understand this error I'm getting

Post by jacque » Fri Jul 12, 2019 12:00 am

If you were running the stack in an older version of LC, we didn't need to worry about encoding back then but since LC 7 we do. If that isn't the case, I have no idea. It's one of those mysteries you could probably track down but probably isn't worth the effort. :)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”