English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

程式碼如下
Dim Changed As Boolean

Private Sub Form_Resize()
Text1.Left = 0
Text1.Top = 0
Text1.Width = ScaleWidth
Text1.Height = ScaleHeight
End Sub


Private Sub SaveFile(ByVal filename As String)
Dim fs As New FileSystemObject
Dim txtf As TextStream

Set txtf = fs.CreateTextFile(filename, True)
txtf.Write Text1.Text
txtf.Close
Changed = False
End Sub

Private Function ShowDialogThenSaveFile() As Boolean
ShowDialogThenSaveFile = True
On Error Resume Next
With CommonDialog1
.CancelError = True
If Len(.InitDir) = 0 Then .InitDir = App.Path
.DialogTitle = \"儲存文字檔\"
.Filter = \"文字檔(*.txt)|*.txt|所有檔案(*.*)|*.*\"
.ShowSave
If Err.Number = cdlCancel Then
ShowDialogThenSaveFile = False
Else
SaveFile .filename
End If
End With
End Function

Private Sub mSave_Click()
If Len(CommonDialog1.filename) > 0 Then
SaveFile CommonDialog1.filename
Else
ShowDialogThenSaveFile
End If
End Sub

Private Sub mSaveAs_Click()
ShowDialogThenSaveFile
End Sub



Private Sub mend_Click()
End
End Sub

Private Sub mNew_Click()
If Changed = True Then
If QuerySaveFile = False Then Exit Sub
End If
Text1.Text = \"\"
Changed = False
CommonDialog1.filename = \"\"
End Sub

Private Sub mOpen_Click()
Dim S As String, f As Integer
If Changed = True Then
If QuerySaveFile = False Then Exit Sub
End If
On Error Resume Next
With CommonDialog1
.CancelError = True
If Len(.InitDir) = 0 Then .InitDir = App.Path
.DialogTitle = \"開啟文字檔\"
.Filter = \"文字檔(*.txt)|*.txt|所有檔案(*.*)|*.*\"
.ShowOpen
If Err.Number <> cdlCancel Then
Dim fs As New FileSystemObject
Dim txtf As TextStream

Set txtf = fs.OpenTextFile(.filename, ForReading)
Text1.Text = txtf.ReadAll
txtf.Close
Changed = False
End If
End With
End Sub

Private Sub Text1_Change()
Changed = True
End Sub
如題~~我只會用readall 總之拜託了!!!

2006-04-26 19:55:41 · 2 個解答 · 發問者 丞博 1 in 電腦與網際網路 程式設計

不好意思~~不知是我看不懂答案還是沒把題目說清楚!!
以這為說明:
"股票代號","股票名稱","收盤價","漲跌","最高價","最低價","成交量"
"0001","鴻運",18.70,-0.30,18.80,18.60,3550
"0002","福元",24.20,-0.50,24.60,24.20,11801
"0003","成長",24.90,-0.10,25.00,24.90,177
"0004","國民",21.30,-0.40,21.50,21.10,1738
另如我想要股票名稱的資料,或是收盤價的資料
只要其中單一行的資料就行了!!!

2006-04-27 16:15:25 · update #1

2 個解答

Set txtf = fs.OpenTextFile(.filename, ForReading)'ReadAll是讀取全部,ReadLine是讀取1行Do Until txtf.AtEndOfStream '若檔案已到結尾就離開迴圈   S = S & txtf.ReadLine & vbCrLf '1次讀1行LoopText1.Text = Stxtf.Close

2006-04-30 18:33:52 補充:
'只讀取股票名稱的資料Set txtf = fs.OpenTextFile(.FileName, ForReading)Do Until txtf.AtEndOfStream  S = Split(txtf.ReadLine, ",")  Text1.Text = Text1.Text & S(1) & vbCrLfLooptxtf.Close

2006-04-27 08:04:45 · answer #1 · answered by W.J.S. 7 · 0 0

open "A.txt" for input as #1
do
line input #1, OneLineText
loop until eof(1)
close #1
把檔案的一行讀入變數OneLineText

2006-04-27 05:48:20 · answer #2 · answered by berniebernietw 3 · 0 0

fedest.com, questions and answers