Solved

If statement syntx

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Word Template Mail merge with vb.net 4 59
Loop through Multiple Processes Async 2 28
Help with Query not working in client's PC 1 35
Vb.net dynamic formulas in runtime 11 62
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

12 Experts available now in Live!

Get 1:1 Help Now