2009-08-08 04:01 UTC
I have a form with about 15 text boxes, 5 check boxes, 2 radio buttons. Validating the text boxes is obviously the largest task. I found a great way to define all of the text boxes. I only wanted float numbers, so I wrote a function that returns a float number from a fraction string or float string. To apply this same function to all my text boxes i used a foreach + eval + read. See below:
(defun txtValidateFuncs (/ functionstrings functions varFunc StringFilter)
(dcl_messagebox "validate has been run" "")
(setq StringFilter "0123456789./")
;"txtOrigin"
;"txtRows"
;"txtColumns"
(setq functionstrings
(list
"txtCellX"
"txtCellY"
"txtTextX"
"txtTextY"
"txtTextULX"
"txtTextULY"
"txtRowOffset"
"txtColumnOffset"
"txtGridXOffset"
"txtGridYOffset"
"txtBlockX"
"txtBlockY"
"txtBlockULX"
"txtBlockULY"
"txtXSize"
)
)
(foreach varFunc functionstrings
(eval
(read
(strcat "(dcl_TextBox_SetFilter " varFunc " \"" StringFilter "\")"
"(defun c:" varFunc "_OnKillFocus (/)
(if (not(validateFloatInput (dcl_Control_GetText " varFunc ")))
(progn
(dcl_messagebox \"Please enter a decimal or a fraction.\" \"Invalid Value!\")
(dcl_Control_SetFocus " varFunc ")
)
)
)
")
)
)
)
)
(defun txtValidateFuncs (/ functionstrings functions varFunc StringFilter)
(dcl_messagebox "validate has been run" "")
(setq StringFilter "0123456789./")
;"txtOrigin"
;"txtRows"
;"txtColumns"
(setq functionstrings
(list
"txtCellX"
"txtCellY"
"txtTextX"
"txtTextY"
"txtTextULX"
"txtTextULY"
"txtRowOffset"
"txtColumnOffset"
"txtGridXOffset"
"txtGridYOffset"
"txtBlockX"
"txtBlockY"
"txtBlockULX"
"txtBlockULY"
"txtXSize"
)
)
(foreach varFunc functionstrings
(eval
(read
(strcat "(dcl_TextBox_SetFilter " varFunc " \"" StringFilter "\")"
"(defun c:" varFunc "_OnKillFocus (/)
(if (not(validateFloatInput (dcl_Control_GetText " varFunc ")))
(progn
(dcl_messagebox \"Please enter a decimal or a fraction.\" \"Invalid Value!\")
(dcl_Control_SetFocus " varFunc ")
)
)
)
")
)
)
)
)