继续前面的问题...... [英] Follow on to earlier question...

查看:71
本文介绍了继续前面的问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



之前被问到一个问题,因为我遇到了文件权限问题,试图将文件写到某个位置。 Mehdi Gholam提出了AppendAllText方法,这解决了写作问题,我遇到了其他问题并开始检查文件,做了大约10次运行,我希望10个日志,我看到两个。



Hi All,

Asked a question earlier on as I was having issues with File permissions trying write a file out to a location. Mehdi Gholam came up with the AppendAllText method this got around the writing issue I was having other issues and got around to check the file, having done around 10 runs I would expect to 10 logs I am seeing two.

'just until I come up with a way of not causing errors
    If ((VoltageTestBool = False) And (TimeKeepTestBool = False) And (LCDtestBool = False) And (RFtestBool = False) And (RFxtalBool = False) And (RFtestHighBool = False) And (QuiescentBool = False)) Then
        Result_Save += "Unit Passed," + DateAndTime.Now
        If (File.Exists(PathFilePass) = False) Then
            CreateText = Result_Save
            File.WriteAllText(PathFilePass, Result_Save + vbCrLf)
        End If
        If (File.Exists(PathFileFail) = True) Then
            MsgBox("here!!")
            File.AppendAllText(PathFilePass, Result_Save + vbCrLf)
        End If
    End If





例程的一部分显示在这里,我的印象是,如果文件存在,它会将文本添加到其他明智的创建它我已经改变了第二个'如果'到一个'elseif',看看是否是问题的原因。事实并非如此。任何人都可以解释为什么这似乎写两次相同的信息而不更新文件。



格伦



The part of the routine is shown here, I was under the impression that if the File existed it would add the text to it other wise create it I have changed the second 'if' to an 'elseif' to see if that was the cause of the problem. It isn't. Can anybody shed any light on why this appears to write same information twice and not update the file.

Glenn

推荐答案

从查看代码我注意到以下内容:



1)你们两个File.Exists()检查两个不同的文件,但是你们每个正在写入相同的位置。

2)因此,如果存在PathFilePass文件,它将覆盖位于PathFilePass中的任何现有文件,就好像存在PathFileFail文件一样,它会在其上附加文本。



我会按照If Then ElseIf然后结束如果我认为这些陈述是互斥的。



如果您想要所有输出,那么我会这样做:



From looking at your code I notice the following:

1) You two File.Exists() checks check for two different files, yet within each you are writing to the same location.
2) As a result, if the PathFilePass file exists it overrides any existing file located in "PathFilePass", where as if PathFileFail file exists then it appends text on to it.

I would do them as If Then ElseIf Then End If statements as I would have thought they would be mutually exclusive.

If you want all your outputs then I would do:

If (File.Exists(PathFilePass) = False) Then
                CreateText = Result_Save
                File.WriteAllText(PathFilePass, Result_Save + vbCrLf)
            Else
                File.AppendAllText(PathFilePass, Result_Save + vbCrLf)
            End If





这将导致包含所有输出的1个文件。

除非你在每次运行后删除文件。



支票说如果文件不存在,则创建它,否则附加到它。



This will result in 1 file that contains all of your output.
Unless you remove the file after each run through.

The check says "If the file is not there, then create it, else append to it.


这篇关于继续前面的问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