שתף באמצעות


flags-what are they??

Question

Thursday, May 1, 2008 11:15 AM

 

Why do we use a flag in vb.net?

What exactly are they used for?

Thanks

 

 

All replies (3)

Thursday, May 1, 2008 1:02 PM ✅Answered

There are some good articles on the web if you do a Google search for "flags in vb.net".

Here's one of them:

http://www.codeguru.com/vb/sample_chapter/article.php/c12963/

 

good luck

 


Saturday, May 3, 2008 11:45 AM ✅Answered

 carlysarahg wrote:

 

Why do we use a flag in vb.net?

What exactly are they used for?

Thanks

 

 

Hi,

 

A flag is usually a TRUE or FALSE ( On or Off ) ( zero or one in Binary ).

 

They can be used to indicate the result of a previous test such as the test of an IF THEN statement

 or within a  SELECT-CASE-END SELECT block.

 

You could use a variable to indicate a condition or state of something that has more than two states such as a valve position, OPEN, CLOSED, HALF-WAY-OPEN and so on. Then a computer needs to use 3 or more different BINARY values like

  • 00
  • 01
  • 10

etcetera.

 

Try this bit of code with one button on a FORM.>>

 

Code Snippet

 

Public Class Form1

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

Dim myFlag As Boolean

Dim myNumber As Integer = 777

 

If myNumber = 777 Then

myFlag = True

MessageBox.Show("myNumber = 777")

Else

myFlag = False

MessageBox.Show("myNumber does NOT EQUAL 777")

End If

 

End Sub

End Class

 

 

 

At the end of the day in a computer all operations work as a result of a flag being TRUE or FALSE.

 

E.G. Run WINDOWS MEDIA PLAYER ( Yes | No )

If Yes, Play an MP3 file ( Yes | No )

 

If Yes to Play a FILE AND If No to Play an MP3 file

 

Play a WMA file instead ( Yes | No )

 

....etcetera.

 

It is all based on whether you click on OK | Cancel or whatever you click on.

 

If myNumber = 777 is evaluated as TRUE or FALSE ( 1 or 0 in binary ) in the above code.

 

 

 

 

Regards,

 

John

 


Tuesday, November 20, 2012 4:33 AM

Help me :)
tag "<>" effective "'(note)" somewhere :)???
Or does it make sense is IsNot Comparison of Operators???