Posts: 117
Threads: 34
Joined: Apr 2022
Reputation:
8
1.
Is the new _IIF limited to only numerics ? Or can I play with strings too ?
2. Can this statement be on one line: p=_iff(p=instr(thing$,"\"): p <= 10, p, p=0)
re: position of "\" must be less than 11 else make it zero
Question two in my mind very iffy. If question #1 is true.
Don't need an code answer for question 2. I could do that in my sleep.
Just thought sub-coding might be possible in a coded line.
Posts: 277
Threads: 46
Joined: May 2022
Reputation:
28
Hi,
In the last two parameters of the function you set its output values. The first for true, the second for false.
Code: (Select All)
| | | a$ = "YES" | | | | result = _IIf(a$ = "YES", 100, 0) | | | | Select Case result | | Case 0: Print "a$ is not YES" | | Case 100: Print "a$ is YES" | | End Select |
Posts: 4,054
Threads: 181
Joined: Apr 2022
Reputation:
231
(12-20-2024, 07:06 PM)doppler Wrote: 2. Can this statement be on one line: p=_iff(p=instr(thing$,"\"): p <= 10, p, p=0)
re: position of "\" must be less than 11 else make it zero
How about:
p=_iff(instr(thing$,"\") <= 10, instr(thing$,"\"), 0)
b = b + ...
Posts: 2,299
Threads: 235
Joined: Apr 2022
Reputation:
116
If iff works with strings why didn't they just name it _stiff?
Pete
- We missed _hitkey by that much!
Posts: 2,299
Threads: 235
Joined: Apr 2022
Reputation:
116
12-21-2024, 12:02 AM
(This post was last modified: 12-21-2024, 12:03 AM by Pete.)
Petr's example as a string I think would be...
Code: (Select All)
| Dim result as String | | a$ = "Yes" | | result = _IIf(a$ = "YES", "a$ is YES", "a$ is not YES" ) | | Print result |
I say think because I haven't downloaded and installed the new version yet.
Someone please correct Steve if I am wrong.
Pete
Posts: 117
Threads: 34
Joined: Apr 2022
Reputation:
8
12-21-2024, 02:00 AM
(This post was last modified: 12-21-2024, 02:07 AM by doppler.)
(12-20-2024, 09:07 PM)bplus Wrote: (12-20-2024, 07:06 PM)doppler Wrote: 2. Can this statement be on one line: p=_iff(p=instr(thing$,"\"): p <= 10, p, p=0)
re: position of "\" must be less than 11 else make it zero
How about:
p=_iff(instr(thing$,"\") <= 10, instr(thing$,"\"), 0) Yes that is the basis of the line. My real question, can I mini sub-code the first parameter of the IFF (test comparison). I thought I could be fancy on the first statement. Since the IFF statements are separated by comma's. Only the last minicoding result is the real test. ie: (p<=10). I only happened to use instr as a question example. The minicoding could be almost anything and referencing other variables to manipulate. Hell for all intended purposes the first statement could be a sub-function call out. ie:
dim share x, p
p=_iff(test,p,p=0)
sub test
x=instr(thing$,"\")
if x<=10 the p=x
end sub
The whole idea of a sub maybe washed up
Posts: 4,054
Threads: 181
Joined: Apr 2022
Reputation:
231
How about:
p = instr(thing$,"\")
p = _iff(p<11, p, 0)
_IFF is just a very brief assignment statement made from a decision.
b = b + ...
Posts: 742
Threads: 105
Joined: Apr 2022
Reputation:
14
12-22-2024, 08:49 PM
(This post was last modified: 12-22-2024, 08:51 PM by madscijr.)
(12-21-2024, 12:02 AM)Pete Wrote: Petr's example as a string I think would be...
Code: (Select All)
| Dim result as String | | a$ = "Yes" | | result = _IIf(a$ = "YES", "a$ is YES", "a$ is not YES" ) | | Print result |
I say think because I haven't downloaded and installed the new version yet.
Someone please correct Steve if I am wrong.
Pete I haven't used the new _IIF command yet, but in VBA (and VB6 if I recall?) you could use IIF to return multiple types.
In QB64 / QB64PE, I had to make seperate functions for different return types, like below, but it would be nice if the built-in _IIF command just worked with whatever type you passed in for parameters 2 & 3 (as long as parameters 2 & 3 aren't 2 different types)...
Code: (Select All) 'Integer
Function IIF% (Condition, IfTrue%, IfFalse%)
If Condition Then IIF% = IfTrue% Else IIF% = IfFalse%
End Function
'String
Function IIFS$ (Condition, IfTrue$, IfFalse$)
If Condition Then IIFS$ = IfTrue$ Else IIFS$ = IfFalse$
End Function
'Long
Function IIFL& (Condition, IfTrue&, IfFalse&)
If Condition Then IIFL& = IfTrue& Else IIFL& = IfFalse&
End Function
'Single
Function IIFSng! (Condition, IfTrue!, IfFalse!)
If Condition Then IIFSng! = IfTrue! Else IIFSng! = IfFalse!
End Function
'Double
Function IIFDbl# (Condition, IfTrue#, IfFalse#)
If Condition Then IIFDbl# = IfTrue# Else IIFDbl# = IfFalse#
End Function
'Float
Function IIFF## (Condition, IfTrue##, IfFalse##)
If Condition Then IIFF## = IfTrue## Else IIFF## = IfFalse##
End Function
'Unsigned Integer
Function IIFUI~% (Condition, IfTrue~%, IfFalse~%)
If Condition Then IIFUI~% = IfTrue~% Else IIFSTR$ = IfFalse~%
End Function
'Etc.
Posts: 388
Threads: 24
Joined: May 2022
Reputation:
66
12-23-2024, 01:15 AM
(This post was last modified: 12-23-2024, 01:16 AM by a740g.
Edit Reason: Add link
)
Quote:but it would be nice if the built-in _IIF command just worked with whatever type you passed in for parameters 2 & 3 (as long as parameters 2 & 3 aren't 2 different types)...
It does.
Posts: 742
Threads: 105
Joined: Apr 2022
Reputation:
14
12-23-2024, 03:53 AM
(This post was last modified: 12-23-2024, 03:55 AM by madscijr.)
(12-23-2024, 01:15 AM)a740g Wrote: Quote:but it would be nice if the built-in _IIF command just worked with whatever type you passed in for parameters 2 & 3 (as long as parameters 2 & 3 aren't 2 different types)...
It does. That's a really cool improvement, thanks guys!
Along those lines, I don't suppose it would be possible (or universally appreciated) to support operator overloading in functions? ie you can define a function x that receives certain parameter types, and define one or more additional functions also called x but receiving different parameters, where the compiler will know which definition to use based on the parameter types sent? In other words, it would allow someone to define a function that works with different parameter types like _iif does.
|