Home   Archive   Permalink



converting word values

Hi,
I'm trying to get a small program to type test each field and focus on and print the errors. I am having difficulty get the fld (field) and tp (type) variables out of a table and into a test. the progam doesn't give an error currently when i type invalid data into the first field. here it is:R E B O L []
fldblk:[vi to-integer vdc to-decimal vdt to-date vtm to-time vmn to-money]
errblk: array [5 2]
errchk: func [fldblk errblk ][
    i: 0
    foreach [fld tp] fldblk [
        i: i + 1
        fld: get fld
        if error? try [tp fld ] [errblk/:i/1 fld errblk/:i/2: "Failed to convert"]
    ]
]
view gui: layout[
    vi: field
    vdc: field
    vdt: field
    vtm: field
    vmn: field
    
    button "val" [
        errblk copy []
        errchk fldblk errblk
        either errblk/1/1 == none [
            alert "Good Entry"
        ][
            alert ["Errors" errblk/1/2]
            focus errblk/1/1
            return
        ]
    ]
]
Hope someone can help.

posted by:   John     21-Apr-2014/21:56:44-7:00



Hi John,
    
The answers in http://rebolforum.com/index.cgi?f=printtopic&permalink=John16-Apr-2014/20:27:35-7:00&archiveflag=new should give you what you need here. To be clear:
    
R E B O L []
fldblk: [vi integer! vdc decimal! vdt date! vtm time! vmn money!]
test: func [fc typ] [
     if error? try [
         either not typ = (type? load fc/text) [
             alert rejoin ["ERROR: '" fc/text "' is not of type " typ]
             focus fc
             return
         ] [
             ; alert rejoin ["Good entry: '" fc/text "'"]
         ]
     ] [
         alert rejoin ["ERROR: '" fc/text "' is not a valid data type"]
         focus fc
     ]
]
view g: layout [
     vi: field
     vdc: field
     vdt: field
     vtm: field
     vmn: field
     btn "val" [
         foreach [fac typ] fldblk [
             do rejoin ["test " fac " " typ]
         ]
     ]
]

posted by:   Nick     22-Apr-2014/7:37:27-7:00



BTW, you can stop the validation loop by returning a value from the 'test function. If the loop finishes, then all entries are valid:
    
R E B O L []
fldblk: [vi integer! vdc decimal! vdt date! vtm time! vmn money!]
test: func [fc typ] [
     if error? try [
         either not typ = (type? load fc/text) [
             alert rejoin ["ERROR: '" fc/text "' is not of type " typ]
             focus fc
             return false
         ] [
             ; alert rejoin ["Good entry: '" fc/text "'"]
         ]
     ] [
         alert rejoin ["ERROR: '" fc/text "' is not a valid data type"]
         focus fc
         return false
     ]
]
view g: layout [
     vi: field
     vdc: field
     vdt: field
     vtm: field
     vmn: field
     btn "val" [
         foreach [fac typ] fldblk [
             if false = do rejoin ["test " fac " " typ] [return]
         ]
         alert "All valid entries"
     ]
]

posted by:   Nick     22-Apr-2014/8:42:46-7:00



Thanks. That is what I was looking for. What I have are 30 or 40 fields that need validating. I need a copy of the entered fields in the fldblk (i need to add more array entries) in order to make sure that if some of the fields have changed from their old values that I clear some of the other fields. In addition, I need to goal seek in a way similar to the excel spreadsheet feature that allows a person to calculate one variable by changing another until it reaches a desired value. This can be done to most of the fields on the screen so I probably want a table of the screen values already converted to their data types so I don't have to keep converting to-decimal etc. I don't want a lot of clutter in the screen layout itself so this routine you have given me will help a lot. Thanks again.

posted by:   John     22-Apr-2014/11:51:12-7:00