Help, my code is half-working...what's wrong?
Hello everyone,
I have a table for recording shipping relating to orders.
A dropdown is used to choose the 'Courier Type', and I need the choice to make 2 changes:
1. to put the correct price in the 'Courier Charge' field.
2. to change the 'Insurance Value' in another dropdown (that calculate the cost to us)
I am using the code below, but it is only populating the 'Courier Charge' field, and not changing the 'Insurance Value' field. What have I done wrong?
I have tried having both changes in brackets, and both without. Ninox added the brackets onto the 'Insurance Value' code itself.
Thanks in advance! Anna
if 'Courier Type' = null then
 'Courier Charge' := null
else
 if 'Courier Type' = 1 then
 'Courier Charge' := 29.99 and ('Insurance Value' := 1)
 else
 if 'Courier Type' = 2 then
 'Courier Charge' := 34.99 and ('Insurance Value' := 2)
 else
 if 'Courier Type' = 3 then
 ('Courier Charge' := 40.99) and ('Insurance Value' := 3)
 else
 if 'Courier Type' = 4 then
 'Courier Charge' := 34.99 and ('Insurance Value' := 1)
 else
 if 'Courier Type' = 5 then
 'Courier Charge' := 39.99 and ('Insurance Value' := 2)
 else
 if 'Courier Type' = 6 then
 'Courier Charge' := 45.99 and ('Insurance Value' := 3)
 else
 if 'Courier Type' = 7 then
 'Courier Charge' := 47.99 and ('Insurance Value' := 1)
 else
 if 'Courier Type' = 8 then
 'Courier Charge' := 53.99 and ('Insurance Value' := 2)
 else
 if 'Courier Type' = 9 then
 'Courier Charge' := 59.99 and ('Insurance Value' := 3)
 else
 if 'Courier Type' = 10 then
 'Courier Charge' := 21.99 and ('Insurance Value' := 1)
 else
 if 'Courier Type' = 11 then
 'Courier Charge' := 26.99 and ('Insurance Value' := 2)
 else
 if 'Courier Type' = 12 then
 'Courier Charge' := 32.99 and ('Insurance Value' := 3)
 else
 if 'Courier Type' = 13 then
 'Courier Charge' := 16.99 and ('Insurance Value' := 1)
 else
 if 'Courier Type' = 14 then
 'Courier Charge' := 22.99 and ('Insurance Value' := 2)
 else
 if 'Courier Type' = 15 then
 'Courier Charge' := 28.99 and ('Insurance Value' := 3)
 else
 if 'Courier Type' = 16 then
 'Courier Charge' := 9.25
 else
 if 'Courier Type' = 17 then
 'Courier Charge' := 10.99
 else
 if 'Courier Type' = 18 then
 'Courier Charge' := null
 else
 if 'Courier Type' = 19 then
 'Courier Charge' := 89.98 and ('Insurance Value' := 1)
 else
 if 'Courier Type' = 20 then
 'Courier Charge' := null
 else
 if 'Courier Type' = 21 then
 'Courier Charge' := 25
 else
 if 'Courier Type' = 22 then
 'Courier Charge' := 1
 else
 if 'Courier Type' = 23 then
 'Courier Charge' := 1.5
 else
 if 'Courier Type' = 24 then
 'Courier Charge' := 101.98 and ('Insurance Value' := 2)
 else
 if 'Courier Type' = 25 then
 'Courier Charge' := 113.98 and ('Insurance Value' := 3)
 end
 
3 replies
- 
  Hi Anna You need to change each if 'Courier Type' = 1 then 
 'Courier Charge' := 29.99 and ('Insurance Value' := 1)To if 'Courier Type' = 1 then 
 'Courier Charge' := 29.99;'Insurance Value' := 1 Although, with this number of types, charges and values they would be better put into a table with the type selected and the charge and type returned. It will give you an easier way to maintain your system too. Regards John 
- 
  I just want to add that a switch() statement would improve readability... switch 'Courier Type' docase null:'Courier Charge' := nullcase 1:('Courier Charge' := 29.99;'Insurance Value' := 1)case 2:('Courier Charge' := 34.99;'Insurance Value' := 2)case 3:('Courier Charge' := 40.99;'Insurance Value' := 3)case 4:('Courier Charge' := 34.99;'Insurance Value' := 1)case 5:('Courier Charge' := 39.99;'Insurance Value' := 2)case 6:('Courier Charge' := 45.99;'Insurance Value' := 3)case 7:('Courier Charge' := 47.99;'Insurance Value' := 1)case 8:('Courier Charge' := 53.99;'Insurance Value' := 2)case 9:('Courier Charge' := 59.99;'Insurance Value' := 3)case 10:('Courier Charge' := 21.99;'Insurance Value' := 1)case 11:('Courier Charge' := 26.99;'Insurance Value' := 2)case 12:('Courier Charge' := 32.99;'Insurance Value' := 3)case 13:('Courier Charge' := 16.99;'Insurance Value' := 1)case 14:('Courier Charge' := 22.99;'Insurance Value' := 2)case 15:('Courier Charge' := 28.99;'Insurance Value' := 3)case 16:'Courier Charge' := 9.25case 17:'Courier Charge' := 10.99case 18:'Courier Charge' := nullcase 19:('Courier Charge' := 89.98;'Insurance Value' := 1)case 20:'Courier Charge' := nullcase 21:'Courier Charge' := 25case 22:'Courier Charge' := 1case 23:'Courier Charge' := 1.5case 24:('Courier Charge' := 101.98;'Insurance Value' := 2)case 25:('Courier Charge' := 113.98;'Insurance Value' := 3)endThe indentation doesn't show up on this forum, but in the code editor there is a big difference between the two approaches.
- 
  Hi Anna John is giving good advise in suggesting you towards having the pricing as a lookup in a separate table. It will be easier in the long run for for maintenace when your pricing changes 
Content aside
- 4 yrs agoLast active
- 3Replies
- 265Views
