[RESOLVED] Parsing/Copying Strings
I built a helpdesk version of a program that would parse out certain information. Now, I am trying to automate it using the same code under a load event and I just can't get it to work. The original code was worked on by .paul. and he did a great job! :bigyello: The original forum is located here.
My Code:
vb.net Code:
Imports System.Text
Imports Microsoft.VisualBasic.FileIO
Imports System.Collections.ObjectModel
Public Class SecurityParser
Private Sub SecurityParser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Fill textbox1 with the original DEBOUT.TXT
'
Dim DeboutTXT As String = My.Settings.DeboutLocation
Dim fileContents As String
fileContents = My.Computer.FileSystem.ReadAllText(DeboutTXT)
TextBox1.Text = fileContents
' Search the contents of the textbox for the keywords
'
Dim lines As New List(Of String)(IO.File.ReadAllLines(DeboutTXT))
Dim matches = (From line In lines Where line.contains("Login") Or line.contains("Username") _
Or line.contains("Logout") Or line.contians("rpt") Or line.contains("USERNAME") _
Select "LINE " & lines.IndexOf(line) & ": " & line).toarray
If matches Is Nothing OrElse matches.length = 0 Then MsgBox("Nothing found") : Return
TextBox2.Lines = matches
' Create the audited file, will be moved by the form1.load event in the background worker
'
My.Computer.FileSystem.WriteAllText(My.Settings.XFER_Dir & "AM-AUDIT.TXT", TextBox2.Text, False)
End Sub
End Class
I am getting one error, which is:
Code:
Error 1 Expression of type 'System.Collections.Generic.List(Of String)' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider. C:\Documents and Settings\mbutler\My Documents\Visual Studio 2008\Projects\Briad Backup\Briad Backup\SecurityParser.vb 20 37 Briad Backup
I did not need to call any references for the other program and I am just wondering if I am missing something. Any help is much appreciated.
Re: Parsing/Copying Strings
Ignore, I got that wrong :(
Re: Parsing/Copying Strings
if vs says it needs a reference, it won't work without it.
some references are added as default depending on the target framework + if you compare references in the 2 projects you'll probably see the problem
1 Attachment(s)
Re: Parsing/Copying Strings
.paul.,
I have checked all the references. I had to change the default framework from 3.0 to 3.5. I now match the other program, but the issue persists. I have attached an image.
Code:
Old References -> References from the other program
New References -> References on the new program
Re: Parsing/Copying Strings
Just to be sure, don't you need to Import System.LINQ in order to perform Queries on your objects ?
I saw you have System.XML.Linq in your references but... I don't know... I always import it to be sure.
Re: Parsing/Copying Strings
LINQ is part of the 3.5FW... so it won't work against the 3.0FW.
-tg
Re: Parsing/Copying Strings
you're missing a system.core reference there too
Re: Parsing/Copying Strings
Quote:
Originally Posted by
stlaural
Just to be sure, don't you need to Import System.LINQ in order to perform Queries on your objects ?
I saw you have System.XML.Linq in your references but... I don't know... I always import it to be sure.
I do not have a System.LINQ reference available. It goes straight from System.IO.Log to System.Management. Why would the other program work without this reference if it were required?
Re: Parsing/Copying Strings
Quote:
Originally Posted by
.paul.
you're missing a system.core reference there too
Adding System.Core could not be added. This component is already automatically referenced by the build system.
Re: Parsing/Copying Strings
Interesting. I added the reference to System.LINQ to the page itself:
And it works now. Thanks stlaural!
Re: Parsing/Copying Strings
Edit : Took me too long to write my answer, you already solved your problem !
As techgnome said :
Quote:
Originally Posted by
techgnome
LINQ is part of the 3.5FW... so it won't work against the 3.0FW.
-tg
Are you sure you are using Framework 3.5 ?
1- to check select Project menu
2- at the bottom should be "Your Project Name" Properties..., Select it
3- in the Compile tab click on the button "Advanced Compile Options..."
4- At the bottom of the newly opened window there is a dropdown titled "Target framework"
Make sure .NET framework 2.5 is selected.
Then you should have access to the library System.LINQ