|
-
Apr 30th, 2008, 06:21 AM
#1
Thread Starter
Fanatic Member
[2005] Select CASE [RESOLVED]
Code:
If Ctype(control, TextBox).Id.StartsWith("txtTest1") Then
'do something
ElseIf Ctype(control, TextBox).Id.StartsWith("txtTest2") Then
'do something
ElseIf Ctype(control, TextBox).Id.StartsWith("txtTest3") Then
'do something
ElseIf Ctype(control, TextBox).Id.StartsWith("txtTest4") Then
'do something
'{more if statements}
Else If
Now i want to recode this with using SELECT CASE.
How do i use select case when i want that each case finds if certain control's id startswith given value?
Thanks
Last edited by selanec; Apr 30th, 2008 at 06:08 PM.
-
Apr 30th, 2008, 06:52 AM
#2
Re: [2005] Select CASE
vb.net Code:
Dim condition As String = CType(Control, TextBox).Id Select Case condition Case condition.StartsWith("txtTest1") Case condition.StartsWith("txtTest2") Case condition.StartsWith("txtTest3") Case condition.StartsWith("txtTest4") End Select
-
Apr 30th, 2008, 07:22 AM
#3
Thread Starter
Fanatic Member
Re: [2005] Select CASE
This is not working, Sorry
-
Apr 30th, 2008, 07:25 AM
#4
Re: [2005] Select CASE
What do you mean it doesn't work? There's no reason it shouldn't.
-tg
-
Apr 30th, 2008, 07:31 AM
#5
Junior Member
Re: [2005] Select CASE
Select Case can only be used here, if the total number of characters are equal for all the cases.
Example:
HTML Code:
Dim condition As String = CType(Control, TextBox).Id
Select Case Microsoft.VisualBasic.Left(condition, 8).ToUpper()
Case "TXTTEST1"
Case "TXTTEST2"
...
End Select
-
Apr 30th, 2008, 07:31 AM
#6
Re: [2005] Select CASE
vb.net Code:
Private Sub Button2_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button2.Click DoStuff(txtTest2) End Sub Private Sub DoStuff(ByVal control As Control) Dim condition As String = CType(control, TextBox).Name Select Case condition Case "txtTest1" MessageBox.Show("txtTest1") Case "txtTest2" MessageBox.Show("txtTest2") Case "txtTest3" MessageBox.Show("txtTest2") Case "txtTest4" MessageBox.Show("txtTest4") End Select End Sub
-
Apr 30th, 2008, 07:43 AM
#7
Re: [2005] Select CASE
 Originally Posted by sallushan
Select Case can only be used here, if the total number of characters are equal for all the cases.
Example:
HTML Code:
Dim condition As String = CType(Control, TextBox).Id
Select Case Microsoft.VisualBasic.Left(condition, 8).ToUpper()
Case "TXTTEST1"
Case "TXTTEST2"
...
End Select
regarding the statement... that's a bunch of hooey. Regarding the code, because of the design of the code, the statement becomes true.... but there's no need to grab only the left 8 characters. How would you test for "txtTest10".... or "txtTest12".... or "txtTest21" ???
-tg
-
Apr 30th, 2008, 07:46 AM
#8
Re: [2005] Select CASE
 Originally Posted by Deepak Sakpal
vb.net Code:
Dim condition As String = CType(Control, TextBox).Id
Select Case condition
Case condition.StartsWith("txtTest1")
Case condition.StartsWith("txtTest2")
Case condition.StartsWith("txtTest3")
Case condition.StartsWith("txtTest4")
End Select
Actually... this could work, with one modification:
Code:
Dim condition As String = CType(Control, TextBox).Id
Select Case True
Case condition.StartsWith("txtTest1")
Case condition.StartsWith("txtTest2")
Case condition.StartsWith("txtTest3")
Case condition.StartsWith("txtTest4")
End Select
It's a usage of the Select Case that I don't personally care for... but, it should work.
@sallushan - I see what you meant now, and why only the left 8 were used... point taken. I'm the one that's dense this morning.
-tg
-
Apr 30th, 2008, 06:08 PM
#9
Thread Starter
Fanatic Member
Re: [2005] Select CASE
Select Case True
that's the winner. Thanks a lot Mr. MVP
I realized that SrartsWith is actually boolean function so your last suggestion worked like a charm
Thanks a lot
-
May 1st, 2008, 11:46 PM
#10
Junior Member
Re: [2005] Select CASE [RESOLVED]
Good one. It really increased my experience with SELECT CASE.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|