Solved

If statement syntx

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

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

630 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