嗨,这真的让我感到困惑,我确信它很简单,但我无法弄清楚它为什么会发生。
我正在阅读一个文本文件并找到一个 startpos 和 endpos 来提取数据。我提取的数据是 - “版本是 10.2.0.5.0”
我有价值,因为我可以将其通过 msgbox 输出。调试时,如果我将鼠标悬停在 OraContents 字符串上,它会显示“版本为 10.2.0.5.0”,这是正确的。
所以有一些 msgboxes 来测试将被删除的东西......
问题是当我尝试在此示例中像在主代码片段中一样将 OraContents 写入文件时.. 即使我为 OraContents 分配了一个值,它也会显示 Null 和错误 - 或者我尝试简单地说以下内容......
If OraContents = "version is 10.2.0.5.0" Then
MsgBox("Oracle found")
End If
再次忽略它只是跳过它的 If 语句,因为 OraContents 不匹配该值,但它是!
我错过了什么...:\
提前致谢。
我的代码..
Sub GetFiles()
Dim DirInfo As New DirectoryInfo(ProgramFiles & "Oracle\Inventory\logs")
For Each file As FileSystemInfo In DirInfo.GetFileSystemInfos()
Dim myFile = IO.Directory.GetFiles(ProgramFiles & "Oracle\Inventory\logs").OrderByDescending(Function(f) New FileInfo(f).LastWriteTime).First()
If InStr(file.FullName, "installActions") Then
MsgBox(myFile)
Dim testTxt As New StreamReader(myFile)
Dim allRead As String = testTxt.ReadToEnd()
testTxt.Close()
If InStr(allRead, "Oracle Universal Installer") Then
Dim OraContents As String
OraContents = allRead
Dim StartPos, EndPos As Integer
StartPos = OraContents.IndexOf("INFO: Oracle Universal Installer version is ")
EndPos = OraContents.IndexOf("INFO: Oracle Universal Installer version is ")
StartPos = StartPos + 32
EndPos = EndPos + 55
OraContents = OraContents.Substring(StartPos, EndPos - StartPos)
MsgBox(OraContents)
Test(OraContents) 'This is a check to make sure value is not Null..its not
System.IO.File.Create("c:\OracleVersion.txt")
Dim path As String = "c:\OracleVersion.txt"
Dim sw As StreamWriter
sw.WriteLine(OraContents)
sw.Close()
End If
MsgBox("Found")
Else
'MsgBox("Not Found")
End If
Next
End Sub