Strange behaviour using "Convert"

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
NigelS
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 83
Joined: Sat Oct 22, 2011 2:37 pm

Strange behaviour using "Convert"

Post by NigelS » Tue Jan 01, 2013 11:01 am

I have a command that loops through an array. This array builds a string of values that will later be used to build a SQL insert. The problem I'm having is on the Convert potion of the code (see images). You'll notice that the first block performs the calculation while the second block does not.

I've included the whole command just for interest. Maybe there's something in there that'll give you a clue of what could be wrong.

Code: Select all

command buildFieldNameAndValuesVariable
   
   global PLNListingDetailArray, gPLNColumnNames, gPLNFieldValues
   local tArrayElement
   local tValue, tCalculatedSeconds, tEnteredDate
   local tItemName
   
   repeat for each element tArrayElement in PLNListingDetailArray 
      put gPLNColumnNames & tArrayElement[3] & "," into gPLNColumnNames
      put empty into tValue
      switch tArrayElement[5]
         case "OptionMenu" -- OptionMenu datatype
            
            if tArrayElement[1] = "PropertyTypeOptionMenu" then
               put the label of button "PropertyTypeOptionMenu" into tItemName
               put char 1 of tItemName into tValue 
               break
            end if
            
            if tArrayElement[1] = "PropertySubtypeOptionMenu" then
               put the label of button "PropertySubtypeOptionMenu" into tItemName
               put char 1 of tItemName into tValue
               break
            end if
            
            if tArrayElement[1] = "AreaOptionMenu" then
               put the label of button "AreaOptionMenu" into tItemName 
               put char 1 of tItemName into tValue
               break
            end if
            
         case "CheckBox" -- CheckBox datatype
            
            if GetAction() = "Add" then 
               put 0 into tValue
            end if 
            
            if tArrayElement[1] = "NoOpenHourCheck" then
               if the hilite of button "NoOpenHourCheck" is true then
                  put 1 into tValue
               end if 
               break
            end if
            
            if tArrayElement[1] = "IsRentalCheck" then
               if the hilite of button "IsRentalCheck" is true then 
                  put 1 into tValue
               end if
               break
            end if
            
            if tArrayElement[1] = "DontContactOwnerCheck" then
               if the hilite of button "DontContactOwnerCheck" is true then 
                  put 1 into tValue
               end if
               break
            end if
            
         case "DateEntryField"
            
            put empty into tEnteredDate
            
            if tArrayElement[1] = "ListDateField" then  
               put field "ListDateField" into tEnteredDate
               --convert tEnteredDate from short date to seconds
               convert tEnteredDate to seconds
               put tEnteredDate into tValue
               break
            end if
            
            if tArrayelement[1] = "ListingExpiryDateField" then 
               put field "ListingExpiryDateField" into tEnteredDate
               --convert tEnteredDate from short date to seconds
               convert tEnteredDate to seconds
               put tEnteredDate into tValue
               break
            end if
            
            if tArrayElement[1] = "OpenHourDateField" then 
               put field "OpenHourDateField" into tEnteredDate
               convert tEnteredDate from short date to seconds
               put tEnteredDate into tValue
               break
            end if
            
      end switch
      
      put gPLNFieldValues & tValue & "," into gPLNFieldValues
      
   end repeat
   
   delete last character of gPLNColumnNames
   
end buildFieldNameAndValuesVariable

Has anyone come across a problem like this and if so what did you do to resolve this?

Thx
Attachments
Screen Shot 2012-12-30 at 12.23.25 PM.png
Second block of code
Screen Shot 2012-12-30 at 12.22.30 PM.png
First Block of Code

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Strange behaviour using "Convert"

Post by jacque » Wed Jan 02, 2013 8:11 pm

The "break" command belongs just before each "case" statement rather than embedded in each "if" clause. I.e.:

Code: Select all

case "OptionMenu" -- OptionMenu datatype
           
            if tArrayElement[1] = "PropertyTypeOptionMenu" then
               put the label of button "PropertyTypeOptionMenu" into tItemName
               put char 1 of tItemName into tValue
            else if ...
             other stuff
          else  if...
            other stuff
         end if
        break -- it goes here
case "other thing"
     if...

Also, in general, use "else if" instead of separate independent "if" statements. When you use only "if", each one will run. When you use "if - else if" the engine will abort the comparison check as soon as it finds a match. It's a fairly trivial point and probably won't cause much difference in your script, but it's a good habit to get into.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply