?
Solved

How to stop an if statement

Posted on 2007-03-29
6
Medium Priority
?
201 Views
Last Modified: 2010-04-23
Hi experts,

i have these two if statements. if a the updateUser.text = "Add User" And LicenseDB.AddUser(userProfile) then step
one should run
=============================================one==========
 If btnUpdateUser.Text = "Add User" And LicenseDB.AddUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been added."
        Else
            lblmsg.Text = "That user details  already exists."
        End If


else two should run
==========================two============================
        If btnUpdateUser.Text = "Update User" And LicenseDB.UpdateUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been updated."
        Else
            lblmsg.Text = "That user details  already exists."

        End If
        Me.SetControlState(ControlState.NoSelection)

        LoadData()

the proble is that when i add a user it displays
   lblmsg.Text = "That user details  already exists."  ============from step two.

How can I stop it from running into step two

==========full code=========
Private Sub btnUpdateUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateUser.Click
        'Initialing the controls
        Dim userProfile As New UserProfile
        userProfile.userProfileID = txtUserID.Text
        userProfile.userLoginID = txtUserID.Text
        userProfile.state = ddlEmp.SelectedItem.Value
        userProfile.firstName = txtFirstName.Text
        userProfile.lastName = txtLastName.Text
        userProfile.address1 = txtAddress1.Text
        userProfile.address2 = txtAddress2.Text
        userProfile.city = txtCity.Text
        userProfile.state = ddlState.SelectedValue
        userProfile.email = txtEmail.Text
        userProfile.phone = txtphone.Text
        userProfile.zip = txtZip.Text
        userProfile.employeeflag = ddlEmp.SelectedValue
        userProfile.username = txtUserName.Text
        userProfile.password = txtCreatePass.Text
        'update users
        If btnUpdateUser.Text = "Add User" And LicenseDB.AddUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been added."
        Else
            lblmsg.Text = "That user details  already exists."
        End If


        If btnUpdateUser.Text = "Update User" And LicenseDB.UpdateUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been updated."
        Else
            lblmsg.Text = "That user details  already exists."

        End If
        Me.SetControlState(ControlState.NoSelection)

        LoadData()
    End Sub
#End Region


thanks
0
Comment
Question by:SirReadAlot
[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
  • 4
  • 2
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18815586
       If btnUpdateUser.Text = "Add User" then
          if LicenseDB.AddUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been added."
          Else
             lblmsg.Text = "That user details  already exists."  
          end if
        End If


        If btnUpdateUser.Text = "Update User"  then
          if LicenseDB.UpdateUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been updated."
          Else
            lblmsg.Text = "That user details  already exists."
          end if
        End If
0
 

Author Comment

by:SirReadAlot
ID: 18815597
i will try this
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 18815602
I would rewrite like this:

select case btnUpdateUser.Text
  case "Add User"
     if LicenseDB.AddUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been added."
          Else
             lblmsg.Text = "That user details  already exists."  
          end if
  case "Update User"
      if LicenseDB.UpdateUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been updated."
          Else
            lblmsg.Text = "That user details  already exists."
          end if
End Select
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:SirReadAlot
ID: 18815614
will try this as well
0
 

Author Comment

by:SirReadAlot
ID: 18815969
THANKS
0
 

Author Comment

by:SirReadAlot
ID: 18815985
I USED THIS

#Region " btnUpdateUser Subroutine "
    Private Sub btnUpdateUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateUser.Click
        'Initialing the controls
        Dim userProfile As New UserProfile
        userProfile.userProfileID = txtUserID.Text
        userProfile.userLoginID = txtUserID.Text
        userProfile.state = ddlEmp.SelectedItem.Value
        userProfile.firstName = txtFirstName.Text
        userProfile.lastName = txtLastName.Text
        userProfile.address1 = txtAddress1.Text
        userProfile.address2 = txtAddress2.Text
        userProfile.city = txtCity.Text
        userProfile.state = ddlState.SelectedValue
        userProfile.email = txtEmail.Text
        userProfile.phone = txtphone.Text
        userProfile.zip = txtZip.Text
        userProfile.employeeflag = ddlEmp.SelectedValue
        userProfile.username = txtUserName.Text
        userProfile.password = txtCreatePass.Text
        'update users
        Select Case btnUpdateUser.Text
            Case "Add User"
                If LicenseDB.AddUser(userProfile) Then
                    Me.ClearFields()
                    lblmsg.Text = "The user has been added."
                Else
                    lblmsg.Text = "That username already exists."
                End If
            Case "Update User"
                If LicenseDB.UpdateUser(userProfile) Then
                    Me.ClearFields()
                    lblmsg.Text = "The user has been updated."
                Else
                    lblmsg.Text = "That username already exists."
                End If
        End Select
        Me.SetControlState(ControlState.NoSelection)

        LoadData()
    End Sub
#End Region
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…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 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