|
-
Dec 2nd, 2004, 05:21 AM
#1
Thread Starter
Junior Member
how to show a lots of data though MSFlexGrid [*resolved]
I need to read a text file and output the data
I tried the code below
but because the data is so many that it takes much time to run
how to faster it?
please help me, thanks very much
'=======================================
TotalNum = 0 'the total row of the file, about 7050
'first loop to get the row of the file
Open App.Path & "\1.dat" For Input As #1
Do While Not EOF(1)
Line Input #1, MyData1
TotalNum = TotalNum + 1
Loop
Close #1
MSFlexGrid1.Rows = TotalNum + 1
'the second loop to send data to MSFlexGrid1
i = 0
Open App.Path & "\1.dat" For Input As #1
Do While Not EOF(1)
Line Input #1, MyData1
i = i + 1
TempString = MyData1
MyData1 = Split(TempString, ",")
With MSFlexGrid1
.Row = i
.Col = 0
.Text = MyData1(0)
.Col = 1
.Text = MyData1(1)
.Col = 2
.Text = MyData1(2)
.Col = 3
.Text = MyData1(3)
.Col = 4
.Text = MyData1(4)
End With
Loop
'========================================
a part of the text file
2.,217.6604,199.8500,199.8500,200.4962
4.,227.5204,199.8500,199.8500,201.0546
6.,234.5468,199.8501,199.8500,201.5784
8.,240.2048,199.8503,199.8500,202.0836
10.,245.0417,199.8509,199.8500,202.5763
12.,249.3170,199.8520,199.8500,203.0596
14.,253.1766,199.8542,199.8500,203.5354
16.,256.7126,199.8580,199.8500,204.0048
18.,259.9873,199.8641,199.8500,204.4688
20.,263.0456,199.8732,199.8500,204.9279
22.,265.9207,199.8861,199.8500,205.3826
24.,268.6383,199.9038,199.8500,205.8334
26.,271.2185,199.9271,199.8500,206.2806
28.,273.6777,199.9569,199.8500,206.7244
30.,276.0292,199.9939,199.8500,207.1650
32.,278.2840,200.0390,199.8500,207.6028
34.,280.4515,200.0927,199.8500,208.0378
36.,282.5396,200.1556,199.8500,208.4702
38.,284.5551,200.2283,199.8500,208.9001
40.,286.5039,200.3111,199.8500,209.3276
42.,288.3912,200.4043,199.8500,209.7530
44.,290.2215,200.5082,199.8500,210.1761
46.,291.9988,200.6230,199.8500,210.5972
48.,293.7268,200.7487,199.8500,211.0163
50.,295.4086,200.8853,199.8500,211.4335
52.,297.0470,201.0329,199.8500,211.8489
54.,298.6447,201.1914,199.8500,212.2624
56.,300.2041,201.3606,199.8501,212.6743
58.,301.7272,201.5403,199.8501,213.0844
60.,303.2160,201.7306,199.8501,213.4930
Last edited by junny; Dec 2nd, 2004 at 08:22 AM.
-
Dec 2nd, 2004, 05:36 AM
#2
First of all, you shouldn't be using .Text if you want speed, as setting the row/col fires some events (so is slow). Use .TextMatrix instead, eg:
VB Code:
'instead of this:
.Row = i
.Col = 0
.Text = MyData1(0)
.Col = 1
.Text = MyData1(1)
...
'use this:
.TextMatrix(i, 0) = MyData1(0)
.TextMatrix(i, 1) = MyData1(1)
...
Next, you can use better methods of putting large amounts of data into the grid.
The one that seems best in this case is AddItem, here's how it could work:
VB Code:
MSFlexGrid1.Rows = 1
'load file and put the data in to MSFlexGrid1
Open App.Path & "\1.dat" For Input As #1
Do While Not EOF(1)
Line Input #1, MyData1
MSFlexGrid1.AddItem Replace(MyData1, ",", vbTab)
Loop
MSFlexGrid1.RemoveItem 1 '(remove blank row)
This has the bonus of only reading the file once, which will make the whole process much faster if the file is large.
-
Dec 2nd, 2004, 06:23 AM
#3
Thread Starter
Junior Member
-
Dec 2nd, 2004, 06:25 AM
#4
junny,
Also why do you read thru the file first then fill the grid? There is no need for this. Do both at the same time.
-
Dec 2nd, 2004, 07:25 AM
#5
Thread Starter
Junior Member
I tried the code below,but it doesn't seem to faster
thanks for your reply all the same
VB Code:
Option Explicit
Dim time
Dim time1
Private Sub Form_Load()
Call now_time
Dim i, j As Integer
Dim mydata1(10000)
'load file and put the data in to MSFlexGrid1
i = 0
Open App.Path & "\1.dat" For Input As #1
Do While Not EOF(1)
Line Input #1, mydata1(i)
i = i + 1
Loop
MSFlexGrid1.Rows = 1
For j = 0 To i
MSFlexGrid1.AddItem Replace(mydata1(j), ",", vbTab)
Next
Call now_time1
MsgBox Second(time1 - time)
End Sub
Private Sub now_time()
time = Now()
End Sub
Private Sub now_time1()
time1 = Now()
End Sub
-
Dec 2nd, 2004, 07:37 AM
#6
junny
I meant your code should look something like this:
VB Code:
Option Explicit
Dim time
Dim time1
Private Sub Form_Load()
Dim i As Integer
Dim mydata1
Call now_time
'load file and put the data in to MSFlexGrid1
MSFlexGrid1.Rows = 1
i = 0
Open App.Path & "\1.dat" For Input As #1
Do While Not EOF(1)
Line Input #1, mydata
MSFlexGrid1.AddItem Replace(mydata, ",", vbTab)
i = i + 1
Loop
Call now_time1
MsgBox Second(time1 - time)
End Sub
Private Sub now_time()
time = Now()
End Sub
Private Sub now_time1()
time1 = Now()
End Sub
-
Dec 2nd, 2004, 07:51 AM
#7
Also try setting the Redraw property to false while your loading the info then set it basck to true afterwards.
-
Dec 2nd, 2004, 08:21 AM
#8
Thread Starter
Junior Member
thanks you all very much!!!!!!!!!!!!
I used the code below and it's so fast that cost only 1 second!
the process of redaw spends so much time!
thank DeadEyes,and thank you all !
VB Code:
Option Explicit
Dim time
Dim time1
Private Sub Form_Load()
Call now_time
Dim mydata1
MSFlexGrid1.Rows = 1
MSFlexGrid1.Redraw = False
'load file and put the data in to MSFlexGrid1
Open App.Path & "\1.dat" For Input As #1
Do While Not EOF(1)
Line Input #1, mydata1
MSFlexGrid1.AddItem Replace(mydata1, ",", vbTab)
Loop
Call now_time1
MSFlexGrid1.Redraw = True
MsgBox Second(time1 - time)
End Sub
Private Sub now_time()
time = Now()
End Sub
Private Sub now_time1()
time1 = Now()
End Sub
-
Dec 2nd, 2004, 01:40 PM
#9
junny
You should always make a habit of fully defining you dim statements. The way you define them as variants instrad of what they actually are such as date, string, long, integer etc...
You will avoid problems in the future and variants cost more in space and processing time.
-
Dec 3rd, 2004, 07:22 AM
#10
Thread Starter
Junior Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|