Private Sub Command1_Click() Open App.Path & "\" & "index.txt" For Output As #1 Write #1, Text1.Text Close #1 ' 关闭文件。 End Sub
唉~,晚了~!commondialog1.showsave if commondialog1.filename<>"" then Open commondialog1.filename For Output As #1 Write #1, Text1.Text Close #1 ' 关闭文件。 endif
Private Sub Command1_Click() CommonDialog1.ShowSave If CommonDialog1.FileName <> "" Then Open CommonDialog1.FileName For Output As #1 Write #1, Text1.Text Close #1 ' 关闭文件。 End If End SubPrivate Sub Command2_Click() CommonDialog1.ShowOpen If CommonDialog1.FileName <> "" Then Open CommonDialog1.FileName For Input As #1 Write #1, Text1.Text Close #1 ' 关闭文件。 End If End SubPrivate Sub Form_Load() Form1.CommonDialog1.Flags = 2 Form1.CommonDialog1.Filter = "文本文件|*.bat;*.txt" End Sub 我的另一个按钮是打开某个文件,那么COMMAND2这样做法是错误的,我该怎么改正呢,谢谢了,各位热心的朋友!
Private Sub Command1_Click() Dim s As String CommonDialog1.ShowOpen If CommonDialog1.FileName <> "" Then Open CommonDialog1.FileName For Input As #1 Do While Not EOF(1) ' 循环至文件尾。 Input #1, s ' 将数据读入变量。 Text1.Text = s + Text1.Text MsgBox s Loop Close #1 ' 关闭文件。 End If End Sub
' '写TEXT文件 '函数:WritTextFile '参数:FileName 目标文件名.WritStr 写到目标的字符串. '返回值:成功 返回文件内容.失败 返回"" '注:如果同名,目标字符串将覆盖原文件内容. Public Function WritTextFile(Filename As String, WritStr As String) As Boolean '/保存文件 Dim FileID As Long, ConTents As String Dim A As Long, B As Long
On Error Resume Next
FileID = FreeFile Open Filename For Output As #FileID Print #FileID, WritStr Close #FileID WritTextFile = (Err.Number = 0) Err.Clear End Function
头都破了~~!有3颗星星在上面转圈~好晕...换行的话连上一个vbCrlf就可以了! Text1.Text = s + Text1.Text 这句子也好像倒过来了!Text1.Text = Text1.Text & vbCrlf & s '就可以了!
Private Sub Command1_Click() Open "f:\b.bat" For Output As #1 Print #1, Text1.Text Close #1 Shell "cmd.exe /c F:\b.bat" End SubPrivate Sub Command2_Click() Dim s As String CommonDialog1.ShowOpen If CommonDialog1.FileName <> "" Then Open CommonDialog1.FileName For Input As #1 Do While Not EOF(1) ' 循环至文件尾。 Input #1, s ' 将数据读入变量。 Text1.Text = Text1.Text & vbCrLf & s Loop Close #1 ' 关闭文件。 End If End Sub还是不好,这样下来,换行是换了,可是输出的时候,就自己先空了一行,然后在输入下面的信息啊,你们看看,这个先空一行的怎么去处理掉,谢谢,就这个问题了!
我倒~~失忆了!换成这样吧! Text1.SelText = s & vbCrLf或加多一个变量...在打开的文件比较大时~这样做会更好! Private Sub Command2_Click() Dim s As String,x as string CommonDialog1.ShowOpen If CommonDialog1.FileName <> "" Then Open CommonDialog1.FileName For Input As #1 Do While Not EOF(1) ' 循环至文件尾。 Input #1, s ' 将数据读入变量。 x = s & vbcrlf Loop text1.text = x Close #1 ' 关闭文件。 End If End Sub
我按楼上的做了。。怎么提示CommonDialog1 没定义呢。。要怎么做呢?
晕哦,天啊,COMMONDIALOG是个控件的,你没加载,当然了,你比我更晕,完蛋了,都,哎!!!
呵呵,判断一下 Private Sub Command1_Click() Dim s As String CommonDialog1.ShowOpen If CommonDialog1.FileName <> "" Then Open CommonDialog1.FileName For Input As #1 Do While Not EOF(1) ' 循环至文件尾。 Input #1, s ' 将数据读入变量。 Text1.Text = IIf(Text1.Text = "", s, Text1.Text & vbCrLf & s) MsgBox s Loop Close #1 ' 关闭文件。 End If End Sub
漏打了个x~直接在论坛上写的~没试过!呵呵~Sorry~下面的可以了~试过了!哈哈!Private Sub Command2_Click() Dim s As String,x as string CommonDialog1.ShowOpen If CommonDialog1.FileName <> "" Then Open CommonDialog1.FileName For Input As #1 Do While Not EOF(1) ' 循环至文件尾。 Input #1, s ' 将数据读入变量。 x = x & s & vbCrLf '这里添加一个x就好了~呵呵! Loop text1.text = x Close #1 ' 关闭文件。 End If End Sub
Open App.Path & "\" & "index.txt" For Output As #1
Write #1, Text1.Text
Close #1 ' 关闭文件。
End Sub
if commondialog1.filename<>"" then
Open commondialog1.filename For Output As #1
Write #1, Text1.Text
Close #1 ' 关闭文件。
endif
ofn.lStructSize=sizeof(OPENFILENAME);
....//OPENFILENAME 结构中一些设置,可以看看MSDN.
ofn.Flags="OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
调用函数GetSaveFileName(&ofn);就可以打开"另存为"对话框。
CommonDialog1.ShowSave
If CommonDialog1.FileName <> "" Then
Open CommonDialog1.FileName For Output As #1
Write #1, Text1.Text
Close #1 ' 关闭文件。
End If
End SubPrivate Sub Command2_Click()
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Open CommonDialog1.FileName For Input As #1
Write #1, Text1.Text
Close #1 ' 关闭文件。
End If
End SubPrivate Sub Form_Load()
Form1.CommonDialog1.Flags = 2
Form1.CommonDialog1.Filter = "文本文件|*.bat;*.txt"
End Sub
我的另一个按钮是打开某个文件,那么COMMAND2这样做法是错误的,我该怎么改正呢,谢谢了,各位热心的朋友!
Dim s As String
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1) ' 循环至文件尾。
Input #1, s ' 将数据读入变量。
Text1.Text = s + Text1.Text
MsgBox s
Loop
Close #1 ' 关闭文件。
End If
End Sub
'写TEXT文件
'函数:WritTextFile
'参数:FileName 目标文件名.WritStr 写到目标的字符串.
'返回值:成功 返回文件内容.失败 返回""
'注:如果同名,目标字符串将覆盖原文件内容.
Public Function WritTextFile(Filename As String, WritStr As String) As Boolean
'/保存文件
Dim FileID As Long, ConTents As String
Dim A As Long, B As Long
On Error Resume Next
FileID = FreeFile
Open Filename For Output As #FileID
Print #FileID, WritStr
Close #FileID
WritTextFile = (Err.Number = 0)
Err.Clear
End Function
B。BAT里面是
cdping www.163.com那么输出怎么不自己换行,而且变成
ping www.163.comcd
这样了啊,乱了啊,我该怎么办啊!
Text1.Text = s + Text1.Text 这句子也好像倒过来了!Text1.Text = Text1.Text & vbCrlf & s '就可以了!
Private Sub Command1_Click()
Open "f:\b.bat" For Output As #1
Print #1, Text1.Text
Close #1
Shell "cmd.exe /c F:\b.bat"
End SubPrivate Sub Command2_Click()
Dim s As String
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1) ' 循环至文件尾。
Input #1, s ' 将数据读入变量。
Text1.Text = Text1.Text & vbCrLf & s
Loop
Close #1 ' 关闭文件。
End If
End Sub还是不好,这样下来,换行是换了,可是输出的时候,就自己先空了一行,然后在输入下面的信息啊,你们看看,这个先空一行的怎么去处理掉,谢谢,就这个问题了!
Text1.SelText = s & vbCrLf或加多一个变量...在打开的文件比较大时~这样做会更好!
Private Sub Command2_Click()
Dim s As String,x as string
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1) ' 循环至文件尾。
Input #1, s ' 将数据读入变量。
x = s & vbcrlf
Loop
text1.text = x
Close #1 ' 关闭文件。
End If
End Sub
Private Sub Command1_Click()
Dim s As String
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1) ' 循环至文件尾。
Input #1, s ' 将数据读入变量。
Text1.Text = IIf(Text1.Text = "", s, Text1.Text & vbCrLf & s)
MsgBox s
Loop
Close #1 ' 关闭文件。
End If
End Sub
Dim s As String,x as string
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1) ' 循环至文件尾。
Input #1, s ' 将数据读入变量。
x = x & s & vbCrLf '这里添加一个x就好了~呵呵!
Loop
text1.text = x
Close #1 ' 关闭文件。
End If
End Sub