OOrexx dialog questions - REXX
This is a discussion on OOrexx dialog questions - REXX ; On Oct 19, 12:26 pm, Mark Miesfeld <miesf...@gmail.com> wrote:
> ... Here is your program reworked so
> that the 'Reset' button works.
Finally, and this will be my last post on this unless you have more
question, the last ...
-
Re: OOrexx dialog questions
On Oct 19, 12:26 pm, Mark Miesfeld <miesf...@gmail.com> wrote:
> ... Here is your program reworked so
> that the 'Reset' button works.
Finally, and this will be my last post on this unless you have more
question, the last program still has a couple of flaws.
1.) The user can enter non-numeric data in your cells, and you can
never trust users.
2.) Any data the user entered is lost when the dialog is ended.
3.) If the user changed some data, pushed reset, and then cancels, the
original data is lost.
This program fixes all those problems.
/* TableValues.rex */
arg inp
if inp='' then inp=9
/*set up a stem variables*/
a. = 0
a.1.1 = 5.88
a.1.2 = 39.50
a.1.3 = 49.17
a.1.9 = 11.22
a.2.1 = 303.59
a.2.2 = 0
a.2.3 = 28.75
a.3.1 = 1215.66
a.3.2 = 643.98
a.3.5 = 32.76
a.zed=inp
MyDialog=.MyDlgClass~new( , , a.)
if MyDialog~initCode == 0 then do
MyDialog~Execute('ShowTop')
MyDialog~DeInstall
end
else do
say 'Error initializing'
say 'Aborting'
end
return
/***************start dialog*******************************/
::requires 'oodwin32.cls'
::class MyDlgClass subclass userdialog
::method Init
expose a. zed
forward class (super) continue
a. = arg(3)
zed = a.zed
-- Add the total fields and save the original data.
self~calc
self~saveOriginal
/*dialog screen*/
x=(53*zed)+100 ; y=(30*zed)+100
ret=self~CreateCenter(x,y, -
'Test form', , ,'MS Sans Serif', 8)
self~InitCode=(ret=0)
-- We will set the control values ourselves.
::method initAutoDetection
self~noAutoDetection
::method defineDialog
expose a. zed
-- Add the year field
self~AddText(5, 08 ,85 , 8,'Year')
self~AddEntryLine(21,"d",25,05,20,12,"right")
down=30
alpha='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n=90
DO k=1 to zed
tab=10
down=down+15
idBase = k * 100
p=substr(alpha,k,1)
self~AddText(tab,down+3,20, 8,'Line 'p )
Do j=1 to zed
-- Add cell field
cellId = idBase + j
tab=tab+40
self~AddText(tab+9,30 ,25, 8,'Row 'j )
self~AddEntryLine(cellId, , tab,down,35,12,"right")
end
-- Add line total field
lineTotalId = idBase + 50
self~AddEntryLine(lineTotalId, ,tab+45,down,35,12,"right")
end
self~AddBlackRect(45,42,tab-5,down-25)
self~AddText(tab+48,30 ,40, 8,'Line totals' )
tab=10
down=down+30
rowTotalIdBase = (zed + 2) * 100
DO j=1 to zed
-- Add row total fields
rowTotalId = rowTotalIdBase + j
tab=tab+40
self~AddEntryLine(rowTotalId, ,tab,down,35,12,"right")
end
-- Add overall total field
totalTotalId = 40
self~AddText(10,down ,40 , 8,'Row Totals')
tab=tab+45
self~AddText(tab+8,down-10 ,40 , 8,'TOTAL')
self~AddEntryLine(totalTotalId, ,tab,down ,35,12, "right")
-- Add the push buttons
self~AddButton(1,Self~SizeX-180,Self~SizeY-40, -
50,15,'OK','Ok','DEFAULT')
self~AddButton(2,Self~SizeX-120,Self~SizeY-40, -
50,15,'Cancel','Cancel')
self~AddButton(3,Self~SizeX-60,Self~SizeY-40, -
50,15,'Reset', onReset)
self~ConnectButton(3, "reset")
::method InitDialog
expose a. zed
-- Set the year field
self~setEntryLine(21, right(date(),4))
-- Calculate all the totals
self~calc
-- Set all the cell values
do i = 1 to zed
idBase = i * 100
do j = 1 to zed
self~setEntryLine(idBase + j, a.i.j)
end
end
-- Set all the total fields
self~setTotals
::method onReset
if \ self~getCellValues then return
self~calc
self~setTotals
::method ok
if \ self~getCellValues then return 0
self~calc
self~setTotals
return self~ok:super
::method cancel
self~restoreOriginal
return self~cancel:super
::method calc
expose a. zed
do i = 1 to zed
lTotal = 0
do j = 1 to zed
lTotal += a.i.j
end
a.lineTotal.i = lTotal
end
a.total = 0
do j = 1 to zed
rTotal = 0
do i = 1 to zed
rTotal += a.i.j
end
a.RowTotal.j = rTotal
a.total += rTotal
end
::method setTotals
expose a. zed
-- Set the line total fields
do i = 1 to zed
idBase = i * 100
lineTotalId = idBase + 50
self~setEntryLine(lineTotalId, a.lineTotal.i)
end
-- Set the row total fields
rowTotalIdBase = (zed + 2) * 100
do j=1 to zed
rowTotalId = rowTotalIdBase + j
self~setEntryLine(rowTotalId, a.rowTotal.j)
end
-- Set the overall total field
totalTotalId = 40
self~setEntryLine(totalTotalId, a.Total)
::method getCellValues
expose a. zed
-- Make sure all cells contain numbers.
do i = 1 to zed
idBase = i * 100
do j = 1 to zed
tmpVal = self~getEntryLine(idBase + j)
if \ tmpVal~datatype('N') then do
msg = "The cell in line" i "column" j "does not" || '0d0a'x ||
-
"contain a valid number. Please enter" || '0d0a'x ||
-
"only numbers in the cells."
j = errorDialog(msg)
return .false
end
end
end
-- Get all the cell values
do i = 1 to zed
idBase = i * 100
do j = 1 to zed
a.i.j = self~getEntryLine(idBase + j)
end
end
return .true
-- Save the original data. This method assumes that calc() has
-- already been invoked.
::method saveOriginal private
expose a. orig.
self~dupe(a., orig.)
-- Restore the original data. This method assumes that calc() has
-- already been invoked.
::method restoreOriginal private
expose a. orig.
self~dupe(orig., a.)
::method dupe private
expose zed
use strict arg src. dst.
do i = 1 to zed
do j = 1 to zed
dst.i.j = src.i.j
if i = 1 then dst.rowTotal.j = src.rowTotal.j
end
dst.lineTotal.i = src.lineTotal.i
end
dst.total = src.total
--
Mark Miesfeld
-
Re: OOrexx dialog questions
On Oct 19, 1:21 pm, Mark Miesfeld <miesf...@gmail.com> wrote:
> This program fixes all those problems.
Sorry, posted the wrong program. This is the one I meant to post:
/* TableValues.rex */
arg inp
if inp='' then inp=9
/*set up a stem variables*/
a. = 0
a.1.1 = 5.88
a.1.2 = 39.50
a.1.3 = 49.17
a.1.9 = 11.22
a.2.1 = 303.59
a.2.2 = 0
a.2.3 = 28.75
a.3.1 = 1215.66
a.3.2 = 643.98
a.3.5 = 32.76
a.zed=inp
-- show values in a. before
j = show(a.)
MyDialog=.MyDlgClass~new( , , a.)
if MyDialog~initCode == 0 then do
MyDialog~Execute('ShowTop')
MyDialog~DeInstall
end
else do
say 'Error initializing'
say 'Aborting'
end
-- show values in a. after
j = show(a.)
return
/***************start dialog*******************************/
::requires 'oodwin32.cls'
::routine show
use arg a.
zed = a.zed
do i = 1 to zed
do j = 1 to zed
.stdout~charout(a.i.j~right(8))
end
say
end
say
return 0
::class MyDlgClass subclass userdialog
::method Init
expose a. zed
forward class (super) continue
a. = arg(3)
zed = a.zed
-- Add the total fields and save the original data.
self~calc
self~saveOriginal
/*dialog screen*/
x=(53*zed)+100 ; y=(30*zed)+100
ret=self~CreateCenter(x,y, -
'Test form', , ,'MS Sans Serif', 8)
self~InitCode=(ret=0)
-- We will set the control values ourselves.
::method initAutoDetection
self~noAutoDetection
::method defineDialog
expose a. zed
-- Add the year field
self~AddText(5, 08 ,85 , 8,'Year')
self~AddEntryLine(21,"d",25,05,20,12,"right")
down=30
alpha='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n=90
DO k=1 to zed
tab=10
down=down+15
idBase = k * 100
p=substr(alpha,k,1)
self~AddText(tab,down+3,20, 8,'Line 'p )
Do j=1 to zed
-- Add cell field
cellId = idBase + j
tab=tab+40
self~AddText(tab+9,30 ,25, 8,'Row 'j )
self~AddEntryLine(cellId, , tab,down,35,12,"right")
end
-- Add line total field
lineTotalId = idBase + 50
self~AddEntryLine(lineTotalId, ,tab+45,down,35,12,"right")
end
self~AddBlackRect(45,42,tab-5,down-25)
self~AddText(tab+48,30 ,40, 8,'Line totals' )
tab=10
down=down+30
rowTotalIdBase = (zed + 2) * 100
DO j=1 to zed
-- Add row total fields
rowTotalId = rowTotalIdBase + j
tab=tab+40
self~AddEntryLine(rowTotalId, ,tab,down,35,12,"right")
end
-- Add overall total field
totalTotalId = 40
self~AddText(10,down ,40 , 8,'Row Totals')
tab=tab+45
self~AddText(tab+8,down-10 ,40 , 8,'TOTAL')
self~AddEntryLine(totalTotalId, ,tab,down ,35,12, "right")
-- Add the push buttons
self~AddButton(1,Self~SizeX-180,Self~SizeY-40, -
50,15,'OK','Ok','DEFAULT')
self~AddButton(2,Self~SizeX-120,Self~SizeY-40, -
50,15,'Cancel','Cancel')
self~AddButton(3,Self~SizeX-60,Self~SizeY-40, -
50,15,'Reset', onReset)
self~ConnectButton(3, "reset")
::method InitDialog
expose a. zed
-- Set the year field
self~setEntryLine(21, right(date(),4))
-- Calculate all the totals
self~calc
-- Set all the cell values
do i = 1 to zed
idBase = i * 100
do j = 1 to zed
self~setEntryLine(idBase + j, a.i.j)
end
end
-- Set all the total fields
self~setTotals
::method onReset
if \ self~getCellValues then return
self~calc
self~setTotals
::method ok
if \ self~getCellValues then return 0
self~calc
self~setTotals
return self~ok:super
::method cancel
self~restoreOriginal
return self~cancel:super
::method calc
expose a. zed
do i = 1 to zed
lTotal = 0
do j = 1 to zed
lTotal += a.i.j
end
a.lineTotal.i = lTotal
end
a.total = 0
do j = 1 to zed
rTotal = 0
do i = 1 to zed
rTotal += a.i.j
end
a.RowTotal.j = rTotal
a.total += rTotal
end
::method setTotals
expose a. zed
-- Set the line total fields
do i = 1 to zed
idBase = i * 100
lineTotalId = idBase + 50
self~setEntryLine(lineTotalId, a.lineTotal.i)
end
-- Set the row total fields
rowTotalIdBase = (zed + 2) * 100
do j=1 to zed
rowTotalId = rowTotalIdBase + j
self~setEntryLine(rowTotalId, a.rowTotal.j)
end
-- Set the overall total field
totalTotalId = 40
self~setEntryLine(totalTotalId, a.Total)
::method getCellValues
expose a. zed
-- Make sure all cells contain numbers.
do i = 1 to zed
idBase = i * 100
do j = 1 to zed
tmpVal = self~getEntryLine(idBase + j)
if \ tmpVal~datatype('N') then do
msg = "The cell in line" i "column" j || -
"does not" || '0d0a'x || -
"contain a valid number. " || -
"Please enter" || '0d0a'x || -
"only numbers in the cells."
j = errorDialog(msg)
return .false
end
end
end
-- Get all the cell values
do i = 1 to zed
idBase = i * 100
do j = 1 to zed
a.i.j = self~getEntryLine(idBase + j)
end
end
return .true
-- Save the original data. This method assumes that
-- calc() has already been invoked.
::method saveOriginal private
expose a. orig.
self~dupe(a., orig.)
-- Restore the original data. This method assumes that
-- calc() has already been invoked.
::method restoreOriginal private
expose a. orig.
self~dupe(orig., a.)
::method dupe private
expose zed
use strict arg src., dst.
do i = 1 to zed
do j = 1 to zed
dst.i.j = src.i.j
if i = 1 then dst.rowTotal.j = src.rowTotal.j
end
dst.lineTotal.i = src.lineTotal.i
end
dst.total = src.total
--
Mark Miesfeld
-
Re: OOrexx dialog questions
Mark.
Again Thanks for the effort in explaining some of these concepts and
for the program.
It's somewhat of a struggle for someone like me with just basic
programing knowledge
to get a clear understanding just from reading the documentation.
I wish I had found this group earlier.It would have saved a lot of
headbanging and my wall.
I will download and install version 3.2.0 .