我的程式碼如下,是從小雄資訊中心VB6 控制項運用的MSFlexGrid存檔與讀檔修改了一下!..^_^
我想請問一下大大
像MSFlexGrid存檔與讀檔是可以
但是MSFlexGrid的儲存格如果為1000x300
時儲存和讀檔就變的滿慢的要如何解決?
我存檔是用For .....then.....去一格一格存的!
讀檔也是...........但多一個Split(... ,\"....\")函數去讀檔!
所以不知道各位大大是否有更好的想法!或者是更
好的演算法可否請各位大大賜教!感謝喔!
存檔:
Open \"C:\\Documents and Settings\\Administrator\\桌面\\1.save\" For Output As #1
Print #1, MSFlexGrid1.FixedCols & \"+\" & MSFlexGrid1.FixedRows & \"+\" & MSFlexGrid1.Cols & \"+\" & MSFlexGrid1.Rows
For a = 0 To MSFlexGrid1.Rows - 1
MSFlexGrid1.Row = a
ColCombient = \"\"
For b = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = b
If MSFlexGrid1.Col = Val(MSFlexGrid1.Cols - 1) Then
ColCombient = ColCombient & MSFlexGrid1.Text
Else
ColCombient = ColCombient & MSFlexGrid1.Text & \",\"
End If
Next b
Print #1, ColCombient
Next a
Close #1
讀檔:
Open \"C:\\Documents and Settings\\Administrator\\桌面\\1.save\" For Input As #1
Line Input #1, mydat
Data1 = Split(mydat, \"+\")
MSFlexGrid1.Cols = Data1(2)
MSFlexGrid1.Rows = Data1(3)
\'先讀出MSFlexGrid1的基本資料
\'--------------------------------------------------------
\'在讀出儲存隔的檔案!
For Idx = 0 To Data1(3) - 1
MSFlexGrid1.Row = Idx
Line Input #1, mydat
Data2 = Split(mydat, \",\")
For Idy = 0 To UBound(Data2)
MSFlexGrid1.Col = Idy
MSFlexGrid1.Text = Data2(Idy)
Next
Next
Close #1
2006-07-15 23:17:05 · 2 個解答 · 發問者 鳴 5 in 電腦與網際網路 ➔ 程式設計
'MSFlexGridx的行與行之間是用vbTab=Chr(9)做區隔,而列與列之間則是以VbCr=Chr(13)來區格,可善用這2個來加速資料存取的速度,若只是要改變單格的資料利用Text屬性還可以,但是若資料量很大因此法每格都必須先指定Row&Col無形中就拖垮速度了,介紹3種輸入的方式你試試看^_^Private Sub Form_Load() With MSFlexGrid1 .Rows = 1: .Cols = 5 .FixedCols = 1: .FixedRows = 0 End WithEnd SubPrivate Sub Command1_Click() '步驟1先加入資料Dim S$, I%, J%With MSFlexGrid1 .Visible = False: DoEvents '隱藏起來會快一點 Randomize Timer For I = 0 To 7 S = I + 1 For J = 0 To 3 S = S & vbTab & Chr(Int(Rnd * (90 - 65 + 1) + 65)) '每列資料以VbTab隔開 Next .AddItem S, I '利用AddItem加入資料 Next .TextMatrix(8, 0) = I + 1 '利用TextMatrix來輸入資料 For I = 1 To 4 .TextMatrix(8, I) = Chr(Int(Rnd * (90 - 65 + 1) + 65)) Next .Visible = TrueEnd With'不管是TextMatrix或AddItem加入資料因不必改變Row,Col速度上會加快End SubPrivate Sub Command2_Click() '步驟2利用Clip來儲存 Dim S$ With MSFlexGrid1 .Visible = False: DoEvents '先選擇要儲存的區域 .Row = 0: .Col = 0 .RowSel = .Rows - 1: .ColSel = .Cols - 1 Open "C:\Test.txt" For Output As #1 Print #1, Replace$(.Clip, vbCr, vbCrLf) '把VbCr改成VbCrlf便於觀看(可不改) Close #1 .Rows = 1: .Clear : .Col = 1: .Visible = True End WithEnd SubPrivate Sub Command3_Click() '步驟3利用Clip來讀取 Dim S$, A() As Byte '讀檔 ReDim A(FileLen("C:\Test.txt") - 1) Open "C:\Test.txt" For Binary As #1 Get #1, , A Close #1 '轉成vbUnicode,再把VbCrlf改成VbCr(若儲存時有改的話) S = Replace$(StrConv(A, vbUnicode), vbCrLf, vbCr) With MSFlexGrid1 .Visible = False: DoEvents '計算vbCr就可得知總列數 .Rows = UBound(Split(S, vbCr)) '選擇區域 .Row = 0: .Col = 0 .RowSel = .Rows - 1: .ColSel = .Cols - 1 .Clip = S '直接放資料 .Row = 0: .Col = 1: .Visible = True End WithEnd Sub
2006-07-16 18:24:56 補充:
'儲存還是利用TextMatrix比較快,抱歉XD
Private Sub Command2_Click()
Dim S$, I&, J%
2006-07-16 18:26:29 補充:
Open "C:\Test.txt" For Output As #1
With MSFlexGrid1
.Visible = False: DoEvents
For I = 0 To .Rows - 1
S = ""
For J = 0 To .Cols - 1
S = S & .TextMatrix(I, J) & vbTab
Next
Print #1, Left$(S, Len(S) - 1)
Next
2006-07-16 18:26:42 補充:
.Rows = 1: .Clear: .Visible = True
End With
Close #1
End Sub
2006-07-19 13:24:35 補充:
謝謝您的誇獎!當然如果問題在下會的話一定是知無不言,言無不盡!
2006-07-16 13:28:44 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
這有類似的
▶▶http://qoozoo2014091500.pixnet.net/blog
2014-09-24 01:40:21 · answer #2 · answered by Anonymous · 0⤊ 0⤋