.Net Cobol

How would one do this in Cobol .Net?  My main concern is the IsValidData function.  How would I write that in .net cobol using invoke.  I tried

                   invoke type Validator::IsPresent(txtCode) and

                   invoke type Validator::IsDecimal(txtPrice) returning validData

but there is a syntax error with the 'and'.

 

If isValidData() then

    *Do somthing

end if

 

Public Function IsValidData() as Boolean

    Return Validator.IsPresent(txtCode) andalso

                Validator.IsDecimal(txtPrice)

end function

 

Class - Validator

Public Shared Function IsPresent(textbox as Textbox) as Boolean

        if textbox.text = " " then Messagebox.Show("Error")

         return false

         else

          return true

end function.

 

  • You could use something like:

    method-id IsValidData.
    procedure division returning myRet as condition-value.

    if Validator::IsPresent(txtCode) and
    Validator::IsDecimal(txtPrice)
    set myRet to true
    else
    set myRet to false
    end-if
  • Verified Answer

    Or somewhat more concise:

    method-id IsValidData returning myRet as condition-value.
       set myRet to Validator::IsPresent(txtCode) and Validator::IsDecimal(txtPrice)
    end method IsValidData.

    Whether this is better is a matter of opinion, of course; it's just a stylistic difference.

    Personally, since this method has no parameters and is a function of the state of the object, I'd make it a property:

    method-id get property IsValidData returning myRet as conditiion-value.
        set myRet to Validator::IsPresent(txtCode) and Validator::IsDecimal(txtPrice)
    end method.

    Or equivalently:

    property-id IsValidData condition-value.
       getter.
          set property-value to Validator::IsPresent(txtCode) and Validator::IsDecimal(txtPrice)
    end property IsValidData.

    Note all of this assumes Validator is non-null, etc.