Hi guys,

I am experiencing a problem with a variable I declare. If I pass on a real value that the variable might contain code works ok , but if I leave the code to get the variable as decalred it doesn`t.
What my code is doing is checking if a string variable exists in a string array. Here is the code:

Dim frow As String = Mid(RichTextBox1.Text, 1, 800)
        Dim ftreaty As String = Mid(frow, 96, 9)
        Dim StrArray() As String = {"AB3VLMY2", "AUMN56HG"}
        Dim FindString As String = ftreaty
        For Each Str As String In StrArray
            If Str.Contains(FindString) Then

                RichTextBox2.Text &= frow & Environment.NewLine

            End If
        Next

        Dim fs2 As New FileStream("C:\File.txt", FileMode.Create, FileAccess.Write)
        Dim ss As New StreamWriter(fs2)
        ss.WriteLine(RichTextBox2.Text)
        ss.Close()

Please please tell me where I am wrong :P
When instead of
Dim FindString As String = ftreaty
I give a real value like

Dim FindString As String = "AUMN56HG" for example
it does the check and writes the row in the new file.
when however the code is like above it writes an empty row having that in the original file the value in the first row it should pick up is in the array and it should write the row in the new file. It doesn`t though it simply writes an empty row.

Thanks in advance

Like you said, if you pass it a real value then you have no problems, so the problem would be in these two lines. Did you check the value that's coming back from Mid(RichTextBox1.Text, 1, 800) ? If this isn't returning a value then that's the problem.

Otherwise check the return value on Mid(frow, 96, 9) as well. If they are returning the proper values then we'll have to take a closer look at it.

Hi nexocentric,
thanks for looking at this.
I have cheked that the expressions return the correct result.
I am doing my task bit by bit so I have some more code , where I managed to read the tab delimited file and write it in the same format as I will need the file to be same format as in the original file.
The problem is I have to take a string bit ftreaty from the tab delimited file , but that ftreaty string bit isn`t at the beggining of a new column it`s in the middle of a tab column in the text file.
So the only way I could think of was get the string using Mid from the whole row.
Every row should always be 800 characters long and the ftreaty part wpould be starting from 96th character and would be 9 char long.
So not really sure if I do thing as they should be done.
Thank you for reply

Your call to Mid is taking a string of 9 chars.
Dim ftreaty As String = Mid(frow, 96, 9)

but what you are searching for is 8 chars long.
Dim FindString As String = "AUMN56HG"

Which might be why it would work when you typed in the value directly. Can you check that really quick?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.