Murray Brown
asked on
VB.net Reading text files not working as expected (RichTextBox)
Hi
I am using the following two procedures to write 4 lines to a text file and read the file.
A SQL statement is held in a RichTextBox. Once the files are written using the first procedure, they are read when needed. In the attached file Access.txt it works as normal and in the text file SQL.txt it seems to skip the fourth line. Does this have something to do with the RichTextBox
Public Sub oSaveQuery(ByVal oFolder As String, ByVal oTextFileName As String)
Dim lblDataBaseType As Label = Globals.ThisAddIn.oRIGHT.l blDataBase Type
Dim lblConnectionString As Label = Globals.ThisAddIn.oRIGHT.l blConnecti onString
Dim txtSQL As RichTextBox = Globals.ThisAddIn.oBOTTOM. txtSQL
Using writer As StreamWriter = New StreamWriter(oFolder & "\" & oTextFileName)
writer.WriteLine("ELEMENTS Query loading. Please wait a moment...")
writer.WriteLine(lblDataBa seType.Tex t)
writer.WriteLine(lblConnec tionString .Text)
writer.WriteLine(txtSQL.Te xt)
End Using
End Sub
Public Function oGetQuickRunQueryInfo(ByVa l oFolder As String, ByVal oTextFileName As String) As String
Dim oReader As System.IO.StreamReader
oReader = System.IO.File.OpenText(oF older & "\" & oTextFileName & ".eleq")
Dim DBType As String
Dim oDataBaseType As String
Dim oConnectionString As String
Dim oSQL As String
Dim oTest As String
With oReader
Dim sELEMENTS_TAG As String = .ReadLine 'this is used when the file is double clicked on for file association
oDataBaseType = .ReadLine
oConnectionString = .ReadLine
oSQL = .ReadLine
oTest = .ReadLine
Globals.ThisAddIn.oRIGHT.l blDataBase Type.Text = oDataBaseType
Globals.ThisAddIn.oRIGHT.l blConnecti onString.T ext = oConnectionString
Globals.ThisAddIn.oBOTTOM. txtSQL.Tex t = oSQL
DBType = oDataBaseType
.Close()
End With
oReader = Nothing
oGetQuickRunQueryInfo = oDataBaseType & "|" & oConnectionString & "|" & oSQL
End Function
SQL.txt
Access.txt
I am using the following two procedures to write 4 lines to a text file and read the file.
A SQL statement is held in a RichTextBox. Once the files are written using the first procedure, they are read when needed. In the attached file Access.txt it works as normal and in the text file SQL.txt it seems to skip the fourth line. Does this have something to do with the RichTextBox
Public Sub oSaveQuery(ByVal oFolder As String, ByVal oTextFileName As String)
Dim lblDataBaseType As Label = Globals.ThisAddIn.oRIGHT.l
Dim lblConnectionString As Label = Globals.ThisAddIn.oRIGHT.l
Dim txtSQL As RichTextBox = Globals.ThisAddIn.oBOTTOM.
Using writer As StreamWriter = New StreamWriter(oFolder & "\" & oTextFileName)
writer.WriteLine("ELEMENTS
writer.WriteLine(lblDataBa
writer.WriteLine(lblConnec
writer.WriteLine(txtSQL.Te
End Using
End Sub
Public Function oGetQuickRunQueryInfo(ByVa
Dim oReader As System.IO.StreamReader
oReader = System.IO.File.OpenText(oF
Dim DBType As String
Dim oDataBaseType As String
Dim oConnectionString As String
Dim oSQL As String
Dim oTest As String
With oReader
Dim sELEMENTS_TAG As String = .ReadLine 'this is used when the file is double clicked on for file association
oDataBaseType = .ReadLine
oConnectionString = .ReadLine
oSQL = .ReadLine
oTest = .ReadLine
Globals.ThisAddIn.oRIGHT.l
Globals.ThisAddIn.oRIGHT.l
Globals.ThisAddIn.oBOTTOM.
DBType = oDataBaseType
.Close()
End With
oReader = Nothing
oGetQuickRunQueryInfo = oDataBaseType & "|" & oConnectionString & "|" & oSQL
End Function
SQL.txt
Access.txt
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I thought that that would have definitely done the trick, but sadly it didn't. I am perplexed as to why a blank line gets written in like that
ASKER
I think it has something to do with the line Server=41.72.128.100;Datab ase=MagicB ox_MicrosS andBox;Uid = MicrosDBN;Pwd= MBN
There is a space in the connection string
The following shows the first text file (first paragraph) and the second text file, which is fragmented because of the connection string I wrote
ELEMENTS Query loading. Please wait a moment...
Access
Provider=Microsoft.ACE.OLE DB.12.0;Da ta Source=C:\Users\murbro\Doc uments\Mag icBox.accd b;
SELECT [Transactions].[Amount], [Transactions].[ID] FROM [Transactions] WHERE [Transactions].[ID]>105 And [Transactions].[ID] < 1000
ELEMENTS Query loading. Please wait a moment...
SQL
Server=41.72.128.100;Datab ase=MagicB ox_MicrosS andBox;Uid = MicrosDBN;Pwd= MBN
SELECT [Periods].[Co_ID], [Periods].[End Date], [Periods].[Period], [Periods].[Start Date] FROM [Periods]
There is a space in the connection string
The following shows the first text file (first paragraph) and the second text file, which is fragmented because of the connection string I wrote
ELEMENTS Query loading. Please wait a moment...
Access
Provider=Microsoft.ACE.OLE
SELECT [Transactions].[Amount], [Transactions].[ID] FROM [Transactions] WHERE [Transactions].[ID]>105 And [Transactions].[ID] < 1000
ELEMENTS Query loading. Please wait a moment...
SQL
Server=41.72.128.100;Datab
SELECT [Periods].[Co_ID], [Periods].[End Date], [Periods].[Period], [Periods].[Start Date] FROM [Periods]
But space should not translate to line break.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
opps..
writer.Close()
writer.Close()
ASKER
Interestingly the .close put the blank line in both
ELEMENTS Query loading. Please wait a moment...
SQL
Server=41.72.123.100;Datab ase=MagicB ;Uid=MB_Do ppio; Pwd=D0xxxxx0
SELECT [Accounting].[Account Type], [Accounting].[Co_ID], [Accounting].[Display Name], [Accounting].[FinCatCode], [Accounting].[GL ACCOUNT], [Accounting].[ID], [Accounting].[Report Category], [Accounting].[Segment 1], [Accounting].[Segment 1 Desc], [Accounting].[Segment 2], [Accounting].[Segment 2 Desc], [Accounting].[Segment 3], [Accounting].[Segment 3 Desc], [Accounting].[Segment 4], [Accounting].[Type] FROM [Accounting]
‘------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
ELEMENTS Query loading. Please wait a moment...
SQL
Server=41.72.123.100;Datab ase=MagicB ;Uid=MB_Do ppio; Pwd=D0xxxx0
SELECT [Accounting].[Account Type], [Accounting].[Co_ID], [Accounting].[Display Name], [Accounting].[FinCatCode], [Accounting].[GL ACCOUNT], [Accounting].[ID], [Accounting].[Report Category], [Accounting].[Segment 1], [Accounting].[Segment 1 Desc], [Accounting].[Segment 2], [Accounting].[Segment 2 Desc], [Accounting].[Segment 3], [Accounting].[Segment 3 Desc], [Accounting].[Segment 4], [Accounting].[Type] FROM [Accounting]
ELEMENTS Query loading. Please wait a moment...
SQL
Server=41.72.123.100;Datab
SELECT [Accounting].[Account Type], [Accounting].[Co_ID], [Accounting].[Display Name], [Accounting].[FinCatCode],
‘-------------------------
ELEMENTS Query loading. Please wait a moment...
SQL
Server=41.72.123.100;Datab
SELECT [Accounting].[Account Type], [Accounting].[Co_ID], [Accounting].[Display Name], [Accounting].[FinCatCode],
ASKER
Thanks very much for the help.
ASKER