Wanxi

Hi everyone =)

I'm using Visual Basic 2005 Express Edition..

When i trying to take data out from text document and

show it out at data grid and

my graph..

It happen to become like this.. Click HERE to view..

As you see, the highlighted box is showing a very weird character..

And it will always happen on the very first few character..

It actually should show 15:46:03

p/s: when i open it in excel.. it will also appear..

How to get rid of it

My program is something like this:

Part of my Program:

FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)

Do While Not EOF(1)

LoadTextLine = LineInput(1)

rows = New DataGridViewRow

rows.CreateCells(Me.DataGridView1)

rows.Cells(0).Value = Trim(LoadTextLine.Substring(0, 8))

rows.Cells(1).Value = Trim(LoadTextLine.Substring(14))

Me.DataGridView1.Rows.Add(rows)

Loop

DataGridView1.Refresh()

FileClose(1)

Thank you

Regards

Wanxi =)




Re: Visual Basic Express Edition When showing data from Text Doc to DataGrid, there always some unknown character appear at the first line

Rajavanya

plz upload your text file somewhere... let us take a look

you can use rapidshare or googlepages or any other file upload service.




Re: Visual Basic Express Edition When showing data from Text Doc to DataGrid, there always some unknown character appear at the first line

Wanxi

MyFileName: 11112007

15:46:03:70 145
15:46:04:87 146
15:46:06:04 146
15:46:07:23 147
15:46:08:42 233
15:46:30:98 251
15:46:32:17 245
15:46:33:32 158
15:46:34:51 136
15:46:39:21 325
15:46:40:39 209
15:46:41:56 325
15:46:42:75 314
15:46:43:92 180
15:46:45:09 166
15:46:48:64 162
15:46:49:81 161
15:46:51:00 162
15:46:52:15 160
16:12:08:21 284
16:12:09:42 251
16:12:10:57 284
16:12:11:75 260
16:12:12:93 279
16:12:18:82 194
16:12:20:01 222
16:12:21:18 220
16:12:22:37 222
16:12:29:42 223
16:12:30:59 224
16:47:52:32 34
16:47:53:51 53
16:47:54:67 50
16:47:55:84 56
16:47:57:03 30
16:47:58:21 24
16:47:59:39 22
16:48:00:56 22
16:48:01:75 23
16:48:02:92 23
16:48:04:09 116
16:48:05:28 248
16:48:06:45 239
16:48:07:60 279
16:48:08:79 99
16:48:09:98 95
16:48:11:15 96
16:48:12:32 96
16:48:13:51 97
16:48:14:68 247
16:48:15:85 378
16:48:17:04 371
16:48:18:21 130
16:48:19:40 129
16:48:20:59 128
16:48:21:75 124






Re: Visual Basic Express Edition When showing data from Text Doc to DataGrid, there always some unknown character appear at the first line

Dave299

This is to do with the file encoding. Try using the .net methods for reading the file instead:

Dim SR As New IO.StreamReader("d:\temp\test.txt")

Dim Line As String

While Not SR.EndOfStream

Line = SR.ReadLine

' your code

End While





Re: Visual Basic Express Edition When showing data from Text Doc to DataGrid, there always some unknown character appear at the first line

Wanxi

Hi Dave299,

Your method is working.. =) Thank you very much..

By the way, do i need to add --> myStreamReader.Close()

Have a nice day ^__^

Regards

Wan Xi






Re: Visual Basic Express Edition When showing data from Text Doc to DataGrid, there always some unknown character appear at the first line

Wanxi

Oh! One more question..

If i need to open 2 times.. what should i do

can i do it like this

The highlighted:

I need to open 2 times, bcos if not like that.. when the first time it open and read until end of file..

the 2nd one couldnt read anymore..

Code Block

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

Do While Not LoadMyStreamReader.EndOfStream

LoadTextLine = LoadMyStreamReader.ReadLine

rows = New DataGridViewRow

rows.CreateCells(Me.DataGridView1)

rows.Cells(0).Value = Trim(LoadTextLine.Substring(0, 8))

rows.Cells(1).Value = Trim(LoadTextLine.Substring(14))

Me.DataGridView1.Rows.Add(rows)

Loop

DataGridView1.Refresh()

LoadMyStreamReader.Close()

'Dim MyStreamReader As New IO.StreamReader(OpenFileDialog1.FileName)

'FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)

LoadMyStreamReader.EndOfStream

CreateGraph(zg1)

FileClose(1)

Else

MessageBox.Show("Please choose a correct file")

End If






Re: Visual Basic Express Edition When showing data from Text Doc to DataGrid, there always some unknown character appear at the first line

Wanxi

Oh! One more question..

If i need to open 2 times.. what should i do

can i do it like this

The highlighted:

I need to open 2 times, bcos if not like that.. when the first time it open and read until end of file..

the 2nd one couldnt read anymore..

Code Block

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

Do While Not LoadMyStreamReader.EndOfStream

LoadTextLine = LoadMyStreamReader.ReadLine

rows = New DataGridViewRow

rows.CreateCells(Me.DataGridView1)

rows.Cells(0).Value = Trim(LoadTextLine.Substring(0, 8))

rows.Cells(1).Value = Trim(LoadTextLine.Substring(14))

Me.DataGridView1.Rows.Add(rows)

Loop

DataGridView1.Refresh()

'Dim MyStreamReader As New IO.StreamReader(OpenFileDialog1.FileName)

'FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)

CreateGraph(zg1)

FileClose(1)

Else

MessageBox.Show("Please choose a correct file")

End If






Re: Visual Basic Express Edition When showing data from Text Doc to DataGrid, there always some unknown character appear at the first line

Dave299

Once you have read the file you should close the reader; that will also call its dispose method.

To open the file again simply create a new reader, but not using Dim. All you need (in my example) is

SR = New IO.StreamReader("d:\temp\test.txt")