Home > Blockchain >  Shortcut criteria check with adding decimal as binary
Shortcut criteria check with adding decimal as binary

Time:12-01

good day,

I've made a program that has several prerequisites before proceeding and have written a scoring system to tally if all criteria are met without needing several if statements.

In addition i continue to write if statements if criteria are not met to alert the issue but this too is getting crazy with if a or b or c or d . . . statements is there a quicker mathematical way to summaries this? In some cases i have 6 or 7 prerequisites, isnt there a way i can count remainder or something of decimal to binary?

here is a dummy example of what i mean

dim points as integer
points = 0

if len(range("A1") ) = 6 then points = points   1             'example checks length
if Cdbl(range("B1") ) >= Cdbl(Date) then points = points   2  'example checks if date is in future
if not isempty(range("C1")) then points = points   4          'example checks field is not blank

if points = 7 then
    [do some code]
    msgbox "criteria met"

else

    ' this is what I want summarized with 1 nice mathematical equation

    if points = 1 or points = 3 or points = 5 or points = 7 then
        msgbox "problem is A1"
    end if

    if points = 2 or points = 3 or points = 6 or points = 7 then
        msgbox  "problem is B1"
    end if

    if points = 4 or points = 5 or points = 6 or points = 7 then
        msgbox "problem is C1"
    end if

end if

CodePudding user response:

Yes. You to just need to use And. points And 1 will return 1 (which will be equivalent to true if used that way) if points is odd.

points And 6 will return 6 if the the number in binary ends in 110 or 111.

  • Related