Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Streamreader in vb.net

Hi,
I am reading a file from richtextbox with streamreader.While reading the file if certain condition is met I am jumping out of the sub by exit sub.i need to again go back to the sub and begin reading the file from that line.Can anybody help me in that code attached.
Don't know how to declare streamreader
Public Sub Get_SQL_Line(ByRef SQL As String)
        Dim EOFile As Boolean
        Dim CreateStatement As Boolean
        Dim CommentBlock As Boolean
        Dim StoredProcedure As Boolean
        Dim strreader As New IO.StreamReader(TempSQLPath)
        Try
 
              If NextLine = String.Empty Then
 
                NextLine = strreader.ReadLine()
 
                LineNo += 1
            End If
            Do
 
                CurrLine = NextLine
                If strreader.EndOfStream Then
                      If NextLine = String.Empty Then Exit Sub
                    If NextLine = vbNewLine Then Exit Sub
                    If NumLines = LineNo Then EOFile = True
                    NextLine = String.Empty
                Else
                    NextLine = strreader.ReadLine
                    LineNo += 1
 
 
                End If
 
 
                'Create statement block
                If Trim(UCase(Left(CurrLine, 16))) = "CREATE PROCEDURE" OrElse Trim(UCase(Left(CurrLine, 14))) = "CREATE TRIGGER" OrElse Trim(UCase(Left(CurrLine, 11))) = "CREATE VIEW" Then
                    CreateStatement = True
                End If
                If Trim(UCase(Left(CurrLine, 15))) = "ALTER PROCEDURE" OrElse Trim(UCase(Left(CurrLine, 7))) = "DECLARE" Then
                    StoredProcedure = True
                End If
                If Trim(UCase(Left(CurrLine, 2))) = "GO" Then
                    StoredProcedure = False
                End If
                'Comment block
                ' added OrElse Right(Trim(CurrLine), 2) = "*/"
                If Left(Trim(CurrLine), 2) = "/*" OrElse Right(Trim(CurrLine), 2) = "*/" Then
                    If Not StoredProcedure Then
                        CommentBlock = True 'Note that SQL Server/Oracle scripts file may have comments formatted as /*  comment */
                    End If
                End If
                If CommentBlock Then
                    'If InStr(CurrLine, "*/") > 0 Then
                    If CurrLine.IndexOf("*/") > 0 Then
 
                        CurrLine = Trim(Right(CurrLine, Len(CurrLine) - (InStr(CurrLine, "*/") + 1)))
                        CommentBlock = False
                    End If
                End If
                If Not CommentBlock Then
                    If Right(CurrLine, 1) = ";" Then
                        SQL = CurrLine
                    ElseIf NextLine.Trim = ";" Then
                        SQL = CurrLine
                        NextLine = String.Empty
                    ElseIf (NextLine.Trim = "" AndAlso Not StoredProcedure) Then
                        SQL = CurrLine
                        NextLine = String.Empty
                    ElseIf (NextLine.Trim).ToUpper = "GO" Then
                        SQL = CurrLine
                        NextLine = String.Empty
                    ElseIf (Not CreateStatement AndAlso CheckNextLine(CurrLine, NextLine) AndAlso Not StoredProcedure) Then
                        SQL = CurrLine
                    ElseIf Not EOFile Then
                        If CurrLine <> "" Then
                            arrNextLine.Add(CurrLine)
                        End If
                        If NextLine <> "" Then
                            arrNextLine.Add(NextLine)
                        End If
                        NextLine = CurrLine & vbNewLine & NextLine
                        Get_SQL_Line(SQL)
                    Else
                        SQL = CurrLine
                    End If
                End If
                If (arrNextLine.Count = 0 AndAlso CurrLine <> "") Then
                    arrNextLine.Add(CurrLine)
                End If
                SQL = CleanSQL(SQL)
                If EOFile Then Exit Sub
                          Loop While SQL = String.Empty
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oobayly
oobayly
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial