Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

If statement syntx

Posted on 2006-07-18
3
Medium Priority
?
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 1200 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 800 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

722 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