Solved

If statement syntx

Posted on 2006-07-18
3
281 Views
Last Modified: 2010-04-23
Can    ANDALSO be used with   OR


example:      If grpPhysics.Visible = True AndAlso txtPTrainID.Text <> ""    OR   grpTraining.Visible = True AndAlso txtTrain_ID.Text <> "" Then
                              SaveTraining()
                  ELSE IF grpPhysics.Visible = True AndAlso txtPTrainID.Text = ""    OR   grpTraining.Visible = True AndAlso txtTrain_ID.Text = "" Then
                                InsertTraining()
                 End If

Thanks in advance
0
Comment
Question by:TimSweet220
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 300 total points
ID: 17133944
Hi TimSweet220;

Yes this syntax should work fine.

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

        If grpPhysics.Visible = True AndAlso txtPTrainID.Text <> "" Or _
            grpTraining.Visible = True AndAlso txtTrain_ID.Text <> "" Then

           SaveTraining()

        ElseIf grpPhysics.Visible = True AndAlso txtPTrainID.Text = "" Or _
            grpTraining.Visible = True AndAlso txtTrain_ID.Text = "" Then

           InsertTraining()

        End If

    End Sub


You can also remove the = True as below code shows because Visible is a Boolean.

        If grpPhysics.Visible AndAlso txtPTrainID.Text <> "" Or _
            grpTraining.Visible AndAlso txtTrain_ID.Text <> "" Then

           SaveTraining()

        ElseIf grpPhysics.Visible AndAlso txtPTrainID.Text = "" Or _
            grpTraining.Visible AndAlso txtTrain_ID.Text = "" Then

           InsertTraining()

        End If

Fernando
0
 
LVL 7

Assisted Solution

by:Joe_Griffith
Joe_Griffith earned 200 total points
ID: 17133964
Works fine for me... here's the code I tested with. You can manipulate the trues/falses to see what happens:

    If False AndAlso True Or True AndAlso True Then
      MessageBox.Show("Yes")
    Else
      MessageBox.Show("No")
    End If

However, I don't really see any reason to use AndAlso in this instance, why not just use And? You might also make use of some parenthesis to make it easier to read.
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17134233
Just an additional note... if you're going to use AndAlso, why not use OrElse?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now