I am trying to use a button to calculate the value of a purchase order. I borrowed this code from another portion of my application (which works) and have modified it for the appropriate tables for my button.
This script will be run when I have a set open "one to many" potbl (1)is a table that contains the Vendor information, prttbl (2)is the table that has all the items to be ordered from the vendor. Pobooking is the field that the end result will be stored in.
The script works fine if I only have ONE item to be ordered. However, if I have more than one item the script will only recognize the FIRST item in the prttbl table. In other words there is something wrong with the "While Loop". Can anyone see why this script doesn't work for more than one item?
Thanks
------------------------------
option strict
dim potbl as p
dim prttbl as p
dim calcbook as n
dim subcalc as n
dim response as n
potbl=table.current(1)
prttbl=table.current(2)
calcbook = 0
subcalc = 0
response = ui_msg_box("Booking Status","The current booking is $"+ltrim(str(round(potbl.pobooking,2),10,2))+" do you want to Calculate Booking?",36)
IF response = 6 Then
goto continue
Else
goto bypass
END IF
continue:
potbl.change_begin()
potbl.pobooking = 0
potbl.change_end(.T.)
prttbl.fetch_first()
while .not. prttbl.fetch_eof()
prttbl.change_begin()
subcalc =(prttbl.quantity*prttbl.unit_cost)
calcbook = calcbook+subcalc
prttbl.change_end(.T.)
prttbl.fetch_next()
end while
potbl.change_begin()
potbl.pobooking = calcbook
potbl.change_end(.T.)
sys_send_keys("{F5}")
bypass:
This script will be run when I have a set open "one to many" potbl (1)is a table that contains the Vendor information, prttbl (2)is the table that has all the items to be ordered from the vendor. Pobooking is the field that the end result will be stored in.
The script works fine if I only have ONE item to be ordered. However, if I have more than one item the script will only recognize the FIRST item in the prttbl table. In other words there is something wrong with the "While Loop". Can anyone see why this script doesn't work for more than one item?
Thanks
------------------------------
option strict
dim potbl as p
dim prttbl as p
dim calcbook as n
dim subcalc as n
dim response as n
potbl=table.current(1)
prttbl=table.current(2)
calcbook = 0
subcalc = 0
response = ui_msg_box("Booking Status","The current booking is $"+ltrim(str(round(potbl.pobooking,2),10,2))+" do you want to Calculate Booking?",36)
IF response = 6 Then
goto continue
Else
goto bypass
END IF
continue:
potbl.change_begin()
potbl.pobooking = 0
potbl.change_end(.T.)
prttbl.fetch_first()
while .not. prttbl.fetch_eof()
prttbl.change_begin()
subcalc =(prttbl.quantity*prttbl.unit_cost)
calcbook = calcbook+subcalc
prttbl.change_end(.T.)
prttbl.fetch_next()
end while
potbl.change_begin()
potbl.pobooking = calcbook
potbl.change_end(.T.)
sys_send_keys("{F5}")
bypass:
Comment