Hi guys,

I have spent a morning working on this. Not sure if I will ever get it right.
What I want to do is read a text file and based on list of constant values split the original file in two smaleer files.
One of them to contain only the rows from original file, and the other one to contain only the rows from original file that don`t match the values from the lsit.
So If I have File A and list of criteria (1,2,3,4,5- known number)
in output I should have file a.txt that will have rows from file A that match the 1,2,3,4,5 . and file b.txt that will have no matching values to the criteria 1,2,3,4.
In every row the criteria string in File A will be positioned at the same position.
I have this code so far:

Dim st As String = Mid(RichTextBox1.Text, 96, 8)
        Dim strrow As String = RichTextBox1.Text.Remove(800)
        Dim 1 As String
        Dim 2 As String

        If st = ("1" Or "2") Then
            Dim sw2 As New FileStream("C:\Test\part1.txt", FileMode.Create, FileAccess.Write)
            Dim ss As New StreamWriter(sw2)
            ss.WriteLine(strrow)

        Else
            Dim sw1 As New FileStream("C:\Test\part2.txt", FileMode.Create, FileAccess.Write)
            Dim ss As New StreamWriter(sw1)
            ss.WriteLine(strrow)
            ss.Close()


        End If

it throws error when i run it it says cannot convert double to string.
I don`t understand why . Also I need to loop through every row in the file in every row starting fro 96 characte to 104 i will have to check if that vaue matches 1,2,3 ... or not , based on that to split the original file in two files.
Would I bind values of criteria to an array. That I can do but then I have no idea what the syntax might be.

Thanks in advance for your help.

Dim 1 As String
Dim 2 As String

Variables can't be numeric, use one or two instead.
And please clarify the question more

Hi Ramy,

thanks for looking at this.
I will try and explain in depth.
I Have a big file wich is tab delimited.
For exampl ai row in a file looks like this:
ABC25KLM980TNH
in every row at the very same position let`s say 4 to 7 I will have a string that I need to check against my list of criteria.In this case "25K"
My list of Criteria will contain 23 string values and I need to check every raw in the file , if the string("25K") is the same as one of the strings in my list or not.List string criterias will be the same lenght as the string I have in every row, some of them will match , others won`t.
In case row one matches any of the string values in the criteria list then that row will all be written in file1.txt and if row 1 doesn`t match any of the 23 values in my criteria list then the row will be written in file2.txt
Also I need to have same record lenghts in the newly created files as in the original raw file.

Hope this makes more sence now.
Thank you for replying

This article has been dead for over six months. Start a new discussion instead.