Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Do any one know a command to completly stop the program running .

 

I have a for loop which has a try and catch function

 

For Each MyFile In FilesArray

Try

MyFile.Delete()

 

Catch ex As Exception

MessageBox.Show("close all other wondows a run the program again", "DocumentManager Information", MessageBoxButtons.OK, MessageBoxIcon.Information)

 

Application.Exit()

End Try

 

Next MyFile

 

i use application.exit() to end the program ,but the program runs till "for loop" ends.

 

ie if the looop goes into catch 2 times then it displays the message box twice.

 

Is there any other command to stop the program from completly running the first time enters the catch.I use vb.net for programming.

Posted

Just Use "Exit For" After The Messagebox Inside Your Catch Block

 

For Each MyFile In FilesArray
Try

MyFile.Delete()

Catch ex As Exception
MessageBox.Show("close all other wondows a run the program again", "DocumentManager Information", MessageBoxButtons.OK, MessageBoxIcon.Information)

Exit For

Application.Exit()
End Try

Next MyFile

 

 

-=Simcoder=-

Whatever thy hand findest to do, do it with all thy heart - Jesus
Posted

actually:

 

Try

[indent]For Each MyFile In FilesArray
[indent]MyFile.Delete()
[/indent]
next MyFile
[/indent]Catch ex As Exception

[indent]MessageBox.Show("close all other wondows a run the program again", "DocumentManager Information", MessageBoxButtons.OK, MessageBoxIcon.Information)

Application.Exit()
[/indent]
End Try

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted
joe yourcode was very helpfull since i was using this for loop inside a funtion and i do call this function 3 times in the same program.I have used try catch whenever i call this function instead of using it in for loop.since i am new to java and VB.net i really don't know much about try catch.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...