473,471 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How is IIF evaluated?

I have the following:
IIF(Shift2StartHour.SelectedIndex + Shift2StartMinute.SelectedIndex +
Shift2StartAmPm.SelectedIndex = 0, _
-1,GetTimeOfDay(Shift2StartHour.SelectedValue,Shift 2StartMinute.SelectedValue,Shift2StartAmPm.Selecte dValue)

I am getting an error on the GetTimeOfDay function that expects 2 integers
and a string - "Cast from string "" to type 'Integer' is not valid.

This is true, if the SelectedIndex were 0 - But my statement says if all 3
selected indexes are 0, then send back a -1. If I change the GetTimeOfDay
function to 0, then it does send back a -1.

I assume that it evaluates both the true and false results regardless of
what the result is.

Is there a way around this?

Thanks,

Tom
Nov 19 '05 #1
9 1815
tshad,

SelectedValue returns a string not an integer. You need to convert the
SelectedValue to an integer.

GetTimeOfDay(CType(Shift2StartHour.SelectedValue, Int32),
CType(Shift2StartMinute.SelectedValue, Int32),
CType(Shift2StartAmPm.SelectedValue, Int32))

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"tshad" <ts**********@ftsolutions.com> wrote in message
news:u$**************@TK2MSFTNGP15.phx.gbl...
I have the following:
IIF(Shift2StartHour.SelectedIndex + Shift2StartMinute.SelectedIndex +
Shift2StartAmPm.SelectedIndex = 0, _
-1,GetTimeOfDay(Shift2StartHour.SelectedValue,Shift 2StartMinute.SelectedValue,Shift2StartAmPm.Selecte dValue)

I am getting an error on the GetTimeOfDay function that expects 2 integers
and a string - "Cast from string "" to type 'Integer' is not valid.

This is true, if the SelectedIndex were 0 - But my statement says if all 3
selected indexes are 0, then send back a -1. If I change the GetTimeOfDay
function to 0, then it does send back a -1.

I assume that it evaluates both the true and false results regardless of
what the result is.

Is there a way around this?

Thanks,

Tom

Nov 19 '05 #2
IIF is a function, not a language construct. As such, all of its parameters
are evaluated prior to the function getting called - just like any other
function. So, if there is an error evaluating one of the arguments, you will
get an exception. Even if that argument is the one that won't be returned
because of the condition. Doesn't matter, because IIF is just another
function and nothing special. You can write your own equivalent, since IIF
doesn't provide anything special anyway.

"tshad" <ts**********@ftsolutions.com> wrote in message
news:u$**************@TK2MSFTNGP15.phx.gbl...
I have the following:
IIF(Shift2StartHour.SelectedIndex + Shift2StartMinute.SelectedIndex +
Shift2StartAmPm.SelectedIndex = 0, _
-1,GetTimeOfDay(Shift2StartHour.SelectedValue,Shift 2StartMinute.SelectedValue,Shift2StartAmPm.Selecte dValue)

I am getting an error on the GetTimeOfDay function that expects 2 integers
and a string - "Cast from string "" to type 'Integer' is not valid.

This is true, if the SelectedIndex were 0 - But my statement says if all 3
selected indexes are 0, then send back a -1. If I change the GetTimeOfDay
function to 0, then it does send back a -1.

I assume that it evaluates both the true and false results regardless of
what the result is.

Is there a way around this?

Thanks,

Tom

Nov 19 '05 #3
Oops,

I got going there and coverted everything! Of course you don't convert AM,
PM to an Int32.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:ua**************@TK2MSFTNGP12.phx.gbl...
tshad,

SelectedValue returns a string not an integer. You need to convert the
SelectedValue to an integer.

GetTimeOfDay(CType(Shift2StartHour.SelectedValue, Int32),
CType(Shift2StartMinute.SelectedValue, Int32),
CType(Shift2StartAmPm.SelectedValue, Int32))

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"tshad" <ts**********@ftsolutions.com> wrote in message
news:u$**************@TK2MSFTNGP15.phx.gbl...
I have the following:
IIF(Shift2StartHour.SelectedIndex + Shift2StartMinute.SelectedIndex +
Shift2StartAmPm.SelectedIndex = 0, _
-1,GetTimeOfDay(Shift2StartHour.SelectedValue,Shift 2StartMinute.SelectedValue,Shift2StartAmPm.Selecte dValue)

I am getting an error on the GetTimeOfDay function that expects 2
integers and a string - "Cast from string "" to type 'Integer' is not
valid.

This is true, if the SelectedIndex were 0 - But my statement says if all
3 selected indexes are 0, then send back a -1. If I change the
GetTimeOfDay function to 0, then it does send back a -1.

I assume that it evaluates both the true and false results regardless of
what the result is.

Is there a way around this?

Thanks,

Tom


Nov 19 '05 #4
"Marina" <so*****@nospam.com> wrote in message
news:Oi**************@TK2MSFTNGP10.phx.gbl...
IIF is a function, not a language construct. As such, all of its
parameters are evaluated prior to the function getting called - just like
any other function. So, if there is an error evaluating one of the
arguments, you will get an exception. Even if that argument is the one
that won't be returned because of the condition. Doesn't matter, because
IIF is just another function and nothing special. You can write your own
equivalent, since IIF doesn't provide anything special anyway.
That was what I thought, but I wasn't sure.

Thanks,

Tom
"tshad" <ts**********@ftsolutions.com> wrote in message
news:u$**************@TK2MSFTNGP15.phx.gbl...
I have the following:
IIF(Shift2StartHour.SelectedIndex + Shift2StartMinute.SelectedIndex +
Shift2StartAmPm.SelectedIndex = 0, _
-1,GetTimeOfDay(Shift2StartHour.SelectedValue,Shift 2StartMinute.SelectedValue,Shift2StartAmPm.Selecte dValue)

I am getting an error on the GetTimeOfDay function that expects 2
integers and a string - "Cast from string "" to type 'Integer' is not
valid.

This is true, if the SelectedIndex were 0 - But my statement says if all
3 selected indexes are 0, then send back a -1. If I change the
GetTimeOfDay function to 0, then it does send back a -1.

I assume that it evaluates both the true and false results regardless of
what the result is.

Is there a way around this?

Thanks,

Tom


Nov 19 '05 #5
"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:ua**************@TK2MSFTNGP12.phx.gbl...
tshad,

SelectedValue returns a string not an integer. You need to convert the
SelectedValue to an integer.
Actually, it does convert the data.

My problem was that in the 0 position, the value was set to "" and this
caused the problem. I changed it to "0" and it all works fine.

I was just curious that it would check the parameters if it wasn't going to
do the call. Apparently it does and that was what was causing the error.

Thanks,

Tom
GetTimeOfDay(CType(Shift2StartHour.SelectedValue, Int32),
CType(Shift2StartMinute.SelectedValue, Int32),
CType(Shift2StartAmPm.SelectedValue, Int32))

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"tshad" <ts**********@ftsolutions.com> wrote in message
news:u$**************@TK2MSFTNGP15.phx.gbl...
I have the following:
IIF(Shift2StartHour.SelectedIndex + Shift2StartMinute.SelectedIndex +
Shift2StartAmPm.SelectedIndex = 0, _
-1,GetTimeOfDay(Shift2StartHour.SelectedValue,Shift 2StartMinute.SelectedValue,Shift2StartAmPm.Selecte dValue)

I am getting an error on the GetTimeOfDay function that expects 2
integers and a string - "Cast from string "" to type 'Integer' is not
valid.

This is true, if the SelectedIndex were 0 - But my statement says if all
3 selected indexes are 0, then send back a -1. If I change the
GetTimeOfDay function to 0, then it does send back a -1.

I assume that it evaluates both the true and false results regardless of
what the result is.

Is there a way around this?

Thanks,

Tom


Nov 19 '05 #6

"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:eR**************@TK2MSFTNGP12.phx.gbl...
Oops,

I got going there and coverted everything! Of course you don't convert AM,
PM to an Int32.
Right.

In the GetTimeOfDay, I am passing a string in the 3rd parameter.

Tom
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:ua**************@TK2MSFTNGP12.phx.gbl...
tshad,

SelectedValue returns a string not an integer. You need to convert the
SelectedValue to an integer.

GetTimeOfDay(CType(Shift2StartHour.SelectedValue, Int32),
CType(Shift2StartMinute.SelectedValue, Int32),
CType(Shift2StartAmPm.SelectedValue, Int32))

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"tshad" <ts**********@ftsolutions.com> wrote in message
news:u$**************@TK2MSFTNGP15.phx.gbl...
I have the following:
IIF(Shift2StartHour.SelectedIndex + Shift2StartMinute.SelectedIndex +
Shift2StartAmPm.SelectedIndex = 0, _
-1,GetTimeOfDay(Shift2StartHour.SelectedValue,Shift 2StartMinute.SelectedValue,Shift2StartAmPm.Selecte dValue)

I am getting an error on the GetTimeOfDay function that expects 2
integers and a string - "Cast from string "" to type 'Integer' is not
valid.

This is true, if the SelectedIndex were 0 - But my statement says if all
3 selected indexes are 0, then send back a -1. If I change the
GetTimeOfDay function to 0, then it does send back a -1.

I assume that it evaluates both the true and false results regardless of
what the result is.

Is there a way around this?

Thanks,

Tom



Nov 19 '05 #7
Yeah. Quit using IIFs. I mean come on, you wrote the thing and even
you can't decipher what it's trying to do.

Split that rat's nest out into seven lines of code, and make sure that
it's apparent what is happening with a quick glance. You'll have to
actually declare variables and cast the result from
Shift2StartHour.SelectedValue, and in the process you'll discover that
it's handing you a string not an integer.

The only thing that we, as programmers have to judge the talent of
other programmers is their source code. If we see sloppy, half-assed
code like that, we'll naturally assume you're a sloppy, half-ass
programmer and cease trying to help you. Write every line of code as
though it was going to be engraved on your tombstone as the one thing
the world will judge you by for eternity.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #8
"Jason Kester" <ja*********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Yeah. Quit using IIFs. I mean come on, you wrote the thing and even
you can't decipher what it's trying to do.
Of course, I didn't know what it was doing.

That's why I was asking. And if you look at what I said, I surmised what it
was doing and was just trying to get confirmation on that.

Split that rat's nest out into seven lines of code, and make sure that
it's apparent what is happening with a quick glance. You'll have to
actually declare variables and cast the result from
Shift2StartHour.SelectedValue, and in the process you'll discover that
it's handing you a string not an integer.
So you are saying that we shouldn't use functions??????

That is exactly what this was doing. I was using a function!

This function is perfectly valid. And it works fine if my first listitem
has an integer (such as -1) as the value.

Are you say that the IIF is not clear?????

IIF(Shift2StartHour.SelectedIndex + Shift2StartMinute.SelectedIndex +
Shift2StartAmPm.SelectedIndex = 0, _
-1,GetTimeOfDay(Shift2StartHour.SelectedValue,Shift 2StartMinute.SelectedValue,Shift2StartAmPm.Selecte dValue)

IF all 3 dropdowns are selecting the 1st position (SelectedIndex = 0) then
pass back a -1 (no choice was made)
else
Call the GetTimeOfDay function to put the 3 values into an integer
(3hour, 15minute, am = 315).
end if

Seems pretty clear to me.

This is identical to C#s:
Status = age > 20 ? "adult" : "child"

The only thing that we, as programmers have to judge the talent of
other programmers is their source code. If we see sloppy, half-assed
code like that, we'll naturally assume you're a sloppy, half-ass
programmer and cease trying to help you. Write every line of code as
though it was going to be engraved on your tombstone as the one thing
the world will judge you by for eternity.
What is sloppy about it?

This particular line will be used 6 times in one of my pages, where the only
difference is the variables Shift1StartHour, Shift1EndHour, Shift2StartHour,
etc.

Are you saying I should write out 7 lines of code 6 times?

Or write a function (why would I do that if IIF does the job).

Why don't you like IIF?

A good programmer doesn't write new code when there is a function available
and writes new functions if none of the functions available does the job.

Tom
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #9
tshad wrote:
Are you say that the IIF is not clear?????

IIF(Shift2StartHour.SelectedIndex + Shift2StartMinute.SelectedIndex +
Shift2StartAmPm.SelectedIndex = 0, _
-1,GetTimeOfDay(Shift2StartHour.SelectedValue,Shift 2StartMinute.SelectedValue,Shift2StartAmPm.Selecte dValue)
That is exactly what I'm saying. That is just plain ugly. The fact
that it's doing wacky things that you didn't expect should have tipped
you off.

private int GetTimeOfDay(HtmlSelect selStartHour, HtmlSelect
selStartMinute, HtmlSelect selStartAmPm)
{
if (selStartAmPm.SelectedIndex == 0
&& selStartHour.SelectedIndex == 0
&& selStartMinute == 0)
{
return -1;
}

return GetTimeOfDay(selStartHour.Value, selStartMinute.Value,
selStartAmPm.Value);
}
There you go, one more signature for your GetTimeOfDay function, and
you never have to see that hairball IIF again.

Look, immediate ifs have their uses, but they can get unreadable in a
hurry. A good rule of thumb is to never use an IIF (or ()?: ) that
needs a linebreak.
A good programmer doesn't write new code when there is a function available
and writes new functions if none of the functions available does the job.


Exactly my point. All the best!
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

---
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/

Nov 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Heinz | last post by:
Hi there Out of curiosity .... Long time ago I was working with Infomix (now IBM) Universal Server, that had a data type 'html' implemented as data blade. Through data blades you could extend...
6
by: David Isaac | last post by:
Default parameter values are evaluated once when the function definition is executed. Where are they stored? (A guess: in a dictionary local to the function.) Where is this documented? As a...
39
by: | last post by:
I am trying to run the following agregate function in a parameterized query on Access2000: Min(.*sqr(./.)/) The query saved OK, but an attempt to run it results in the message: The expression...
0
by: Arvin Portlock | last post by:
I'm designing a small XML DTD to encode some help documentation. The documentation contains a large number of examples of XML markup. Naturally CDATA was my first thought, but ideally I would like...
6
by: William Payne | last post by:
Consider the following code: struct foo { char* bar; }; // fooptr is of type foo* if(fooptr != NULL && fooptr->bar != NULL) {
3
by: tconkling | last post by:
I have an if statement that looks like this: if(foo(&x) && x > y) ... where the value of x is modified by foo, and the comparison between x and y only makes sense after x has been modified by...
1
by: Gaijinco | last post by:
If I have something like: if (dx<0 and dy>=SIZE and m!=0){ ... } Can I assume that m!=0 would be testes last or to be sure I need to nest it? if (dx<0 and dy>=SIZE){
4
by: Divick | last post by:
Hi, does sizeof operator evaluate the size at compile time or run time ? In other words is sizeof(SomeType) evaluated at compile time or at runtime? Please provide the reasoning involved as well....
1
by: User1014 | last post by:
Since you can pass a function to a ... erm...... function.... how to you use the result of a function as the argument for another function instead of passing the actual function to it. i.e. ...
5
by: Ben | last post by:
Hi, i would like to have an explanation about this: This works, but i get the message in code-behind: access of shared member,... or nested type through an instance; qualifying expression will...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.