最近都在作類似的題目,之前問過類似的現在問題是::一個combox一個textbox在combox點選txt檔,顯示在textbox做出來了,不過執行出了點問題程式碼如下,希望幫忙找一下錯誤,謝謝Private Sub Combo1_Click()If Combo1.Text = "" Then Exit Sub Dim A() As Byte, S$ S = App.Path & "\\aaa\\" & Combo1.Text & ".txt" ReDim A(FileLen(S) - 1) Open S For Binary As #1 Get #1, , A Close #1 Text1 = StrConv(A, vbUnicode)End SubPrivate Sub Form_Load()If Dir(App.Path & "\\aaa\\", vbDirectory) = "" Then Exit SubDoMyDirFile = DirIf MyDirFile <> ".." And MyDirFile <> "" ThenCombo1.AddItem MyDirFileEnd IfLoop Until MyDirFile = ""End Sub
2006-10-02 20:36:18 · 2 個解答 · 發問者 ? 5 in 電腦與網際網路 ➔ 程式設計
存成exe檔之後
點combox選完txt檔
要顯示在textbox之後他會跑去一個小視窗
說載入不進去之類的
2006-10-03 06:11:14 · update #1
'我把你的程式改了一下,你再跑跑看Dim MyPath As StringPrivate Sub Combo1_Click() If Combo1.Text = "" Then Exit Sub ReadTxt Combo1.TextEnd SubPrivate Sub File1_Click() If File1.FileName = "" Then Exit Sub ReadTxt File1.FileNameEnd SubPrivate Sub Form_Load() Dim MyDirFile As String '資料夾路徑 MyPath = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") & "aaa\" '檢查路徑是否存在 If Dir(MyPath, vbDirectory) = "" Then Exit Sub '尋找副檔名為Txt之檔案 MyDirFile = Dir(MyPath & "*.txt") Do Until MyDirFile = "" Combo1.AddItem MyDirFile MyDirFile = Dir Loop '其實不用這麼麻煩,VB本就有提供FileListBox物件,表單上置1個FileListBox,Name=File1 File1.Path = MyPath '資料夾路徑 File1.Pattern = "*.txt" '只顯示.Txt檔 File1.RefreshEnd Sub'讀檔,之前以Binary方式讀檔比較快,但若檔案非ANSI編碼時,在Text1 = StrConv(A, vbUnicode)就會出問題,故這次改成以Input方式來讀.Sub ReadTxt(ByVal nPath As String) nPath = MyPath & nPath If Dir(nPath) = "" Then Exit Sub Dim S$, K$, F& F = FreeFile Open nPath For Input As #F Do Until EOF(F) Line Input #F, S K = K & S & vbCrLf Loop Close #F Text1 = Left(K, Len(K) - 1)End Sub下載整個專案(只能放7天)
2006-10-03 08:42:05 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
請問你所說的"執行有點問題"是指發生了什麼情況而無法處理呢?
我執行了你的程式..看起來..
Private Sub Combo1_Click 裡的程式碼,應寫在 Private Sub Combo1_DropDown() 唷,不然好像無法觸動事件,提供你參考了。
2006-10-03 04:30:23 · answer #2 · answered by noniechang 3 · 0⤊ 0⤋