Solved

How to stop an if statement

Posted on 2007-03-29
6
199 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 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Independent Software Vendors: 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!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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 …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 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