Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello dope community, I did search a lot about this but found nothing
so simply I do have 1 textbox, 1 label called "Invalid", 1 button and finally a text file

the text file has numbers in lines or more likely a zip codes written by that way:
"10000
23251
30021
51931
and so on..."
textbox = type the zip code number
button = to search if the number which i did type in the textbox is inside the text file or not
if yes then label1.text = "Valid"

and that's pretty much all of it

I tried the following but I know it's totally wrong + it doesn't work + it will talk so long time to type each and every single number in it

Thank you so much in advance

What I have tried:

nothing so far, I've tried this:

If value1 = 10000 or 23251 or 30021 or 51931 Then
            Label1.Text = "VALID"
        End If
Posted
Updated 23-Feb-22 21:44pm

Just treat it as text: use File.ReadAllLines to read the file data into an array, then use Linq methods to tell you if there is an exact match:
VB
If linesFromFile.Any(Function(l) l = myTextBox.Text) Then
    label1.Text = "Valid"
End If
 
Share this answer
 
Comments
Sam K. Lewis 24-Feb-22 9:44am    
Thank you so much for your reply, I've tried this:

Dim File As String = "Georgia.txt"
Dim Georgia As String = IO.File.ReadAllLines(File)
If Georgia.Any(Function(l) l = TextBox1.Text) Then
Label1.Text = "Valid"
End If

but not good so far, i think I did a mistake
OriginalGriff 24-Feb-22 10:47am    
why do you think that ReadAllLines would return a single string?
If you come across a method you don't recognise, don't guess - check the documentation!
independant from the answer from Griff (which is pretty pretty good) your code-snipped would not work. If you want to do something like this your code must look like :
If (value1 = 10000) or (value1 = 23251) or (value1 = 30021) or (value1 = 51931) Then
   Label1.Text = "VALID"
End If
 
Share this answer
 
Comments
Sam K. Lewis 24-Feb-22 9:45am    
That helped a lot, small thing but matters!
I Appreciate you

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