Solved

How to stop an if statement

Posted on 2007-03-29
6
191 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

22 Experts available now in Live!

Get 1:1 Help Now