史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   VB6.0如何儲存TextBox裡的內容? (http://forum.slime.com.tw/thread249646.html)

chung1206 2009-06-25 10:37 PM

VB6.0如何儲存TextBox裡的內容?
 
各位先進們好,我在Form1表單裡做了一個button為另存新檔,但不知道要如何將TextBox的內容存起來,希望大大指教一二,謝謝。

程式碼如下:
Private Sub cmdsave_Click()
CommonDialog2.Filter = "All Files(*.*)"
CommonDialog2.FilterIndex = 2
CommonDialog2.ShowSave
End Sub

後來更改如下:
Private Sub cmdsave_Click()
F = FreeFile
Open "c:\data\hello.txt" For OutPut As #F
Print #F, Text2.Text
Close #F
End Sub

但我還是希望能向第一支程式一樣跳一個視窗出來讓我自己選擇要存在那裡,自己命名檔名。

mini 2009-06-26 02:28 PM

引用:

作者: chung1206 (文章 2169747)
各位先進們好,我在Form1表單裡做了一個button為另存新檔,但不知道要如何將TextBox的內容存起來,希望大大指教一二,謝謝。

後來更改如下:
Private Sub cmdsave_Click()
F = FreeFile
Open "c:\data\hello.txt" For OutPut As #F
Print #F, Text2.Text
Close #F
End Sub

但我還是希望能向第一支程式一樣跳一個視窗出來讓我自己選擇要存在那裡,自己命名檔名。

可以使用 Inputbox

Private Sub cmdsave_Click()
Dim sFileName As String

sFileName = InputBox("請輸入路徑+檔名", "存檔", "c:\data\hello.txt")
F = FreeFile
Open sFileName For OutPut As #F
Print #F, Text2.Text
Close #F
End Sub

再不然就要使用
CommonDialog

你只要把第一段與第二段修改結合一下就好了
語法:

    With CommonDialog1
        .DialogTitle = "選擇檔案"
        .Filter = "處理清單(*.fnl)|*.fnl"
        .ShowSave
        If Len(.filename) = 0 Then Exit Sub
        F = FreeFile
        Open .filename For OutPut As #F
        Print #F, Text2.Text
        Close #F
    End With


chung1206 2009-06-27 08:45 AM

引用:

作者: mini (文章 2170018)
可以使用 Inputbox

Private Sub cmdsave_Click()
Dim sFileName As String

sFileName = InputBox("請輸入路徑+檔名", "存檔", "c:\data\hello.txt")
F = FreeFile
Open sFileName For OutPut As #F
Print #F, Text2.Text
Close #F
End Sub

再不然就要使用
CommonDialog

你只要把第一段與第二段修改結合一下就好了
語法:

    With CommonDialog1
        .DialogTitle = "選擇檔案"
        .Filter = "處理清單(*.fnl)|*.fnl"
        .ShowSave
        If Len(.filename) = 0 Then Exit Sub
        F = FreeFile
        Open .filename For OutPut As #F
        Print #F, Text2.Text
        Close #F
    End With


感謝大大指教,我後來是用CommonDialog的方式,想請教一下大大有沒有這方面的
書可以推薦一下,我去書局找VB的書都沒有教這種的,只有教如何將另存新檔那個畫
面打開而已,這算小技巧嗎?

mini 2009-06-27 10:39 AM

很久沒買書了
現在都是網路搜尋... (要很有耐心就對了)


所有時間均為台北時間。現在的時間是 06:49 PM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1