mercredi 25 mars 2020

TCL script Need Help to Optimise If and also Correction of the 3rd Output

I have the following code, and would like to know how to:

1) Optimise the "if", so in future if I have 10 new customer_id, I don't have to write 10 time the if-then-else statement, any suggestion?

2) Notice the output for no.3 its wrong, it should not be calculating (divide 1.5) how do I correct it?

TCL Source Script

set VG01 0

set VT01 0

set VG02 0

set VT02 0

set VG03 0

set VT03 0

set VGtable01 150

set VTtable01 15

set VGtable02 250

set VTtable02 25

set VGtable03 350

set VTtable03 35

set sCompareCustomerID01 "0001"

set sCompareCustomerID02 "0002"

set sCompareCustomerID03 "0003"

set sCustomer01 "0001"

set sCustomer02 "0002"

set sCustomer03 "0004"

if {[string compare $sCompareCustomerID01 $sCustomer01 ] == 0 ||

[string compare $sCompareCustomerID02 $sCustomer02 ] == 0 ||

[string compare $sCompareCustomerID03 $sCustomer03 ] == 0 } {

    set VG01 [expr $VGtable01 / 1.5]

    set VT01 [expr $VTtable01 / 1.5]

    set VG02 [expr $VGtable02 / 1.5]

    set VT02 [expr $VTtable02 / 1.5]

    set VG03 [expr $VGtable03 / 1.5]

    set VT03 [expr $VTtable03 / 1.5]


} else {

    set VG01 $VGtable01

    set VT01 $VTtable01

    set VG02 $VGtable02

    set VT02 $VTtable02

    set VG03 $VGtable03

    set VT03 $VTtable03

}

puts "Target Value_Group 01: $VG01"

puts "Target Value_Transaction 01: $VT01"

puts "Target Value_Group 02: $VG02"

puts "Target Value_Transaction 02: $VT02"

puts "Target Value_Group 03 : $VG03"

puts "Target Value_Transaction 03: $VT03"

============

Output:

Import started at 26 Mar 2020 04:09:58.


Loading Script DLL

C:\Program Files (x86)\Common Files\Cubeware\cwscript85.dll

MMM-2020


200325_test division 1.5: Starting jobs at 26 Mar 2020 04:09:58

Execute script: 200325_test division 1.5 - Started at 26 Mar 2020 04:09:58

Target Value_Group 01: 100.0

Target Value_Transaction 01: 10.0

Target Value_Group 02: 166.6666666666667

Target Value_Transaction 02: 16.66666666666667

Target Value_Group 03 : 233.3333333333333 < ------ this should be 350, no calculation require

Target Value_Transaction 03: 23.33333333333333 < ------ this should be 35, no calculation require


Freeing resources

Import completed

Import finished at 26 Mar 2020 04:09:58

Aucun commentaire:

Enregistrer un commentaire