|
You are catching the exception and ignoring it. Never do that! (Notice the exclamation mark that I used. I use less than a dozen per year, so when I do, they mean something.) If you don't know what to do with it, just throw it again, so that some higher level of the program can catch it.
Also, your error handling doesn't make sure that the files are closed if an error occurs. I believe that the error message that you see comes from some other part of your program when it tries to use a file that has been left open by the function.
Use Try and Finally to make sure that the files are always closed:
Dim fSave
Try
fSave = As New StreamWriter(fName)
fSave.WriteLine("# File Created By ABC")
fSave.WriteLine(value1)
Finally
If not fSave is Nothing Then
fSave.Close()
End If
End Try
You can add a Catch section before the Finally to handle any exception that occurs in this specific part of the code, or wrap all the code in the function inside a Try ... Catch to take care of any exception that occurs anywhere in the function.
---
b { font-weight: normal; }
|
|
|
|
|
no man its not the problem , listen the whole story
i write any text in richtextbox and click on save button which connected to that function, save file properly. but when i open that file again and edit and save again then this error occurs , so im sure that this codes are correct in the fuction:
Dim value1 As String = Text1.Text
Dim fName As String
If lblmsg.Text = "IPL NOT LOAD" Then
Save.ShowDialog()
fName = Save.FileName
If Save.FileName <> "" Then
Dim fSave As New StreamWriter(fName)
fSave.WriteLine("# File Created By ABC")
fSave.WriteLine(value1)
fSave.Flush()
fSave.Close()
lblmsg.Text = fName
lblmsg.TextAlign = ContentAlignment.MiddleLeft
lblmsg.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!)
savechk = False
End If
i think the error occurs in these codes
Else
fName = lblmsg.Text
Dim fSave As New StreamWriter(fName)
If InStr(Text1.Text, "# File Edited By ABC") = True Then
fSave.WriteLine(value1)
fSave.Flush()
fSave.Close()
lblmsg.Text = fName
lblmsg.TextAlign = ContentAlignment.MiddleLeft
lblmsg.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!)
savechk = False
ElseIf InStr(Text1.Text, "# File Created By ABC") = True Then
fSave.WriteLine(value1)
fSave.Flush()
fSave.Close()
lblmsg.Text = fName
lblmsg.TextAlign = ContentAlignment.MiddleLeft
lblmsg.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!)
savechk = False
Else
fSave.WriteLine("# File Edited By ABC")
fSave.WriteLine(value1)
fSave.Flush()
fSave.Close()
lblmsg.Text = fName
lblmsg.TextAlign = ContentAlignment.MiddleLeft
lblmsg.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!)
savechk = False
End If
End If If
|
|
|
|
|
I still believe that's the problem. Especially as you say that the error occurs the second time you use the function.
I showed you how to use proper error handling on the saving part of the code, but not because it's only there you should use it. You should use it on any file operation.
You have no indication of whether the function is working properly or not, as you are ignoring any exceptions that occur. At this stage you have no idea where the error actually is. Start by removing the Try ... Catch so that you see where the error occurs. Then you can correct the error and add proper error handling.
---
b { font-weight: normal; }
|
|
|
|
|
yeah man but you showed me only first/half code,
man i dint said that error coming on second time but i said sometimes it come sometimes not
|
|
|
|
|
xmen_xwk wrote: yeah man but you showed me only first/half code,
I showed you how to do it. I based the example on your code, but perhaps I should have made a completely different example.
xmen_xwk wrote: i dint said that error coming on second time but i said sometimes it come sometimes not
Actually you have said both. Anyway, you have to locate the source of the error before you can do anything about it, regardless of when it appears.
---
b { font-weight: normal; }
|
|
|
|
|
i made an application that looklikes a notepad so i want when i click on any txt file then mine notepad should open
|
|
|
|
|
if u have XP then goto control panel -> folder options -> view -> file types - > scroll down to txt file and click change.
Nathan Lindley
|
|
|
|
|
yeah man i know this , my application open perfect but it not open the text in file
|
|
|
|
|
Your app will be passed the name of the file to open as a parameter, you need to recieve this value and open this file. It doesn't happen magically, you need to grab the parameter and use it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
You're app has to be written to handle command line parameters. Check out the Environment class and its <a href="http://msdn2.microsoft.com/en-us/library/system.environment.getenvironmentvariable.aspx">GetCommandLineArgs</a>[<a href="http://msdn2.microsoft.com/en-us/library/system.environment.getenvironmentvariable.aspx" target="_blank" title="New Window">^</a>] method.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
How can add icon to ToolStripCombobox for VB.NET 2005 as IE...?
Thanks
................
|
|
|
|
|
you want a button on the toolstrip to launch Internet Explorer? or do u want the IE icon?
Nathan Lindley
|
|
|
|
|
I want to add icon to ToolStripCombobox only in VB.NET 2005
................
|
|
|
|
|
Hello.
I work for a PLC programming company and my boss has asked me to create a cleanup program which will remove all the temp files we dont need. He also wants a message box to appear with "More Info" and "Clean" and "Zip Porject" buttons.
Initially I was using VBScript, but I can change the msgbox buttons with this so I moved it to VB6.
The idea is to right click the folder(s) you want to clean and click the project from the SendTo menu and it will work.
How do I get the folder(s) that the user selected with VB6? With VBScript I used WScript.Arguments but I cannot seem to get VB6 to do this.
Thanks for your help
|
|
|
|
|
In VB6 look at the Command$ statement. It returns to you a string containing all the command line args sent to your app.
|
|
|
|
|
Thankyou!
That does just I job I need it to. I knew it would be something simple.
Thankyou again
|
|
|
|
|
hi to all,
I like to create a crystal report in manual manner.
using window form design
|
|
|
|
|
I m generating a crystal report in vb. and an error is coming. Please help me how to solve it?
Dim mystrpur As String
mystrpur = "SELECT IPurMast.`Date`, IPurMast.`Party`, IPurMast.`Amt`, " & _
"IPurTran.`Item`, IPurTran.`NetQty`, IPurTran.`Rate`, IPurTran.`Amt` " & _
" From `IPurMast` IPurMast INNER JOIN `IPurTran` IPurTran ON IPurMast.`Amt` = IPurTran.`Amt` AND IPurMast.`PurNo` = IPurTran.`PurNo` where IPurMast.`Party` = '" & txtParty.Text & "' AND IPurMast.`Date`>= #" & DTPickerS.Value & "# AND IPurMast.`Date`<= #" & DTPickerE.Value & "# "
CrystalReport1.SQLQuery = mystrpur
CrystalReport1.Formulas(0) = "Bill_no = '" & txtBill.Text & "' "
CrystalReport1.Formulas(1) = "Start_dt = '" & DTPickerS.Value & "' "
CrystalReport1.Formulas(2) = "End_dt = '" & DTPickerE.Value & "' "
CrystalReport1.Formulas(3) = "Party_name = '" & txtParty.Text & "' "
CrystalReport1.ReportFileName = "c:\PurReport.rpt"
CrystalReport1.Action = 1 '****Error is in this line
CrystalReport1.WindowWidth = 100
'Erro is *****
error run time error '20599'
can't open sql server
With Regards
Alok Singh
|
|
|
|
|
|
hi,
i have to complete a program today and i stuck on one last problem. i have an access database and an image table with images as ole object. i found some codes in the www to fill my picturebox with these images but it didn`t work.
i tried to fill a dataset with the image column and set the picturebox.image to the column with the following code but it did not work.
<br />
Dim pictureDataset As New Data.DataSet<br />
<br />
HauptAnweisung.CommandText = "Select IMG_DATA AS BILD, IMG_PRID AS ID FROM T_IMAGE WHERE IMG_PRID = '" & besucherId & "'"<br />
<br />
HauptDataAdapter.SelectCommand = HauptAnweisung<br />
<br />
HauptDataAdapter.Fill(pictureDataset)<br />
<br />
bild.Image = pictureDataset.Tables.Item(0).Rows(0).Item("BILD")<br />
can you please help me to get the picture into my picturebox?
thanks michael
|
|
|
|
|
I have approximately 50 labels on an asp.net page written in VB.NET 2003. I use these labels to indicate when an error has occurred by changing the color to system.drawing.color.red when the user tries to submit the page.
Before I perform this validation (there are good reasons why I don't use the native validation controls) I want to make the label invisible so that they don't appear unless an error has been detected.
I tried the following (which obviously didn't work)!
dim LabelCollection as new Collection
dim x as label
for each x in LabelCollection
if x.forecolor.equals(system.drawing.color.red) then
x.visible=false
end if
next
When I debug this code it reaches the "for each" statement but skips over the rest of the code block, i.e. it doesn't appear to find any labels in the collection.
Can anyone help with this process of iterating through a collection of controls?
What have I missed?
|
|
|
|
|
Peter Stanford wrote: dim LabelCollection as new Collection
dim x as label
I'm confused. By what piece of magic did you expect this collection to contain anything ?
The form has a Controls collection. But because a web page is heirarchical, all the controls in it also have a controls collection. You need to iterate over it recursively to find all the labels.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks, I understand recursion, what I can't find is an example of the syntax to use for this particular situation. None of the online help or forums like this one provide anything other than the answer you've just given, i.e. "just do this".
With respect, if I knew how to "just do this" I wouldn't have asked the question!
|
|
|
|
|
Well, like I said - the form has a Controls collection, and so does each control
private void SetLabels(ControlCollection ctrls)
foreach(Control c in ctrls)
{
if (c is Label)
{
// Whatever
}
SetLabels(c.Controls);
}
(somewhere else)
SetLabels(this.Controls)
Sorry, I don't 'do' VB.NET, I give answers here because I know the framework, from using C#. Hopefully, you can convert this.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks Christian,
That's all I was looking for! I can work it out from here.
Best regards
|
|
|
|