passing conditional parameters

Drstein99

Well-known member
Joined
Sep 26, 2003
Messages
283
Location
Audubon, Nj
I am trying to pass a parameter to a sub, as a condition (example):

doTest(dialogresult.ok)

sub doTest(byval pdresult as dialogresult)

bla

end sub
-------
I WANT to pass an "or", "and" condition to the sub, (example):

doTest (dialogresult.ok OR dialogresult.cancel)

--


How do i transfer the conditions to the sub? It seems only to take the "dialogresult.ok" as a paramter
 
Hi,

I tried what you are trying to do in a sample code - and it seems to work just fine.
Code:
    Private Sub TestDialogResultParameters(ByVal lDialogResult As Long)
        MessageBox.Show(lDialogResult.ToString())
    End Sub

If you are trying to AND any paramter with dialogresult.ok, then you will always get dialogresult.ok - as the value of this parameter is 0.

E.g. TestDialogResultParameters(DialogResult.OK Or DialogResult.Cancel) returns 3.
however, TestDialogResultParameters(DialogResult.OK And DialogResult.Cancel) returns 0.

Chaitanya
 
Youll have to verify that inside your function. You can do it that way... but itll be a bit to bit comparison. And if you select 3 (with OR)... then itll be Cancel else... with AND itll be OK. What you can do is that :
Code:
DialogResult res = form1.ShowDialog()
If( res = DialogResult.OK ) Then
Do something
doTest( res )
End If
 
The AND and OR operators in this case were performing a bit-wise operation. In C/C++ this is done with & for AND and | for OR. Becuase DialogResult.OK etc.. are Enumerations, they have an associated integer values and their bits can be manipulated in a meaninful way.

It is quite common to use bitwise operations in C/C++ where speed/space is a major consideration and in low level API calls but in VB I dont really see a need for it unless the problem domain explicitly dictates it. Other bitwise operations Xor, not, left shift and, right shift. Bit wise operations are really cool and extremely powerful but very low level. Really no point in .Net.

Id use what Arch4ngel put up for you.
 
Back
Top