Solved

How to stop an if statement

Posted on 2007-03-29
6
194 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
  • 4
  • 2
6 Comments
 
LVL 142

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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

11 Experts available now in Live!

Get 1:1 Help Now