Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want display result in third text box based on cases so i created 10 cases

when i debugged it displays only first case every time although output it 1,2,3,4,5,6,7,8,9,10;

VB
Dim Rtn As String
        Select Case Rtn
            Case 1
                Lnt = 1
                TextBox3.Text = " Sister"
            Case 2
                Lnt = 2
                TextBox3.Text = "Enemy"
            Case 3
                Lnt = 3
                TextBox3.Text = "Enemy "
            Case 4
                Lnt = 4
                TextBox3.Text = "Enemy"
            Case 5

                Lnt = 5
                TextBox3.Text = "Friend"
            Case 6
                Lnt = 6
                TextBox3.Text = "Marrage "
            Case 7
                Lnt = 7
                TextBox3.Text = "Enemy"
            Case 8
                Lnt = 8
                TextBox3.Text = "Affection"
            Case 9
                Lnt = 9
                TextBox3.Text = "Enemy"
            Case 10
                Lnt = 10
                TextBox3.Text = "Lover "
        End Select
    End Sub
End Class


The Rtn will get values like 1,2,3,4,5,6,7,8,9,10;
based on this value the specified case should come as out put but it always displaying first case "Sister" What to do No Please help me>Merry Christmas To All
Posted

This is one of the reasons I hate automatic casting and prefer to work in C# where this will throw up an error.

When you have the string "1,2,3" in rtn, and try to compare it against a set of integer values, VB automatically parse the string and converts it to an integer value. Since the string contains a "," which is not a part of an integer, it stops parsing at that, and uses the value it has parsed so far: 1
So it will always only execute the first option.

But there is a wider problem here: you are assuming the Select Case will work on each sub element in your string: it won't, unless you provide a loop yourself:
VB
Dim rtn As String = "1,2,3,4"
Dim parts As String() = rtn.Split(","C)
For Each s As String In parts
    Select Case s
        Case "1"
            Lnt = 1
            TextBox3.Text = " Sister"
            Exit Select
        ...
    End Select
Next
 
Share this answer
 
Comments
[no name] 24-Dec-12 4:49am    
Dear OriginalGriff,

Kindly see this i tried although it displaying "Sister
Actually Rtn gets different values like 1,2,3,4,5,6,7,8,9,10; In these numbers any one number may come .According to that nuber below cases should be come as output in thirdtextbox. But it always displaying "Sister"

Dim parts As String() = Rtn.Split(","c)
For Each s As String In parts
Select Case s
Case "1"
Lnt = 1
TextBox3.Text = " Sister"
Exit Select
Case "2"
Lnt = 2
TextBox3.Text = "Enemy"
Exit Select
Case "3"
Lnt = 3
TextBox3.Text = "Enemy "
Exit Select
Case "4"
Lnt = 4
TextBox3.Text = "Enemy"
Exit Select
Case "5"
Lnt = 5
TextBox3.Text = "Friend"
Exit Select
Case "6"
Lnt = 6
TextBox3.Text = "Marrage "
Exit Select
Case "7"
Lnt = 7
TextBox3.Text = "Enemy"
Exit Select
Case "8"
Lnt = 8
TextBox3.Text = "Affection"
Exit Select
Case "9"
Lnt = 9
TextBox3.Text = "Enemy"
Exit Select
Case "10"
Lnt = 10
TextBox3.Text = "Lover "
Exit Select
End Select
Next

End Sub
End Class


please give me solution according to mentioned above please sir
OriginalGriff 24-Dec-12 5:16am    
Try an experiment: Change
TextBox3.Text = "..."
To
TextBox3.Text += "..."
In every case.
What happens?
[no name] 24-Dec-12 5:54am    
Didn't worked!!!
In second text box it Just Duplicated" Sister Sister Sister Sister Sister Sister"

When i press the many times
OriginalGriff 24-Dec-12 6:03am    
It wasn't meant to fix the problem: hence the word "experiment".
It was meant to find out more detail of what happens.
Try it again, but this time replace the line with
TextBox3.Text += rtn & "..."
It won't fix the problem, but it should give us a better idea of what is actually happening.
[no name] 24-Dec-12 6:21am    
First of all thanks spending Your valuable time with me Merry Christmas
as you said it not done!
it giving "1 Sister1 Sister1 Sister1 Sister"


VB
Dim Rtn As Integer
        Rtn = Val(Lnt.Length)
        Select Case Rtn
            Case 1
                If Lnt = 1 Then
                    TextBox3.Text = " Sister"
                Else
                    If Lnt = 2 Then
                        TextBox3.Text = "Enemy"
                    Else
                        If Lnt = 3 Then
                            TextBox3.Text = "Enemy "
                        Else
                            If Lnt = 4 Then
                                TextBox3.Text = "Enemyes"
                            Else
                                If Lnt = 5 Then
                                    TextBox3.Text = "Friends"
                                Else
                                    If Lnt = 6 Then
                                        TextBox3.Text = "Marriage "
                                    Else
                                        If Lnt = 7 Then
                                            TextBox3.Text = "Enemys"
                                        Else
                                            If Lnt = 8 Then
                                                TextBox3.Text = "Affection"
                                            Else
                                                If Lnt = 9 Then
                                                    TextBox3.Text = "Enemys"
                                                Else
                                                    If Lnt = 10 Then
                                                        TextBox3.Text = "Lovers "
                                                    Else
                                                        If Lnt = 11 Then
                                                            TextBox3.Text = "Lovers"
                                                        Else
                                                            If Lnt = 12 Then
                                                                TextBox3.Text = "Affection"
                                                            End If
                                                        End If
                                                    End If
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
        End Select
    End Sub
 
Share this answer
 
Comments
Thomas Daniels 24-Dec-12 8:38am    
Perhaps this code block did solve your problem, but it's a really huge and hard to understand code block. There're very much IFs and the code isn't very readable.
Sergey Alexandrovich Kryukov 3-Jun-13 13:59pm    
Not just abuse, super abuse. Could be used in illustration of the book "How not to program".
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900