Page 1 of 1
how to implement the function iif
Posted: Tue Mar 15, 2016 3:23 pm
by Angel
`Function iif(condition as string, value1 as integer,value2 as integer)
Object frmForm as Form
Caption="Form"
Width=640
Height=480
Center
`Other objects
Object btnButton as Button
Tag=0
Top=10
left=10
`Width=100
`Height=30
Caption="Button1"
Hint="This is a button"
ShowHint=True
`Cursor=crHandPoint
`Bitmap.loadFromFile("bitmap.bmp")
OnClick=btnButton_OnClick
End Object
Object btnButton2 as Button
Tag=0
Top=btnButton.top+btnButton.height
left=10
`Width=100
`Height=30
Caption="Button1"
Hint="This is a button"
ShowHint=True
`Cursor=crHandPoint
`Bitmap.loadFromFile("bitmap.bmp")
`OnClick=btnButton_OnClick
End Object
`End other objects
`Onshow=frmForm_Onshow
`Onclose=frmForm_Onclose
End Object
`frmForm.WindowState=WsMaximized
frmForm.Showmodal
Sub btnButton_OnClick
dim a as integer,b as integer
a=10
b=5
btnbutton2.enabled=iif("a>b",true,false)
End Sub
`===============================================
Function iif(condicion as string,valor1 as integer,valor2 as integer) as integer
if val(condicion)=true then result=valor1 else result=valor2
End Function
how to implement the function iif
Posted: Tue Mar 15, 2016 7:42 pm
by Angel
unfortunately it does not work. Any help?
how to implement the function iif
Posted: Thu Mar 17, 2016 4:19 pm
by Sergio M.
Hi Angel
I think that in fnxbasic val("abc") always return 0
for val(string) the string must be "1234"(numeric).
regards
how to implement the function iif
Posted: Thu Mar 17, 2016 4:41 pm
by Sergio M.
btnbutton2.enabled=iif(a,b)
`=====================================
Function iif(valor1 as integer,valor2 as integer) as boolean
if valor1 > valor2 Then result = True Else result = False
End Function
how to implement the function iif
Posted: Fri Mar 18, 2016 4:42 am
by Angel
Hello Sergio:
Thanks for your answer. Your resolution is valid only for the specific case of the condition a> b. I want a general solution. For example, btnsave.enabled = iif (tabeditor (tabindex) = 2 and rcheditormodified = true, true, false).
For any type of condition,>, <, <>, =, simple or complex.
Best regards.
how to implement the function iif
Posted: Fri Mar 18, 2016 1:53 pm
by Sergio M.
Sorry Angel
I don`t understand what you want to do, in your example you need to have a boolean value; you can pass to the function all the values you want, manage them inside and have the result.
otherwise maybe you want a function that return the datatype
you demand ?
In this case I don`t know if it is possible. ciao.
(excuse me for sintax you know that I don`t speak english)
how to implement the function iif
Posted: Sun May 08, 2016 8:33 pm
by Marco
Hi, i did not tested it but you can try something like this
function iff(cond as string, val1 as integer,val2 as integer) as integer
result=0
select case cond
case ">":if val1>val2 then result=1
case "<":if val1<val2 then result=1
case "=":if val1=val2 then result=1
case ">=":if val1>=val2 then result=1
case "=>":if val1>=val2 then result=1
case "<=":if val1<=val2 then result=1
case "=<":if val1>=val2 then result=1
end select
end function
best regards
how to implement the function iif
Posted: Mon May 16, 2016 4:31 pm
by Angel
Thanks Marco.
how to implement the function iif
Posted: Mon May 16, 2016 8:16 pm
by Marco
Hi, just see i forgot <> you can just added it to it.
It is also possible to create == or other use boolean functions to to this routine.
best regards
how to implement the function iif
Posted: Wed May 18, 2016 11:12 am
by Angel
Your code for IIF function works fine. Thanks Marco.
Example for two simultaneous conditions:
Object frmForm as Form
Caption="Form"
Width=640
Height=480
Center
`Other objects
Object btnButton1 as Button
Tag=0
Top=10
left=10
`Width=100
`Height=30
Caption="Button1"
Hint="This is a button1"
ShowHint=True
End Object
Object btnButton2 as Button
Tag=0
Top=btnButton1.top+btnButton1.height+5
left=10
Caption="Button2"
Hint="This is a button2"
ShowHint=True
OnClick=btnButton2_OnClick
End Object
`End other objects
End Object
frmForm.Showmodal
`============================================================================================================================================
Sub btnButton2_OnClick
dim a as integer, b as integer, c as integer, d as integer
a=19:b=15
c=19: d=18
btnbutton1.enabled=iff(">",a,b,"=",c,d)
End Sub
`============================================================================================================================================
Function iff(cond1 as string, val1 as integer,val2 as integer,cond2 as string, val3 as integer,val4 as integer) as integer
result=0
select case cond1
case "="
select case cond2
case "="
if val1=val2 and val3 =Val4 then result=1
case "<>"
if val1=val2 and val3 <>Val4 then result=1
case ">"
if val1=val2 and val3 >Val4 then result=1
case "<"
if val1=val2 and val3 <Val4 then result=1
case ">="
if val1=val2 and val3 >=Val4 then result=1
case "<="
if val1=val2 and val3 <=Val4 then result=1
end select
case "<>"
select case cond2
case "="
if val1<>val2 and val3 =Val4 then result=1
case "<>"
if val1<>val2 and val3 <>Val4 then result=1
case ">"
if val1<>val2 and val3 >Val4 then result=1
case "<"
if val1<>val2 and val3 <Val4 then result=1
case ">="
if val1<>val2 and val3 >=Val4 then result=1
case "<="
if val1<>val2 and val3 <=Val4 then result=1
end select
case ">"
select case cond2
case "="
if val1>val2 and val3 =Val4 then result=1
case "<>"
if val1>val2 and val3 <>Val4 then result=1
case ">"
if val1>val2 and val3 >Val4 then result=1
case "<"
if val1>val2 and val3 <Val4 then result=1
case ">="
if val1>val2 and val3 >=Val4 then result=1
case "<="
if val1>val2 and val3 <=Val4 then result=1
end select
case "<"
select case cond2
case "="
if val1<val2 and val3 =Val4 then result=1
case "<>"
if val1<val2 and val3 <>Val4 then result=1
case ">"
if val1<val2 and val3 >Val4 then result=1
case "<"
if val1<val2 and val3 <Val4 then result=1
case ">="
if val1<val2 and val3 >=Val4 then result=1
case "<="
if val1<val2 and val3 <=Val4 then result=1
end select
case ">="
select case cond2
case "="
if val1>=val2 and val3 =Val4 then result=1
case "<>"
if val1>=val2 and val3 <>Val4 then result=1
case ">"
if val1>=val2 and val3 >Val4 then result=1
case "<"
if val1>=val2 and val3 <Val4 then result=1
case ">="
if val1<val2 and val3 >=Val4 then result=1
case "<="
if val1>=val2 and val3 <=Val4 then result=1
end select
case "<="
select case cond2
case "="
if val1<=val2 and val3 =Val4 then result=1
case "<>"
if val1<=val2 and val3 <>Val4 then result=1
case ">"
if val1<=val2 and val3 >Val4 then result=1
case "<"
if val1<=val2 and val3 <Val4 then result=1
case ">="
if val1<val2 and val3 >=Val4 then result=1
case "<="
if val1<=val2 and val3 <=Val4 then result=1
end select
end select
end function