选择输出TXT路径
输入的TXT形式为:每行都为X,Y,Z
选择导出TXT路径
导出的TXT形式为:每行都为X,Y,Z

解决方案 »

  1.   

    仅供参考:Set fs = CreateObject("Scripting.FileSystemObject"): _
    Set a = fs.CreateTextFile("c:\alltext.txt", True): _
    a.WriteLine(CStr(X)+","+CStr(Y)+","+CStr(Z)): _
    a.Close: _
    Set a=Nothing: _
    Set fs=Nothing: _
      

  2.   

    老师看看我这个,我这个读文件的地方怎么改
    Private Sub Command1_Click()With CommonDialog1
    .DialogTitle = "请选择文件"
    .Filter = "文本文件|*.txt"
    .CancelError = False
    .ShowOpen
    Text1.Text = .FileName
    End WithDim str As String
    Dim B As Double
    Dim L As Double
    Dim H As Double
    Dim canshu1 As Double
    Dim canshu2 As DoubleOpen "Filer" For Input As #1
    Do Until EOF(1)
    Line Input #1, str
    canshu1 = InStr(str, ",")
    B = Mid(str, 1, x1 - 1)
    canshu2 = InStr(x1 + 1, str, ",")
    L = Mid(str, x1 + 1, x2 - x1 - 1)
    H = Mid(str, x2 + 1)
    Loop
    Close #1
      

  3.   

    老师,我这个上边可能没有说明白
    1.通过Command1选择打开TXT文件路径
    2.然后读取所选的TXT文件(格式每行都是X,Y,Z)
    3.然后将每行的XYZ作为一组数据进行函数计算
    4.通过Command2选择保存TXT文件路径
    5.保存的格式同上
     
    小白用的是VB6.0
      

  4.   

    1. 使用CommonDialog时,把 CancelError属性赋值为 False的,9成以上的人是小白;
      把 CancelError设置成False之后,在“后续处理”中又不进行返回值判断的,100%是小白!
      如果把CancelError设置成False,在“对话框”返回之后,一定要判断 FileName属性值是否为空串!
      建议楼主看一下本论坛中最近的一个帖子:
      http://bbs.csdn.net/topics/3921643002. 你的“打开文件”语句写错!
      Open "Filer" For Input As #1 结果是“打开‘当前目录’中文件名为Filer的文件”。
      这个“被打开的文件”,跟之前的公共对话框返回结果没有任何直接关联;
      由于是“Input”模式打开文件,文件不存在时还会引起运行时错误。
      应该是 Open CommonDialog.FileName For Input As #13. 如果读取的文件数据,能够保证“格式正确、规范”,
      那么“拆分数据”就用不着那么多Instr、Mid之类的函数来处理。
      dim arrData() as string
      . . . . . 
      Open . . . . . . 
      Do
        line Input #1, str
        if("" = str) Then Exit Do
        arrData = Split(str, ",")
        . . . . . . . .
      这个时候,arrData(0)到arrData(2),就是每一行中对应的X、Y、Z的“字符串数据”值了。
    暂时不想再说了…………自己好好修改一下代码吧。
      

  5.   

    CancelError = False 时,仅仅判断文件名属性是否为空还不够。还需要在 ShowOpen 之前,将 FileName 属性设置为空串。否则上次选定的文件名会在下次取消的操作中输出。试一下就知道:
    Private Sub Command1_Click()
        With CommonDialog1
            '.FileName = ""
            .ShowOpen
            MsgBox .FileName
        End With
    End Sub第一次选定文件,第二次单击取消按钮。
      

  6.   

    居然有这事?
    不过我是从来不用 CancelError = False 的,即使用CancelError = False,遇到问题时也能发现。并且我自己的程序中,可能不会再使用这个控件了,用的是API封装接口函数。