MuxClass.DSIValues.count
(1)
DSIValues.Count
(1)
Muxclass.COM2Active
(1)
Muxclass.COM1Active
(1)
Debug.Print
(1)
Computer
(1)
Print
(1)
OP
(1)

If statement not catching on conditions

Asked By cmdolcet69
30-Oct-08 06:45 AM
I have the below if statement, that should catch if any of the
conditions are met.....however for some reasons if my
boolDSIFlushGapReading = true and MuxClass.DSIValues.count =1 and my
muxclass.COM1Active =1 it will not exit the program??? Why is that can
anyone help me

Urgent!!!!!!



If boolDSIFlushGapReading = False And muxClass.DSIValues.Count < 2 And
Not muxClass.COM1Active = 1 Then
Exit Sub
End If

If statement not catching on conditions

Asked By Lloyd Sheen
29-Oct-08 01:27 PM
Any = Or
All = And

your statement wants all the conditions to be met before the exit will
occur.

LS

Did you want an OR connector instead of AND?

Asked By Bet
29-Oct-08 01:34 PM
Did you want an OR connector instead of AND?
You said: should catch if ANY of the conditions are met

Would
If (not boolDSIFlushGapReading) OR (muxClass.DSIValues.Count < 2) OR
(muxClass.COM1Active <> 1) Then

do it?

If statement not catching on conditions

Asked By Jack Jackson
29-Oct-08 01:39 PM
On Wed, 29 Oct 2008 10:20:57 -0700 (PDT), cmdolcet69


Your statement says to execut the Exit Sub only if all three
conditions are met.  In your example the first one is not met and the
other two are.

Apparently you want Or instead of And.  An Or test is true if either
item is true, and And test is true of both items are true.

Also, you should use AndAlso and OrElse instead of And and Or for
tests like this.
If statement not catching on conditions
Asked By cmdolcet69
30-Oct-08 06:45 AM
Ok a step further lets say:
boolDSIFlushGapReading =3D true and MuxClass.DSIValues.count =3D1 and my
muxclass.COM1Active =3D2 it will not exit the program???

How can I fix that.......
If statement not catching on conditions
Asked By cmdolcet69
30-Oct-08 06:45 AM
y
n
d

No what happends is that DSIValues.Count can =3D1 but then the
muxclass.COM1Active =3D 0
The only wat it doesn;t exist is that DSIValues.Count can =3D2 but then
the muxclass.COM1Active =3D 1 or

