473,763 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ElseIF or Case Statement?

Is there anyway I could clean-up all these ElseIF statements with a
select/case or is this the best that can be done ("I can't think of a better
way")?

Private Sub Update_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles Update.Click

If Page.IsValid Then

If Me.NewEmailAddr ess.Text = "" And Me.NewPassword. Text = "" Then

Me.CustomDataCh eck.IsValid = False

Me.CustomDataCh eck2.IsValid = False

ElseIf Me.NewEmailChec k.Text <> "" And Me.NewEmailAddr ess.Text = "" Then

Me.CompEmailChe ck.IsValid = False

ElseIf Me.NewPasswordC heck.Text <> "" And Me.NewPassword. Text = "" Then

Me.CompPassword Check.IsValid = False

ElseIf Me.NewEmailAddr ess.Text = context.Session ("Email") Then

Me.CustomEmailC heck.IsValid = False

Me.CustomEmailC heck.ErrorMessa ge = "Email update failed - Email Address " &
_

Me.NewEmailAddr ess.Text & " is already registered to your account."

Me.CustomEmailC heck.Text = "Opps Already In Use By You!"

ElseIf Me.NewEmailAddr ess.Text <> "" And Me.NewPassword. Text <> "" Then

UpdateAccount(M e.NewEmailAddre ss.Text, Me.NewPassword. Text)

ElseIf Me.NewEmailAddr ess.Text <> "" Then

UpdateAccount(M e.NewEmailAddre ss.Text, Me.CurrentPassw ord.Text)

ElseIf Me.NewPassword. Text <> "" Then

UpdateAccount(c ontext.Session( "Email"), Me.NewPassword. Text)

End If

End If

End Sub
Nov 19 '05 #1
5 2036
Leon,

It looks like a load of page validation which could be done client side with
some validators... This would only allow a postback (and hence Update_Click)
to fire once the Validators have been passed, eliminating the need for the
checking to be done in this method.

Thanks.
Dan.

"Leon" <vn*****@msn.co m> wrote in message
news:OU******** ******@TK2MSFTN GP09.phx.gbl...
Is there anyway I could clean-up all these ElseIF statements with a
select/case or is this the best that can be done ("I can't think of a
better
way")?

Private Sub Update_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles Update.Click

If Page.IsValid Then

If Me.NewEmailAddr ess.Text = "" And Me.NewPassword. Text = "" Then

Me.CustomDataCh eck.IsValid = False

Me.CustomDataCh eck2.IsValid = False

ElseIf Me.NewEmailChec k.Text <> "" And Me.NewEmailAddr ess.Text = "" Then

Me.CompEmailChe ck.IsValid = False

ElseIf Me.NewPasswordC heck.Text <> "" And Me.NewPassword. Text = "" Then

Me.CompPassword Check.IsValid = False

ElseIf Me.NewEmailAddr ess.Text = context.Session ("Email") Then

Me.CustomEmailC heck.IsValid = False

Me.CustomEmailC heck.ErrorMessa ge = "Email update failed - Email Address "
&
_

Me.NewEmailAddr ess.Text & " is already registered to your account."

Me.CustomEmailC heck.Text = "Opps Already In Use By You!"

ElseIf Me.NewEmailAddr ess.Text <> "" And Me.NewPassword. Text <> "" Then

UpdateAccount(M e.NewEmailAddre ss.Text, Me.NewPassword. Text)

ElseIf Me.NewEmailAddr ess.Text <> "" Then

UpdateAccount(M e.NewEmailAddre ss.Text, Me.CurrentPassw ord.Text)

ElseIf Me.NewPassword. Text <> "" Then

UpdateAccount(c ontext.Session( "Email"), Me.NewPassword. Text)

End If

End If

End Sub

Nov 19 '05 #2
How can I do these validation client side?

"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:e6******** **********@TK2M SFTNGP12.phx.gb l...
Leon,

It looks like a load of page validation which could be done client side
with some validators... This would only allow a postback (and hence
Update_Click) to fire once the Validators have been passed, eliminating
the need for the checking to be done in this method.

Thanks.
Dan.

"Leon" <vn*****@msn.co m> wrote in message
news:OU******** ******@TK2MSFTN GP09.phx.gbl...
Is there anyway I could clean-up all these ElseIF statements with a
select/case or is this the best that can be done ("I can't think of a
better
way")?

Private Sub Update_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles Update.Click

If Page.IsValid Then

If Me.NewEmailAddr ess.Text = "" And Me.NewPassword. Text = "" Then

Me.CustomDataCh eck.IsValid = False

Me.CustomDataCh eck2.IsValid = False

ElseIf Me.NewEmailChec k.Text <> "" And Me.NewEmailAddr ess.Text = "" Then

Me.CompEmailChe ck.IsValid = False

ElseIf Me.NewPasswordC heck.Text <> "" And Me.NewPassword. Text = "" Then

Me.CompPassword Check.IsValid = False

ElseIf Me.NewEmailAddr ess.Text = context.Session ("Email") Then

Me.CustomEmailC heck.IsValid = False

Me.CustomEmailC heck.ErrorMessa ge = "Email update failed - Email Address "
&
_

Me.NewEmailAddr ess.Text & " is already registered to your account."

Me.CustomEmailC heck.Text = "Opps Already In Use By You!"

ElseIf Me.NewEmailAddr ess.Text <> "" And Me.NewPassword. Text <> "" Then

UpdateAccount(M e.NewEmailAddre ss.Text, Me.NewPassword. Text)

ElseIf Me.NewEmailAddr ess.Text <> "" Then

UpdateAccount(M e.NewEmailAddre ss.Text, Me.CurrentPassw ord.Text)

ElseIf Me.NewPassword. Text <> "" Then

UpdateAccount(c ontext.Session( "Email"), Me.NewPassword. Text)

End If

End If

End Sub


Nov 19 '05 #3
A Select Case statement only works when you are comparing against a single
value. If the logic in your code represents the way you want it to run, I
believe you've come up with about the best you can do here.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Leon" <vn*****@msn.co m> wrote in message
news:OU******** ******@TK2MSFTN GP09.phx.gbl...
Is there anyway I could clean-up all these ElseIF statements with a
select/case or is this the best that can be done ("I can't think of a better way")?

Private Sub Update_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles Update.Click

If Page.IsValid Then

If Me.NewEmailAddr ess.Text = "" And Me.NewPassword. Text = "" Then

Me.CustomDataCh eck.IsValid = False

Me.CustomDataCh eck2.IsValid = False

ElseIf Me.NewEmailChec k.Text <> "" And Me.NewEmailAddr ess.Text = "" Then

Me.CompEmailChe ck.IsValid = False

ElseIf Me.NewPasswordC heck.Text <> "" And Me.NewPassword. Text = "" Then

Me.CompPassword Check.IsValid = False

ElseIf Me.NewEmailAddr ess.Text = context.Session ("Email") Then

Me.CustomEmailC heck.IsValid = False

Me.CustomEmailC heck.ErrorMessa ge = "Email update failed - Email Address " & _

Me.NewEmailAddr ess.Text & " is already registered to your account."

Me.CustomEmailC heck.Text = "Opps Already In Use By You!"

ElseIf Me.NewEmailAddr ess.Text <> "" And Me.NewPassword. Text <> "" Then

UpdateAccount(M e.NewEmailAddre ss.Text, Me.NewPassword. Text)

ElseIf Me.NewEmailAddr ess.Text <> "" Then

UpdateAccount(M e.NewEmailAddre ss.Text, Me.CurrentPassw ord.Text)

ElseIf Me.NewPassword. Text <> "" Then

UpdateAccount(c ontext.Session( "Email"), Me.NewPassword. Text)

End If

End If

End Sub

Nov 19 '05 #4
Thanks!
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
A Select Case statement only works when you are comparing against a single
value. If the logic in your code represents the way you want it to run, I
believe you've come up with about the best you can do here.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Leon" <vn*****@msn.co m> wrote in message
news:OU******** ******@TK2MSFTN GP09.phx.gbl...
Is there anyway I could clean-up all these ElseIF statements with a
select/case or is this the best that can be done ("I can't think of a

better
way")?

Private Sub Update_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles Update.Click

If Page.IsValid Then

If Me.NewEmailAddr ess.Text = "" And Me.NewPassword. Text = "" Then

Me.CustomDataCh eck.IsValid = False

Me.CustomDataCh eck2.IsValid = False

ElseIf Me.NewEmailChec k.Text <> "" And Me.NewEmailAddr ess.Text = "" Then

Me.CompEmailChe ck.IsValid = False

ElseIf Me.NewPasswordC heck.Text <> "" And Me.NewPassword. Text = "" Then

Me.CompPassword Check.IsValid = False

ElseIf Me.NewEmailAddr ess.Text = context.Session ("Email") Then

Me.CustomEmailC heck.IsValid = False

Me.CustomEmailC heck.ErrorMessa ge = "Email update failed - Email Address "

&
_

Me.NewEmailAddr ess.Text & " is already registered to your account."

Me.CustomEmailC heck.Text = "Opps Already In Use By You!"

ElseIf Me.NewEmailAddr ess.Text <> "" And Me.NewPassword. Text <> "" Then

UpdateAccount(M e.NewEmailAddre ss.Text, Me.NewPassword. Text)

ElseIf Me.NewEmailAddr ess.Text <> "" Then

UpdateAccount(M e.NewEmailAddre ss.Text, Me.CurrentPassw ord.Text)

ElseIf Me.NewPassword. Text <> "" Then

UpdateAccount(c ontext.Session( "Email"), Me.NewPassword. Text)

End If

End If

End Sub


Nov 19 '05 #5
Do a search on validators and asp.net...

I found this:
http://msdn.microsoft.com/library/de..._userinput.asp
[beware of line wraps]

let me know if you get stuck
"Leon" <vn*****@msn.co m> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
How can I do these validation client side?

"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:e6******** **********@TK2M SFTNGP12.phx.gb l...
Leon,

It looks like a load of page validation which could be done client side
with some validators... This would only allow a postback (and hence
Update_Click) to fire once the Validators have been passed, eliminating
the need for the checking to be done in this method.

Thanks.
Dan.

"Leon" <vn*****@msn.co m> wrote in message
news:OU******** ******@TK2MSFTN GP09.phx.gbl...
Is there anyway I could clean-up all these ElseIF statements with a
select/case or is this the best that can be done ("I can't think of a
better
way")?

Private Sub Update_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles Update.Click

If Page.IsValid Then

If Me.NewEmailAddr ess.Text = "" And Me.NewPassword. Text = "" Then

Me.CustomDataCh eck.IsValid = False

Me.CustomDataCh eck2.IsValid = False

ElseIf Me.NewEmailChec k.Text <> "" And Me.NewEmailAddr ess.Text = "" Then

Me.CompEmailChe ck.IsValid = False

ElseIf Me.NewPasswordC heck.Text <> "" And Me.NewPassword. Text = "" Then

Me.CompPassword Check.IsValid = False

ElseIf Me.NewEmailAddr ess.Text = context.Session ("Email") Then

Me.CustomEmailC heck.IsValid = False

Me.CustomEmailC heck.ErrorMessa ge = "Email update failed - Email Address
" &
_

Me.NewEmailAddr ess.Text & " is already registered to your account."

Me.CustomEmailC heck.Text = "Opps Already In Use By You!"

ElseIf Me.NewEmailAddr ess.Text <> "" And Me.NewPassword. Text <> "" Then

UpdateAccount(M e.NewEmailAddre ss.Text, Me.NewPassword. Text)

ElseIf Me.NewEmailAddr ess.Text <> "" Then

UpdateAccount(M e.NewEmailAddre ss.Text, Me.CurrentPassw ord.Text)

ElseIf Me.NewPassword. Text <> "" Then

UpdateAccount(c ontext.Session( "Email"), Me.NewPassword. Text)

End If

End If

End Sub



Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
23032
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which field is completed.
7
9338
by: Lauren Quantrell | last post by:
Is there any speed/resource advantage/disadvantage in using Select Case x Case 1 Case 2 etc. many more cases... End Select VS.
6
3149
by: Ivan Sergio Borgonovo | last post by:
First thanks to Tom Lane who helped me promptly. Now let's come to the problem: create or replace function testa( ) returns char(32) as ' begin if 1=2 then if 1=2 then
3
2208
by: amrhi | last post by:
Hy guys , I try to make conditional statement by using if and elseif . the problem are if i use 2 conditional statement the script run well but if try add more conditinal statement it's not working only 2 conditional it select. thanks to help me my script //condtional// if ($ttl_dur > 10 and $bay!=$stand and $dpt_reg==0){ $fail=1; }elseif($ttl_dur > 15 and $bay==$stand and categori==0){ $fail=1; ...
1
2843
by: RobinAG | last post by:
I'm having a wierd difficulty with my If...ElseIf...Else...End If statement. I'm having the db put together a string to base a recordset off of, and depending on the ID number, the select statement changes. Basically it looks like this: If Me.ProjectID.Value <=1835 Then str = _Select statement 1 ElseIf 1836 <= Me.ProjectID.Value <= 5109 Then
2
1170
by: patsman77 | last post by:
Hello All, I have a slight problem/small question.... I am trying this code out, but am not getting correct results.... any help would be great. if (($pass-$pass) > ($pass+$pass)) { echo "$pass is Winner.\n"; } elseif (($pass-$pass) < ($pass+$pass)) { echo "$pass wins.\n"; } else {
17
2462
by: JRough | last post by:
I'm trying to get error proof code. I have this code which seems to work but now I look at it I think it should be elseif not else and I wonder why it works. It is in the block: if($_POST('assign']='Open in Excel')]...{ }elseif($_POST=='Open in Excel')]... ? shouldn't it be else instead of elseif? or should it be
3
2572
by: Tim Roberts | last post by:
JRough <jlrough@yahoo.comwrote: More than the syntax problems, you also have a logic problem here. How do you think that "if" statement is ever going to be hit, given the statement immediately before it? -- Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc.
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.