Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
dim AllPlayerInfo as string()

AllPlayerInfo = PlayerFile.split(vbcrlf)

If Not AllPlayerInfo.Length = 0 Then

            If AllPlayerInfo(1) = TextBox1.Text Then

                If AllPlayerInfo(2) = TextBox2.Text Then

                    MsgBox("Hello " & TextBox1.Text)

                    Return True
                    Exit Function

                End If

            End If

        End If
  MsgBox("Can't Find This Account .. , MsgBoxStyle.Information)

    Return False





The problem is it show the can't find msgbox
even AllPlayerInfo(1) = TextBox1.Text and AllPlayerInfo(2) = TextBox2.Text


How can i solve this
Posted
Updated 11-Jan-14 9:16am
v2

Try this:

VB
Dim AllPlayerInfo As String()

AllPlayerInfo = PlayerFile.Split(vbCrLf.ToCharArray, StringSplitOptions.RemoveEmptyEntries)

If Not AllPlayerInfo.Length = 0 AndAlso AllPlayerInfo(1).ToLower() = TextBox1.Text.ToLower() AndAlso AllPlayerInfo(2).ToLower() = TextBox2.Text.ToLower() Then
      MsgBox("Hello " & TextBox1.Text)
      Return True
Else
      MsgBox("Can't Find This Account .. ", MsgBoxStyle.Information)
      Return False
End If


Your messagebox always displays becuase you have written it outside the scope of IF..THEN..ELSE statement. By doing this it will display iff the "Length" property returns zero, which is your intentions i guess.

Hope it helps!

EDIT

First of all, the code has been modified. I have figured out a couple of things is your code.

1) No need to EXIT FUNCTION when there is already RETURN statement present. So remove it.
2) Change:

PlayerFile.Split(vbCrLf)


to :

PlayerFile.Split(vbCrLf.ToCharArray, StringSplitOptions.RemoveEmptyEntries)

my guess is that you are getting a "vbLf" appended in front of the next array element which fails the comparison. So doing it this way will fix this issue.

3) When we compare strings it is preferred to make it either UPPER case or LOWER case, so i have used .ToLower(), depending upon case sensitivity. Please adjust it as per your scenario.

4) It is good to define ELSE part for each IF..ELSE IF condition, it helps to cover the rest of the cases so instead of defining three ELSE statements i have minimized the condition to one IF..ELSE statement.

Check it out. Hope it helps!

If you need further assistance please come up with sample values of variables and the desired result examples.

Happy coding!!!
 
Share this answer
 
v2
Comments
CPallini 11-Jan-14 15:16pm    
5.
Shahan Ayyub 11-Jan-14 15:19pm    
Thanks. :)
Tarek Mohamed Abdalla 12-Jan-14 4:24am    
No it didn't work there is a problem in the array when i say
AllPlayerInfo(1) = TextBox1.Text</pre>It dind't work but if i do this it work ....!<pre lang="vb">If TextBox1.Text = "admin" Then

If TextBox2.Text = "admin" Then

MsgBox("Hello " & TextBox1.Text)

Return True



End If

End If</pre>
Ok but i want the array not specific string

plz help me
Shahan Ayyub 12-Jan-14 15:02pm    
Check out each point of the updates.
VB
dim AllPlayerInfo as string()

AllPlayerInfo = PlayerFile.split(vbcrlf)

If Not AllPlayerInfo.Length = 0 Then

            If AllPlayerInfo(0) = TextBox1.Text Then

                If AllPlayerInfo(1) = TextBox2.Text Then

                    MsgBox("Hello " & TextBox1.Text)

                    Return True
                    Exit Function

                End If

            End If
Else
  MsgBox("Can't Find This Account .. , MsgBoxStyle.Information)
End If

Return False
 
Share this answer
 

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