Can anyone explain me how to shorten the code I use?

Rob Cozens rcozens at pon.net
Wed Mar 15 11:00:51 EST 2006


Hi William,

> if the text of field "naam1" = empty and the selectedtext of button
> "naam1nivo" = "1"
>  then answer error "Naam van leerling 1 mag niet leeg zijn!"
>  if the text of field "naam1" = empty and the selectedtext of button
> "naam1nivo" = "2"
>  then answer error "Naam van leerling 1 mag niet leeg zijn!"
>  if the text of field "naam1" = empty and the selectedtext of button
> "naam1nivo" = "3"
>  then answer error "Naam van leerling 1 mag niet leeg zijn!"
>  if the text of field "naam1" = empty and the selectedtext of button
> "naam1nivo" = "4"
>  then answer error "Naam van leerling 1 mag niet leeg zijn!"
>  if the text of field "naam1" = empty and the selectedtext of button
> "naam1nivo" = "5"
>  then answer error "Naam van leerling 1 mag niet leeg zijn!"
>  if the text of field "naam1" = empty and the selectedtext of button
> "naam1nivo" = "6"
>  then answer error "Naam van leerling 1 mag niet leeg zijn!"
>  if the text of field "naam1" = empty and the selectedtext of button
> "naam1nivo" = "7"
>  then answer error "Naam van leerling 1 mag niet leeg zijn!"

Note: the following case

>
>  if the text of field "naam1" is not empty and the selectedtext of
> button "naam1nivo" = "..."
>  then answer error "Niveau van leerling 1 mag niet leeg zijn!"
>

triggers a second action in the else clause below

>  if the text of field "naam1" = empty and the selectedtext of button
> "naam1nivo" = "..."
>  then put "" into tData
>  else put field "naam1" && the selection of button "naam1nivo" &cr 
> into tData
>
> So can anyone help to shorten the code (because I have 25 fields)?
>

on processFields
    put  "Naam van leerling 1 mag niet leeg zijn!" into errorMessage -- 
if "1" is constant
    repeat with x = 1 to 25
        put  ("Naam van leerling"&x&"mag niet leeg zijn!") into 
errorMessage -- if "1" changes
        put ("naam"&x&"nivo") into buttonName
        put (the text of field ("naam"&x) = empty) into emptyField
        get the selectedtext of button buttonName
        if  it "..." then
            if not emptyField then answer error errorMessage
            if emptyField then put "" into tData
            else put field ("naam"&x) && the selection of button 
buttonName &cr into tData
        else if emptyField answer error errorMessage
     end repeat
end processFields

Rob Cozens
CCW, Serendipity Software Company

"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."

from "The Triple Foole" by John Donne (1572-1631)




More information about the use-livecode mailing list