|
I did point this out when I said that your code relied on two assumptions (one being that similar lines are together when the example shows this is not the case).
There's a problem in the logic you describe since you would need to wind the input file back to line 4. Can't be done without closing and reopening the file and reading through from the start ignoring lines until you get to line 4.
You need to read the file into a list: either sorting it after reading the whole file, or checking for matches as each line is read.
I suppose you could use your logic if you read the file into an array of strings and dealt with it that way.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
|
It's easy to read a file into an array (use ReadAllLines ) and to sort the array (use Array.Sort(yourArray) ). But that's where your problems start. This simple approach won't work with your data. You would need to use Array.Sort(yourArray, yourComparer) and doing this will be messy. You have to define a class that implements IComparer (i.e. implements the Compare method). You then have to loop through the array and write it out while dropping duplicates. There is a problem with this approach if the output lines should be in the same order as the input (unless your compare method is clever enough to maintain order).
An alternative is to create a List(Of T) and populate the list as you read through the file. However, you can't use string for the T; you would have to define a suitable type.When each line is read in you can check if there's a match in the list. If there is you either ignore the line or update the created date field. When you have finished reading the file, you then loop through the list writing it to output.
There are other possible ways to solve the problem e.g. you could define a class that has a string property and overrides the Equals method to allow comparisons.
Given some of the problems you have raised (and what I infer about your knowledge of VB.NET), I think you are going to find this difficult.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Hi to All
I have a few doubts on creation of process to execute any exe/ppt/any file in VB.NET. Please clarify me
1) How to use waitforexit() methods. Its not working for me in some cases?
My code is..
dim p as new process
p.startInfo.filename=MyPath
p.start()
p.waitforexit()
Sometimes If I run a calc, (ie MyPath is either calc.exe or a path to a shortcut of calc)..It runs the calc and shows an error in p.waitforexit() saying something like "p has not assign any process"
2)Can we check for an process if it is alive? I want to check if explorer.exe is running?
3)Can we maximise and bring it to front of the all window, for a process which is running? (eg: I have a form which covers the desktop. I have a button(run calc) which runs calculator..Now after running if I click on the form,the calc goes back to my form...Now if I click the button(run calc),I dont want to open a new calc,...instead I want to bring the already running calc on top.)
Thnaks in advance
-----------------------------
I am a beginner
|
|
|
|
|
p.startInfo.filename=MyPath
p.start()
If (!p.HasExited && p.Responding) Then
p.waitforexit()
End If
himangshuS wrote: 2)Can we check for an process if it is alive?
Yes. Check out the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.hasexited.aspx">HasExited</a>[<a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.hasexited.aspx" target="_blank" title="New Window">^</a>] and the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.responding.aspx">Responding</a>[<a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.responding.aspx" target="_blank" title="New Window">^</a>] properties.
himangshuS wrote: 3)Can we maximise and bring it to front of the all window, for a process which is running?
Yes. You'll have to get the handle to the mainform, based on the proces-id. Then you can set the WindowState and you can BringToFront the Window
I are troll
|
|
|
|
|
thnaks for your reply..
About my first doubt,...fine I will execute your code and see. But Could you please tell me what could be the problem in the line p.waitforexit()...that happen only sometimes,spexially when I run calc.
About my second problem:: How do I check for the process explorer.exe? Could u please a sample code, Since I will have to get the process id for explorer.exe or something like that?
For the third one...Are you talking about the handle of my application window or the proicess window ie calc?...Also How will I get to know the exact process Id?..since if I can run calc more then one time...how will i get process id for each one?
thanks
-----------------------------
I am a beginner
|
|
|
|
|
himangshuS wrote: About my first doubt,...fine I will execute your code and see. But Could you please tell me what could be the problem in the line p.waitforexit()...that happen only sometimes,spexially when I run calc.
It may already have been terminated, or just too busy to proces incoming messages.
himangshuS wrote: About my second problem:: How do I check for the process explorer.exe? Could u please a sample code, Since I will have to get the process id for explorer.exe or something like that?
Use the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx">Process</a>[<a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx" target="_blank" title="New Window">^</a>] class to get a list of all running processes.
' Start Explorer.
Dim p As Process
p = Process.Start("explorer.exe")
MessageBox.Show(p.Id)
himangshuS wrote: since if I can run calc more then one time...how will i get process id for each one?
Well, you get an Id each time you start "calc.exe" through the Process class. Your best option would be to keep a list around of the processes that you started. I wouldn't close any of the processes that you didn't start yourself; the end-user might be really confused if his/hers calculator suddenly dissapears.
I are troll
|
|
|
|
|
You're calling WaitForExit before the process even has a chance to start. Starting a new process is a very expensive call. The Start method does not wait for the process to completely start before returning.
It's up to you to wait for the app to start, by calling p.WaitForInputIdle before you call the WaitForExit method.
himangshuS wrote: Now if I click the button(run calc),I dont want to open a new calc,...instead I want to bring the already running calc on top.)
Then you have to check to see if it's still running (the user may have closed it), relaunch it if needed, easily done using the Process class. If it's still running, then you can get the ProcessId from its Process object, than pass that to AppActivate to bring it to the front.
|
|
|
|
|
thanks
Could you please help me with the code since I have very less idea about the process class an all.
In order to maximise or bring the already running calc/any process to front
thanks
-----------------------------
I am a beginner
|
|
|
|
|
I'm not writing your code for you.
Check out the Process.GetProcessesByName method.
|
|
|
|
|
Dear all
i have this problem keeps coming often using inet control 12002 time out
can any body give me the solution .its very urgent...
i am using the inet control to download the data from remote server..
the main intention is to download the database rows from remote server to my local system which is in access database
plzzzzzzzzzzzzzzzzzzzzzzzzzzzzz help me
thanks in advance
|
|
|
|
|
Are you saying that you're trying to use an Access database on a remtoe machine, acrossed the Internet?? Since Access is a file based database, this is a very high security risk!
|
|
|
|
|
To add to Dave K's point. I have used Access over a company intranet and found the performance pretty poor even with dedicated links. Over the internet I'd think it's a non-starter.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
how to create codeing for search files in computer for using language for vb.net.
|
|
|
|
|
Simple:
Install visual studio
Create new project
Start coding.
More serious answer:
Look at the system.io namespace
system.io.file
system.io.directory
system.io.path
Without more information nobody can truly give you an answer.
|
|
|
|
|
Hi,
I would like to know if there is a possible way to set the folder name as the newly created file name??
I have a folder which contains n number of files.
I have appened all those files as single a new file.
Now I want to name that file with the name of the folder.
Any means to do it?
Thanks in advance
|
|
|
|
|
Check out FileInfo.Directory property. Might help you.
जय हिंद
|
|
|
|
|
Have you tried just creating the file with the same name as the folder in your program?
E.g. if input folder is C:\myStuff\myTextfiles\ then output file is C:\myStuff\myTextfiles i.e. no trailing \.
Don't know if it will work but worth a shot.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Hi David,
My input folder is got from the FolderBrowserDialog.
The input folder path is not hardcoded.
In that case how to manage?
|
|
|
|
|
Use SelectedPath property and extract string after last "\".
जय हिंद
|
|
|
|
|
In that case just try using the SelectedPath from the FBD for both input path and output file - IIRC FolderBrowserDialog returns path without the trailing \.
As I said don't know if it will work, but don't see why not (you can have a file and folder with same name in Windows).
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
I think this piece of code might help:
Dim test As String
'This will get the Folder name from the selected path.
test = FileIO.FileSystem.GetName(FolderBrowserDialog1.SelectedPath)
'So if you had a folder path of C:\Program Files\SomeFolder\Program1 selected the above command should 'display Program1
I hope this helps.
|
|
|
|
|
Hi all,
Is it possible to create our own FolderBrowserDialog???
I have created my own MsgBox.
Code:
Sub MyMessageBox1(ByVal strMessage As String, ByVal imgImage As Image)
Dim frmMsgBx As New Form
Dim pbxMsgImage As New PictureBox
Dim lblMsgText As New Label
Dim btnMsgOK As New Button
With frmMsgBx
.MinimizeBox = False
.MaximizeBox = False
.Width = 50
.Height = 20
.AutoSize = True
.BackColor = Color.MediumAquamarine
.Text = "Saved"
.StartPosition = FormStartPosition.CenterScreen
End With
With pbxMsgImage
.Parent = frmMsgBx
.Left = 12
.Top = 12
.Width = 50
.Height = 50
.Image = imgImage
.SizeMode = PictureBoxSizeMode.StretchImage
End With
With lblMsgText
.Parent = frmMsgBx
.Left = 100
.Top = 20
.Width = 300
.Height = 20
.Text = strMessage
.TextAlign = ContentAlignment.MiddleCenter
End With
With btnMsgOK
.Parent = frmMsgBx
.Left = 175
.Top = 45
.Width = 75
.Height = 23
.Text = "OK"
.DialogResult = DialogResult.OK
BackColor = Color.MediumAquamarine
End With
frmMsgBx.ShowDialog()
Button3.Enabled = False
End Sub
/pre>
In the same way is it possible to create a new FolderBrowserDialog???
Thanks in advance
|
|
|
|
|
Yes, you can create your own folder browser dialog.
जय हिंद
|
|
|
|
|
Within a VB6 form frmMain with a button that have the following click sub
Dim Ace As Object
Set Ace = CreateObject("Access.Application")
Ace.OpenCurrentDatabase "c:\test.mdb", False
Set Ace = Nothing
unload frmMain
The test.mdb opens perfectly but it is not full screen. How can i open it with full screen?
Thanks in anticipation.
|
|
|
|