DSIValues.Count can =3D1 but then the muxclass.COM2Active =3D 2
If statement not catching on conditions
Asked By Armin Zingler
29-Oct-08 03:51 PM
First I thought it could be a matter of operator precedence
(http://msdn.microsoft.com/en-us/library/fw84t893.aspx), but it's correct.

You expect the program to exit. Have you tested if the "Exit sub" statement
is reached (Debug.Print)? Or maybe it is reached but it doesn't cause the
expected behavior? Exit Sub exits the sub, not the program.


Armin
If statement not catching on conditions
Asked By cmdolcet69
30-Oct-08 06:45 AM
y
.
nt

Armin it never exit the Sub and that all I want it to do is exit the
sub
If statement not catching on conditions
Asked By Armin Zingler
29-Oct-08 04:45 PM
It's possible that debugging has an influence on the result, in particular
as you are handling COM ports here (I guess) where the state can change
while debugging. For example, if you set a breakpoint and examine the
values, they can be different from those if you had not interrupted the
execution. Therefore, try this:

debug.write(boolDSIFlushGapReading & " ")
debug.write(muxClass.DSIValues.Count & " ")
debug.writeline(muxClass.COM1Active)

If boolDSIFlushGapReading = False And muxClass.DSIValues.Count < 2 _
And Not muxClass.COM1Active = 1 Then
debug.writeline("exit sub")
Exit Sub
End If


I can not debug it here, so maybe exit sub is reached but the function is
called again and you think it is never left? I don't know. Is "exit sub"
ever shown in the debug/output window? Do you ever get the value combination
that you think should make the sub exit?



Armin
If statement not catching on conditions
Asked By Jack Jackson
29-Oct-08 06:37 PM
On Wed, 29 Oct 2008 11:38:16 -0700 (PDT), cmdolcet69


I don't understand what behavior you want.

In the example above, it would not exit because only one of the
conditions is true, and when you use And all must be true.

If you use Or, then if any condition is true it will exit, so in your
example above if you changed the Ands to Ors (or preferrably OrElse)
it would exit since muxClass.DSIValues.Count is < 2.
Why are you not reading what everybody writes, but does not want to give you
Asked By Cor Ligthert[MVP]
30-Oct-08 01:12 AM
Why are you not reading what everybody writes, but does not want to give you
the fish but tries to teach you how to catch the fish.

Here is the fish

\\\
If boolDSIFlushGapReading = False OrElse muxClass.DSIValues.Count < 2 OrElse
muxClass.COM1Active <> 1 Then
Exit Sub
End If
///

This means that if any of this tests is true, then it will Exit Sub

Do they all have to be true then it is

\\\
If boolDSIFlushGapReading = False AndAlso muxClass.DSIValues.Count < 2
AndAlso
muxClass.COM1Active <> 1 Then
Exit Sub
End If
///


Cor
If statement not catching on conditions
Asked By Andrew Morton
30-Oct-08 06:43 AM
This is why everyone is saying to use "or" rather than "and": you're not
translating English into computer the right way round.

English: let's have all the apples and bananas->let's have all the apples
and let's have all the bananas

Computer: (all the items where x is an apple) + (all the items where x is a
banana)

Logically, the + translates to "or", not "and".


If in doubt, write it as three separate conditions to make it obvious:

if not(boolDSIFlushGapReading) then
exit sub
end if

if MuxClass.DSIValues.count < 2 then
exit sub
end if

if muxClass.COM1Active <> 1 then
exit sub
end if

Remember the syntax is "if <boolean> then...", so you shouldn't test boolean
values: you should treat it directly as a boolean, which is why I changed
your "If boolDSIFlushGapReading = False" to "if
not(boolDSIFlushGapReading)".

Also, I think that "if muxClass.COM1Active <> 1" is easier to read than "if
Not muxClass.COM1Active = 1".

HTH

Andrew
"easier to read" is open to debate (although I don't disagree), but if Not
Asked By James Hahn
30-Oct-08 06:35 PM
if Not muxClass.COM1Active = 1
relies on precedence, whereas
if muxClass.COM1Active <> 1
does not.  Barely significant in this example, but it can save a lot of
headscratching in more complex cases.
If statement not catching on conditions
Asked By Bet
03-Nov-08 11:41 AM
I thought my threads were weird.

James, do you mean:
Not muxClass.COM1Active = 1
is interpreted as:
(Not muxClass.COM1Active) = 1
which would never be true, because true equates to -1, false to 0, and is
different from:
Not (muxClass.COM1Active = 1)

parens can be your friends...

maybe the whole problem is he should be testing for -1 instead of 1,
I don't know.
No. The two expressions are equivalent.
Asked By James Hahn
03-Nov-08 03:42 PM
No. The two expressions are equivalent. I was simply commenting that the
form
Not muxClass.COM1Active = 1
relies on
muxClass.COM1Active = 1
having a higher precedence than the Not. My preference is for having an
expression that doesn't rely on the default precedence rules, therefore I
would use either
Not (muxClass.COM1Active = 1)
which makes it explicit or (much simpler)
if muxClass.COM1Active <> 1

So not only does it _look_ more sensible but there's some programming sense
behind the choice - just a tiny bit in this case, but possibly relevant in
more complex cases. The original code was complicated enough without the
possibility of misunderstanding the implied precedence rules.
so you're saying you don't like the left-to-right thing being overridden by
Asked By Bet
03-Nov-08 05:30 PM
so you're saying you don't like the left-to-right thing being overridden by
the precedence rules, because who remembers the precedence rules anyways (I
don't, obviously.  I use parens.)

I don't know why this guy's confused, then.
I don't think anyone knows why OP is confused because he never comes back to
Asked By James Hahn
03-Nov-08 06:05 PM
I do not think anyone knows why OP is confused because he never comes back to
indicate whether or not he worked it out.  He just asks another question
from somewhere else in the project.
Post Question To EggHeadCafe
met. . . . .however for some reasons if my boolDSIFlushGapReading = true and MuxClass.DSIValues.count = 1 and my muxclass.COM1Active = 1 it will not exit the program??? Why is that can anyone help me Urgent!!!!!! If boolDSIFlushGapReading = False And muxClass.DSIValues.Count < 2 And Not muxClass.COM1Active = 1 Then Exit Sub End If Any = Or All of the conditions are met Would If (not boolDSIFlushGapReading) OR (muxClass.DSIValues.Count < 2) OR (muxClass.COM1Active <> 1) Then do it? On
Framework Applying ++ and + = to properties If I had public int Count { get; set; } int x, y; . . . Count = 0; Count++; x = Count; Count + = 1; y = Count; what would be the values of x and y? Are both operations treated as though they were Count = Count + 1; or are the semantics different from that? Hello, And the property is implemented (for example if you implament the count property as returning a rndom number you ahve no way Applying, ++, and, + = , to, properties description: If I had public int Count { get; set; } int x, y; . . . Count = 0; Count++; x = Count
the following classes: namespace MyApp.Models { public class Tie { public Count Count { get; set; } public Tie() { this.Count = new Count(); } } } namespace MyApp.Models { public class Count { public int File { get; set; } public int Professor { get; set is: Tie.Tie.Tie . . . Why can't I access Tie.Count ? The Tie method inside the Tie class is only a constructor to initialize the Count property. Am I doing something wrong? I have been using class then try to access; Tie tie = new Tie(); tie.Count Count is an instance property - so you should be able to do: Tie someTie = 3D new Tie(); Count count = 3D someTie.Count; But you cannot do: Count count
this code for draw an x, y chart - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- for (int count = 1; count < = Width; count = count + 1) { int punto_shiftato_nella_serie = count + (int.Parse(txtOffsetX.Text) * 25); int punto_shiftato_nella_serie_piu_uno = punto_shiftato_nella_serie + 1; / / Disegno linea grafico sensore 2 if (chkSegnale2.Checked) { float X1 = count * valore_zoom_in_X; float Y1 = offset_in_Y + Serie2[punto_shiftato_nella_serie] * valore_zoom_in_Y; float X2 = (count + 1) * valore_zoom_in_X; float Y2 = offset_in_Y + Serie2[punto_shiftato_nella_serie_piu_uno] * valore_zoom_in_Y; formGraphics.DrawLine chkSegnale2.Checked) { int offsetX = Int32.Parse(txtOffsetX.Text); for (int count = 1; count < = Width; count++) { int punto_shiftato_nella_serie = count + offsetX * 25; int punto_shiftato_nella_serie_piu_uno = punto_shiftato_nella_serie + 1; float
NET Framework List newList = new List (MyList.Count + MyOtherList.count);newList. , newList, = , new, List<T> (MyList.Count, +, MyOtherList.count);newList." / > List<T> newList = new List<T> (MyList.Count + MyOtherList.count); newList.AddRange(MyList); newList.AddRange(MyOtherList); All great stuff thanks goal is here. Pete description: ListT newList = new ListT(MyList.Count + MyOtherList.count); newList.AddRange(MyList); newList.AddRange(MyOtherList);
AppString = "deviceappid"; byte[] AppData = new byte[AppString.Length]; for (int count = 0; count < AppString.Length; count++) AppData[count] = (byte)AppString[count]; int appDataSize = AppData.Length; byte[] DeviceOutput = new byte[20]; uint
I am defining a class as follows: stat = new Stat { Count = Roles.GetUsersInRole(RoleType.Administrator.ToString ()).Count(), Share = Count / UserCount * 100, UserCount = Membership.GetAllUsers().Count }; Is there a way to make: Share Count / UserCount * 100, To work? I mean, at the moment, Count and UserCount are not being recognized. I understand why . . . I repeating the code like: Share = Roles.GetUsersInRole(RoleType.Administrator.ToString()).Count () / Membership.GetAllUsers().Count * 100 Thanks, Miguel Sure. Write it *after* your object initializer: stat = new Stat { . . . }; stat.Share = stat.Count / stat.UserCount * 100; Note that underneath, this is what the down neatly. Also, if "Share" is always completely defined by Count and UserCount, consider making it a property without storage instead
from t in database.Tags select new TagPaper { Tag = t, Count = t.PostsTags.Count } into tp where tp.Count ! = 0 orderby tp.Tag.Name, tp.Count descending select tp).Take(20).ToList(); I don't think the 20 records that have an higher value of tp.Count. Then I need to order those 20 records by their discuss this? First, the early orderby should be reversed: tp.Count, tp.Tag.Name Also, at a minimum, you need to Marc new TagPaper { g = 3D t, unt = 3D t.PostsTags.Count tp tp.Count ! = 3D 0 y tp.Tag.Name, tp.Count tp).Take(20).ToList(); You need to order twice, so t in database.Tags select new TagPaper { Tag = 3D t, Count = 3D t.PostsTags.Count } into tp where tp.Count ! = 3D