Solved

If statement syntx

Posted on 2006-07-18
3
286 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 63

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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