Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statement problem 1

Status
Not open for further replies.

920506

Programmer
Jun 13, 2003
201
US


Hi everyone,

can I do the following:

If countRS.EOF or ( (Not CountRS.EOF) and ( CInt(CountRS.fields("submitCount"))<4 ) ) then

do something here

End if
What I am trying to do is merge the following code:

if countRS.EOF then
do something
End
If ( (Not CountRS.EOF) and ( CInt(CountRS.fields("submitCount"))<4 ) ) then
do same something as in case if countRS.EOF
End if

I got "Exception occurred" error message, when countRS is empty. Can you help?
Betty
 
not sure what you are trying to do here but...

Code:
if countRS.EOF  then
 do something
else
 If CInt(CountRS.fields("submitCount"))<4 then
   'do something else
 End if
End if

-DNG
 
Hi DNG,
Thanks for the reply.
What I am trying to do is

1----if countRS.EOF then
2---- do something
3----else
4----- If CInt(CountRS.fields("submitCount"))<4 then
5----- do same thing as line 2
6----- End if
7----- End if
That's why I am trying to merge the code into one if statement, while when countRS.EOF=True, you cannot really use CInt(CountRS.fields("submitCount")) statement, that's where exception comes from. I guess I have design issue.
Betty
 
Suppose in VB you have:
[tt]IF ((A = B) AND (C < D)) THEN
MyNumber = 10
ELSE
MyNumber = 20
END IF
[/tt]

And in a "C-style" languages it looks like this:
[tt]if ((A == B) && (C < D) {
MyNumber = 10;
}
else {
MyNumber = 20;
}
[/tt]

Suppose your values are:
A = 1
B = 2
C = 3
D = 4


OK. Now your C-Style language will see [tt]A == B[/tt], test for the equivilancy of A and B, and decide that it is false. Since it is false, the entire expression must be false because no matter the result of C < D, the overall expression will be false because both
False and True = False
and
False and False = False

Got it?

OK now VB doesnt work that way.

VB uses the same equal character for an assignment as for an equivilancy test. So where your C-style uses "==" for equivilancy and "=" to assign a value, the VB uses the same for both purposes.

How does VB do it? By context. It interprets the entire line and figures out whether you want an assignment or equivilancy by what makes sense in context of the line.

This is usually a good thing because in English we use the word "equals" for both concepts of equivilancy and assignment... but it is a bad thing in a situation like this because it evaluates the entire line, even though you would think it SHOULD know better after the first half of the conditional is False.

That is why you need to use the embedded conditional statement like DNG showed.








 
Thank you, Sheco, for your clarification.
I thought VB could stop evaluation when it sees countRS.EOF
true.
Sincerely
Betty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top