|
Hi Dave,
AFAIK a Flush() is implied by a Close(), so it makes no sense to explicitly Flush()
just before a Close(). The only time Flush() is useful is when you don't intend
to Close() but instead just want to make sure everything up till then is actually
written to the file before you continue.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I try to write to file on network
Try
swship = New StreamWriter(shipFile, True)
swship.WriteLine(frmShip.cmbobxLocation.Text + "," + frmShip.txtbxScanID.Text + "," + frmShip.cmbobxBuyer.Text + "," + dt.ToString("d"))
swship.Close()
Catch ex As Exception
writeLocal()
End Try
WriteLocal:
Try
Dim swshipCatch As StreamWriter = New StreamWriter(localShipFile, True)
swshipCatch.WriteLine(frmShip.cmbobxLocation.Text + "," + frmShip.txtbxScanID.Text + "," + frmShip.cmbobxBuyer.Text + "," + "," + dt.ToString("d"))
swshipCatch.Flush()
swshipCatch.Close()
Catch ex As Exception
MessageBox.Show("writeLocal failed")
End Try
The above all works Fine.
The Below is when I attempt to access the localShipFile
Try
'SHIP
frmsr = New StreamReader("program files\steidingerfoodsce\localship.txt")
frmsw = New StreamWriter("\\lit3\device\ship.txt", True)
Do While frmsr.Peek() >= 0
frmsw.WriteLine(frmsr.ReadLine())
Loop
frmsr.Close()
frmsw.Close()
file.ReWriteSHIPFile() This is where it fails!!!
MessageBox.Show("SHip done")
Catch ex As Exception
MessageBox.Show(ex.ToString)
MessageBox.Show("Network connection not established")
End Try ReWriteSHIPFIle()
Public Sub ReWriteSHIPFile()
dim swship as streamwriter = New StreamWriter(localShipFile, False) ----It fails when this line executes.
swship.Write("")
swship.Close()
End Sub
modified on Monday, March 24, 2008 4:20 PM
|
|
|
|
|
Cory Kimble wrote: frmsr = New StreamReader("program files\steidingerfoodsce\localship.txt")
You're really using a hard-coded path that assumes the current directory is C:\ ?? Change this to use a fully qualified path built from known sources, such as Application.StartupPath , the System.Io.Path class, and other methods of determining the true path to well-known folders.
|
|
|
|
|
Hi Cory,
if it still does not work, just show us the code with all the opens, writes,
flushes, closes, disposes, what have you.
BTW: please use PRE tags (not CODE tags) for multi-line code snippets; they
preserve formatting such as indentation, much easier to read.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I try to write to file on network
Try
swship = New StreamWriter(shipFile, True)
swship.WriteLine(frmShip.cmbobxLocation.Text + "," + frmShip.txtbxScanID.Text + "," + frmShip.cmbobxBuyer.Text + "," + dt.ToString("d"))
swship.Close()
Catch ex As Exception
writeLocal()
End Try
WriteLocal:
Try
Dim swshipCatch As StreamWriter = New StreamWriter(localShipFile, True)
swshipCatch.WriteLine(frmShip.cmbobxLocation.Text + "," + frmShip.txtbxScanID.Text + "," + frmShip.cmbobxBuyer.Text + "," + "," + dt.ToString("d"))
swshipCatch.Flush()
swshipCatch.Close()
Catch ex As Exception
MessageBox.Show("writeLocal failed")
End Try
The above all works Fine.
The Below is when I attempt to access the localShipFile
Try
'SHIP
frmsr = New StreamReader("program files\steidingerfoodsce\localship.txt")
frmsw = New StreamWriter("\\lit3\device\ship.txt", True)
Do While frmsr.Peek() >= 0
frmsw.WriteLine(frmsr.ReadLine())
Loop
frmsr.Close()
frmsw.Close()
file.ReWriteSHIPFile() This is where it fails!!!
MessageBox.Show("SHip done")
Catch ex As Exception
MessageBox.Show(ex.ToString)
MessageBox.Show("Network connection not established")
End Try
ReWriteSHIPFIle()
Public Sub ReWriteSHIPFile()
dim swship as streamwriter = New StreamWriter(localShipFile, False) ----It fails when this line executes.
swship.Write("")
swship.Close()
End Sub
|
|
|
|
|
Cory Kimble wrote: Try 'SHIP frmsr = New StreamReader("program files\steidingerfoodsce\localship.txt")
You're really using a hard-coded path that assumes the current directory is C:\?? Change this to use a fully qualified path built from known sources, such as Application.StartupPath, the System.Io.Path class, and other methods of determining the true path to well-known folders.
|
|
|
|
|
Does Application.StartPath work in .net compact framework?
|
|
|
|
|
Cory Kimble wrote: Does Application.StartPath work in .net compact framework
Nope, not supported. You can find out what is and isn't supported in the .NET Framework documentation. Everything with a small phone-looking icon next to it is supported by the Compact framework. Click[^]
|
|
|
|
|
Hi Cory,
Your code is not very clear; here are my assumptions:
1. the files refered to in the lines frmsr = New StreamReader("program files\steidingerfoodsce\localship.txt")
and dim swship as streamwriter = New StreamWriter(localShipFile, False)
are the same
2. sub ReWriteSHIPFile intends to delete the original file.
Under those assumptions I see two potential problems:
1. you do close the streams frmsr (and frmsw) but you fail to dispose of them, although the
documentation says one should dispose of streams. (In fact one should dispose of any class instance
that has a public dispose method). Failing to do so is likely to have negative effects, in this
case I expect the underlying file system does not get cleaned up until the Finalize method is
executed (either by calling dispose explicitly, or by forcing a garbage collection, which happens
to occur when you minimize your form).
2. other processes may have the same file temporarily open (without you being aware); that happens
for fresh files when you have disk indexing enabled, or a gready antivirus program.
in these cases, you should attempt say 5 times in a loop, with 1 second intervals to solve almost
all of it.
Further remarks:
1.
you should avoid similar lines of code, they will lead to mistakes in the end (when you change one
and forget to change the other). Example: swship.WriteLine(frmShip.cmbobxLocation.Text + "," + frmShip.txtbxScanID.Text + "," + frmShip.cmbobxBuyer.Text + "," + dt.ToString("d"))
Solution: calculate the text line once, and (re)use it where ever you need it.
2.
you should avoid magic constants in your code; here "program files\steidingerfoodsce\localship.txt"
should be defined once, at the start of your program, in the initialization code, not in the middle of some
method. And I suspect you already have the variable localShipFile to point to it, so use it consistently.
3.
not sure you should store application data files under "program files". Some Windows versions, and/or some
installations won't let your app write anything there.
4.
I don't like the catch blocks that catch an exception and then ignore it, i.e. only the change-in-flow is used,
not the actual exception. On the other hand, MessageBox.Show(ex.ToString) is excellent; most
programmers use Message or so and miss most of the exception text...
5.
the sequence Flush() followed by Close() is overkill; AFAIK every Close() implies a Flush(), flush is useful
only if you do not intend to close right away but want to make sure the data so far got out to disk anyway.
6.
If the aim of ReWriteSHIPFile() is to delete a possibly existing file, there are better ways to do that.
And remember trying 5 times with 1 sec intervals (as Windows Explorer does, but no single API function offers).
Regards,
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Thank you so much for your time and comments.
|
|
|
|
|
I have searched the command for launching EXCEL.EXE with an existed .xls file without any success.
Can someone help me?
Thank in-advanced
|
|
|
|
|
Launch the ".xls" file itself. If Excel is installed, it'll launch and open the file, just like you double-clicked the file yourself.
|
|
|
|
|
Hi DAve,
I am sorry that I did not post the question clearly, what I meant was a valid command code in VB.net source codes in order to execute EXCEL.exe to open an existed .xls file (I do have EXCEL.exe available in my computer)
Anyhelp?
Thanks
|
|
|
|
|
You can find the documentation on the Process class here[^], along with examples on it's use.
|
|
|
|
|
Hi Dave,
Thank for the link, I am able to do what I posted
Thank for help
|
|
|
|
|
i create an update page for my assignment
when i click my update button success msg box appeared
but when i refresh the updated page..only few fields updated
the fields come from 2 different classes
i use datagrid to display the data
|
|
|
|
|
This is great and all, but you haven't saiid anything about the problem you're having, any error messages, what your code looks like, ... nothing anyone can use to help you narrow down the problem.
|
|
|
|
|
**my update statement in my oracle em package
**my update button code
Dim applyprogram As BLL.CApplyProgram = New BLL.CApplyProgram
Dim loanapplication As BLL.CLoanApplication = New BLL.CLoanApplication
applyprogram.ApplyStreamID = Viewstate("APPLYSTREAMID")
applyprogram.laCountryID = ddlCountry.SelectedItem.Value
applyprogram.laFieldID = ddlStudyFields.SelectedItem.Value
applyprogram.laInstituteID = ddlInstitute.SelectedItem.Value
applyprogram.laStreamID = ddlStream.SelectedItem.Value
applyprogram.laProgramID = ddlProgram.SelectedItem.Value
loanapplication.APPID = ViewState("APPID")
loanapplication.LACPROGID = ddlProgram.SelectedItem.Value
loanapplication.LACCOUNTRYID = ddlCountry.SelectedItem.Value
loanapplication.LACSTREAMID = ddlStream.SelectedItem.Value
loanapplication.LACFIELDID = ddlStudyFields.SelectedItem.Value
loanapplication.LACINSTITUTEID = ddlInstitute.SelectedItem.Value
loanapplication.LASTARTEDUCATION = CCommon.MyFormatDate(txtStartDate.Text)
loanapplication.LAYEAREDUCATION = txtYearEducation.Text
loanapplication.LADURATIONYEAR = txtDurationYear.Text
loanapplication.LADURATIONMONTH = txtDurationMonth.Text
applyprogram.Save(BLL.UpdateType.Update)
loanapplication.Save(BLL.UpdateType.Update)
CCommon.CreateMessageAlert(Me, "Record Updated Successfully",
"PromptMessage")
** only few fields (end with smileys) updated
** no error msg
|
|
|
|
|
Ok. This isn't complete by any means. All this does is set a bunch of properties. We'd need to see the code that's behind the Save methods. What does the actual updates to the database?
|
|
|
|
|
hi habibah
What Exactly are you updating ?
Post us your code and point to the Error.
i have once Written an Article about your problem, but that article is for Newbies, for now it will help you
http://www.codeproject.com/KB/vb/N-Tier_Application_VB.aspx[^]
Hope it helps and dont forget to vote for my Article
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
anyone out there who can help me develop a very,very simple game of snake using VB.NET? it is due tomorrow so i really need your help...
it must be until Level 3...
tnx in advance...God bless...
|
|
|
|
|
sakhura_31 wrote: help me develop a very,very simple game of snake using VB.NET?
Maybe we could help if you asked a more specific question about where your stuck.
sakhura_31 wrote: it is due tomorrow so i really need your help...
I certainly hope you started this project at least a couple of weeks ago...
|
|
|
|
|
sakhura_31 wrote: is due tomorrow so i really need your help.
When you fail this assignment, stop and consider if you want to pursue Computer Science or not. IF you do, then do your own homework instead of going out drinking, when it is assigned to you. By all means, if you do your homework and get stuck on specifics, ask here.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I am developing an application which i am using crystal report as reporting.
i am getting exception despite i added crystal report .dll in reference.
You are the most welcome to assit me in solving this problem.
Abdul Rahaman Hamidy
Senior Student Student in Computer Science, Kabul, Afghanistan
Interesed in Software Development
|
|
|
|
|
Abdul Rahman Hamidy wrote: You are the most welcome to assit me in solving this problem.
We'd love to help, but you haven't told us what the problem is, other than "I'm getting an exception." What's the exception message?? Without that, we're just guessing at the hundred of possible exception messages you may be getting.
|
|
|
|
|