|
Hi ,
ok Good questions:
let me give all answers :
let's say .csv file has 10K rows with column firstname,lastname,SSN,DOB.Now you are checking record by record and if you find firstname in bad format like numeric then count that row as bad row and then continue for next record and like that you can get how much are good records and how much are bad records and at end of the finding,you need to show to user that let's say 1000 records are bad and 9000 records are good out of 10,000 records.
This is how you have to report to user,so user can understand that what's problem with rest of records which are bad.
so user can change those records and then upload .csv file again.
I hope your now clear abt output.My main problem is to how to validate each and every rows (records).??If i will count one by one record then performance will be def. a issue.
regards,
Montu3377
|
|
|
|
|
montu3377 wrote: My main problem is to how to validate each and every rows (records).??If i will count one by one record then performance will be def. a issue.
You don't have a choice here. You have to go through this file, one record at a time, parse and validate each field. A RegEx expression would probably speed things up a little bit.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Dave Kreskowiak wrote: RegEx expression would probably speed things up a little bit.
And since you are going to use the same 4 or 5 RegEx you may want to consired precompile them.
montu3377 wrote: If i will count one by one record then performance will be def. a issue.
If the Business does not require a sync response, then fire a new thread to do the validation and then email a report when complete.
Just some other options.
You can only be young once. But you can always be immature.
- Dave Barry
|
|
|
|
|
I have a sub procedure that cleans a text file and write it to the console. Now I need some help appending that cleaned text file to its specified path. Here is the code that I have:
Private Sub CleanFile()
'Read file line by line
Dim file_name As String = "c:\Scanning files\lsprint_MO.txt"
Dim textline As String
If System.IO.File.Exists(file_name) = True Then
Dim objReader As New System.IO.StreamReader(file_name)
Do While objReader.Peek() - 1
textline = objReader.ReadLine() & vbNewLine
If textline.IndexOf("xxxxxxx") = 17 Then
Console.WriteLine(textline)
WriteFile(textline)
End If
Loop
End If
End Sub
Private Sub WriteFile(ByVal fname As String)
Dim oWrite As System.IO.StreamWriter
oWrite = IO.File.AppendText("c:\Scanning files\lsprint_MO.txt")
End Sub
When I run the program I get the following message:
The process cannot access the file 'c:\Scanning files\lsprint_MO.txt' because it is being used by another process.
Any ideas!
jds1207
|
|
|
|
|
Hi,
You are seeing this problem because the WriteFile() function is trying to open a stream to the same file opened in the CleanFile() function.
A quick and easy solution is to create a temporary output file and pass its filename into the WriteFile() function, then at the end of the CleanFile() function delete the original c:\Scanning files\lsprint_MO.txt file and then rename the temporary file...
You can get a temporary file name by:
dim Temp_file as String = my.Computer.FileSystem.GetTempFileName()
Then update WriteFile() function:
Private Sub WriteFile(ByVal OUTPUT_FILE as String, ByVal fname As String)
Dim oWrite As New System.IO.StreamWriter(OUTPUT_FILE)
oWrite = IO.File.AppendText(fname)
End Sub
At the end of CleanFile()
ObjReader.Close()
My.Computer.FileSystem.DeleteFile("c:\Scanning files\lsprint_MO.txt")
My.Computer.FileSystem.RenameFile(Temp_file, "c:\Scanning files\lsprint_MO.txt")
I hope this helps you out....
Regards
Martin
|
|
|
|
|
I got this error message: Illegal characters in path.
This line was highlighted:
Dim oWrite As New System.IO.StreamWriter(Output_File)
Also, am I on the right track?
Private Sub CleanFile()
'Read file line by line
Dim file_name As String = "c:\Scanning files\lsprint_MO.txt"
Dim textline As String
Dim Temp_file As String = My.Computer.FileSystem.GetTempFileName
If System.IO.File.Exists(file_name) = True Then
Dim objReader As New System.IO.StreamReader(file_name)
Do While objReader.Peek() - 1
textline = objReader.ReadLine() & vbNewLine
If textline.IndexOf("xxxxxxx") = 17 Then
'Console.WriteLine(textline)
WriteFile(textline, "c:\Scanning files\lsprint_MO.txt")
End If
Loop
objReader.Close()
My.Computer.FileSystem.DeleteFile("c:\Scanning files\lsprint_MO.txt")
My.Computer.FileSystem.RenameFile(Temp_file, "c:\Scanning files\lsprint_MO.txt")
End If
End Sub
Private Function WriteFile(ByVal Output_File As String, ByVal fname As String) As Boolean
Dim oWrite As New System.IO.StreamWriter(Output_File)
oWrite = IO.File.AppendText(fname)
Thanks!
jds1207
|
|
|
|
|
I notice you have got the parameters the wrong way round in your call to the WriteFile() function.... You are basically on the right track:
Here is my (slightly corrected) version of your WriteFile() function:
Private Sub WriteFile(ByVal Output_file as string, ByVal The_text as String)<br />
Dim oWrite As System.IO.StreamWriter<br />
<br />
If File.Exists(Output_file) = False Then<br />
' Create a new file to write to.<br />
oWrite = IO.File.CreateText(Output_file)<br />
Else<br />
' Append to file<br />
oWrite = IO.File.AppendText(Output_file)<br />
End If<br />
<br />
oWrite.WriteLine(The_text)<br />
oWrite.Flush()<br />
oWrite.Close()<br />
End Sub
And here is my version of your CleanFile() Function:
Private Sub CleanFile()<br />
'Read file line by line<br />
Dim file_name As String = "c:\Scanning files\lsprint_MO.txt"<br />
Dim Temp_file As String = My.Computer.FileSystem.GetTempFileName<br />
Dim textline As String<br />
<br />
If System.IO.File.Exists(file_name) = True Then<br />
Dim objReader As New System.IO.StreamReader(file_name)<br />
<br />
Do While objReader.Peek() - 1<br />
textline = objReader.ReadLine() & vbNewLine<br />
<br />
If textline.IndexOf("xxxxxxx") = 17 Then<br />
'Console.WriteLine(textline)<br />
WriteFile(Temp_file, textline)<br />
End If<br />
Loop<br />
objReader.Close()<br />
My.Computer.FileSystem.DeleteFile("c:\Scanning files\lsprint_MO.txt")<br />
My.Computer.FileSystem.RenameFile(Temp_file, "c:\Scanning files\lsprint_MO.txt")<br />
End If<br />
End Sub
One thing to note here, your original lsprint_MO.txt file will be overwritten by the process of running CleanFile()....
I hope this clears everything up for you....
Have fun and best regards,
Martin
|
|
|
|
|
I have the program running but it has been running for quiet a while now. Does it suppose to take this long to complete?
jds1207
|
|
|
|
|
I guess it will all depend on the size of the input file....
Perhaps a tweak to the "while" loop inside your cleanFile() function may help speed things up:
Private Sub CleanFile()<br />
'Read file line by line<br />
Dim file_name As String = "c:\Scanning files\lsprint_MO.txt"<br />
Dim Temp_file As String = My.Computer.FileSystem.GetTempFileName<br />
Dim textline As String<br />
<br />
If System.IO.File.Exists(file_name) = True Then<br />
Dim objReader As New System.IO.StreamReader(file_name)<br />
<br />
Do<br />
textline = String.Concat(objReader.ReadLine(), ControlChars.NewLine)<br />
<br />
If textline.IndexOf("xxxxxxx") = 17 Then WriteFile(Temp_file, textline)<br />
<br />
Loop Until textline Is Nothing<br />
<br />
objReader.Close()<br />
My.Computer.FileSystem.DeleteFile("c:\Scanning files\lsprint_MO.txt")<br />
My.Computer.FileSystem.RenameFile(Temp_file, "c:\Scanning files\lsprint_MO.txt")<br />
End If<br />
End Sub
Other than that, I'm affraid I have no ideas.....
Regards,
Martin
|
|
|
|
|
Hi all,
I am writing a VB.Net application that has a Command Prompt, which is running as a hidden process and I am redirecting the standard input/output from this process to my own user interface.
Everything seems to be working fine for regular DOS commands, for example; If I type "DIR" into my user-interface it displays exactly the same as if I'd typed DIR in to a command prompt window -- no problems there....
If I enter the name of an executable that is a windows based application, for example notepad.exe, then nothing seems to happen. If I then close my application the program I tried to start (i.e. Notepad) magically appears.
Having delved a bit deeper into this, I notice that after executing the notepad.exe command in my user interface, task manager is showing a "notepad.exe" process running but its not visible. I tried executing the dos command "start notepad.exe", and hey presto - the Notepad application starts up and is immediately visible.
Does anybody have any ideas as to why my hidden command prompt process is not making windows based applications immediately visible (unless they are proceeded by the "start" command)??
Thanks,
Martin
|
|
|
|
|
I can duplicate your problem, but I can't figure out why it's doing what it is. I think it has something to do with UseShellExecute , but you don't have much of a choice there considering you can't redirect the Streams without it being False .
The reason I say this is because you start the CMD process WITHOUT the shell. Any process that's launched from that CMD will ALSO not be launched from the Shell. The START executable gets around that by creating a new instance of the Shell and launching your command line through that (I THINK!). Funny thing is that you can't launch your hidden, or otherwise, CMD process with "START CMD.EXE" while UseShellExecute is False ! You also can't tell your successfully launched hidden CMD process to launch another CMD process using START ("CMD.EXE /K START CMD.EXE") without a Win32 error stopping you.
Sorry, it looks like there is no way around this that I can think of...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks a lot for having a look into my problem Dave,
You have provided a brilliant analysis, and I guess its a limitation I am going to have to live with....
Best regards,
Martin
|
|
|
|
|
Hello friends,
I have to create an application through which client can take backup of other machines on server machine(in LAN).
So primarily I want to create server application which can copy simple text file from client machines(in LAN) and save them on server machine.
I am new in .net and not getting how I should start?........I hope some experts can help me out.
Please help me to solve this situation it's urgent.....
Thanks,
Nagraj.
|
|
|
|
|
If you're familiar with how Windows networking works (folder sharing stuff), then this should be as easy as a file copy. But, it depends on how your network is setup. Domain or Workgroup? Are you going to be doing this as a service on the server? Are the workstation names available to your or are you going to have to type them in yourself? Do you have a single account that has access to all of the machines and gives you the permissions you need to get at the files you want to backup?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks Dave Kreskowiak for response,
I haven't worked on network project uptill now.
we have setup our network in workgroup and I have list of computer names in workgroup.
I hope u will explain something in detail.
Regards,
NAgraj
|
|
|
|
|
OK. You better start by learning Windows Networking first. A workgroup environment makes this MUCH more difficult because each machine in the workgroup keeps it's own list of user accounts that don't work on any other machine in the group.
Along with the list of machine names, you'll also need a username and password that gives you access to the files you want to backup, for EACH machine you want to copy files from!
Basically, you've going about this backwards. Don't write an application that pulls files down from each client. Turn it around and write an application that runs on each client and copies the files you need to the server. That way, your app can either depend on the user account that is logged in on each workstation to get access to the server, or the clients all use a single account on the server to login to it and copy the files.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I am trying to deserialize data into a class with a different name from that which was serialized. I believe the solution should be simple with a SerializationBinder but this doesn't seem to work if the class contains an enumerated member.
The simplified example below throws ArgumentException: "Object of type 'SerializationTest.NewClassToDeserialize' cannot be converted to type 'SerializationTest.OldClassToSerialize+eBar'."
-------------------
Module TestModule
Sub Main()
Dim tOldObject As New OldClassToSerialize
tOldObject.Foo = "My Data Value"
' Serialize object in old format
Dim tFilePath As String = Path.GetTempFileName()
Dim tBinaryWriteStrm As FileStream = File.Create(tFilePath)
Dim tBinaryWriteFomatter As New BinaryFormatter()
tBinaryWriteFomatter.Serialize(tBinaryWriteStrm, tOldObject)
tBinaryWriteStrm.Close()
' Deserialize object in new format
Dim tBinaryReadStrm As FileStream = File.OpenRead(tFilePath)
Dim tBinaryReadFomatter As New BinaryFormatter()
' Override binding to bind to NewClassToDerialize
tBinaryReadFomatter.Binder = New MyBinder
' Enum leads to ArgumentException
Dim tNewUntypedObject As Object = tBinaryReadFomatter.Deserialize(tBinaryReadStrm)
tBinaryReadStrm.Close()
Console.WriteLine(tNewUntypedObject.ToString)
Console.ReadLine()
End Sub
End Module
<Serializable()> Public Class OldClassToSerialize
Public Enum eBar
EnumVal1
EnumVal2
End Enum
Public Foo As String
Public Bar As eBar
End Class
<Serializable()> Public Class NewClassToDeserialize
Public Foo As String
Public Bar As OldClassToSerialize.eBar
End Class
Public Class MyBinder
Inherits SerializationBinder
Public Overrides Function BindToType(ByVal assemblyName As String, ByVal typeName As String) As System.Type
Return GetType(NewClassToDeserialize)
End Function
End Class
--------------------
It works fine if you comment out the member 'Bar'! Can anyone tell me how to handle the enum?
Many thanks,
Nick
|
|
|
|
|
I want to know how i can read/write from USB port in vb.net?
|
|
|
|
|
The USB port doesn't work like a serial or parallel port. You have to write your code to communicate with a specific device attached to the bus. How you do that depends entirely on the device your trying to do something with.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello
I am using VS 2005 CR 10.
I am using typed datasets to populate a report.
From my database I have 1 field called incidentDate, this is a smallTimeDate datatype.
My reports always displayes the correct date, but is followed by the time which is always 12:00. For example 18/12/2006 12:00 AM.
I don't want to display this time. I have tried setting the DateWindowsDefaultType in the report properties for that field. But this did not work.
Does anyone have any other ideas,
Thanks very much,
Steve
|
|
|
|
|
How about trying CStr({@Date},'MM/dd/yyyy')). I dont have the IDE with me so check for the correct syntax
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
Experience is like a comb that life gives you when you are bald - Navjot Singh Sidhu
|
|
|
|
|
<br />
Imports WMPLib<br />
' used to import the windows media player lib<br />
<br />
i can create a play list, play selected media and all that but i can't get it to select a play list from file and play it . i looked briefly at the "currentplaylist" and other IWMPPlaylist but they only have functions that adds to a play list. i just want to simply select a play list from a storage area of choice.
any help would be appreciated. thanks in advanced.
p.s. Bless up NCU and Bless up Jamaica.
c.smith
|
|
|
|
|
Hello,
I am writing a problem that populates a combo box. When the user selects something from the combo box, they will press a tab key that will take them to the next control. However, i have tried using the keydown, keyup, and keypress. All these capture the other keys but not the tab key.
Sample of what I am trying to do.
Private Sub ComboCompany_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboCompany.KeyDown<br />
If (e.KeyCode = Keys.Tab) Then<br />
MessageBox.Show(Keys.Tab)<br />
Else<br />
MessageBox.Show(e.KeyValue)<br />
End If<br />
End Sub<code><br />
<br />
many thanks for your help,<br />
<br />
Steve
|
|
|
|
|
What exactly are you trying to do?
You could use the leave event of the combobox to know when the focus moves from the combobox to any other control on the screen.
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
Experience is like a comb that life gives you when you are bald - Navjot Singh Sidhu
|
|
|
|
|
Yes the leave event would be a better option because a windows form intercepts the tab key. Leave event would be a hassle free workaround.
Posted by The ANZAC
|
|
|
|