Program not ending???

A

Armin Zingler

CMM said:
2) F1 behavies differently in VS2005. Don't highlight any part of
the word in your source code that you're trying to look up. Just
keep the cursor anywhere in it, then hit F1.


As he mentioned "#Region " Windows Form Designer generated code ", I guess
he is not using VB 2005.


Armin
 
C

cj

Lets see if I can answer some of the question that came up overnight.

I'm using VS 2003. Of course now 50% of the time I'm using Visual Fox
Pro 9 which I've never touched before.

No, never used project properties. I wrote programs not projects. :)
Before .net I used VB4. No flash screens either. My programming has
always been for in-house use. No need to advertise and nobody wants
extra glitz.

I'll take a look at your link as soon as I can.
 
C

cj

I agree boring, if I didn't need to get this info I wouldn't be reading
it. What perplexes me is I see you did continue to read because you
posted at the end of the longest "thread" emanating from my original post.

Your suggestion is interesting however quite different from Armin's code
which has stuff like application.run(form) in it. If you're both right,
and I think you are, then I must conclude there is no "right" way to
write this program. Which makes me wonder if there was any real problem
with my approach to the program--except the closing issue I noted.
Which I solved by putting end in the form1.closing event, everyone gasp now.
 
C

CMM

Wait a minute. I just tried your code (its not boring... it's
interesting).... it works here... are you saying you want to be able to
ABORT the loop when the user closes the form? I see

Here's my elegant fix (note I also avoid short-circuiting with is
problematic and discouraged):

Private cancelLoop As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.Show()
Application.DoEvents()

If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
' Create a reference to the current directory.
Dim DirInfo As New
System.IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
' Create an array representing the files in the current directory.
Dim FileInfo As System.IO.FileInfo() = DirInfo.GetFiles("*.jpg")

For Each File As System.io.FileInfo In FileInfo
Label1.Text = File.FullName
PictureBox1.Image = Image.FromFile(File.FullName)
Application.DoEvents()
System.Threading.Thread.Sleep(2000)

If cancelLoop Then
Exit For
End If
Next
End If

End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

cancelLoop = True

End Sub
 
C

cj

I like it. It fixes my problem w/o radically changing my code. Hence I
completely understand it. Although Armin did pretty good. I think you
need me.close after the for loop to match my original functionality but
who cares.

Now, suppose I put a menu with file/exit on it. What code would you put
in it? Perhaps just me.close() since that would make the closing
routine run which stop the loop. (I first tried this reversed. Having
the menu item do the cancelloop and me.close and the closing event call
the menu item click but that gave me lots of problems.) It seems
logical. Let The closing event could stop all the crap that's running
and tidy up. All the exit item has to do is start the form closing
which is the exact same thing as clicking the X which so many folks like
to do. Does that sounds logical to you too?
 
C

CMM

Yup sounds logical. If Form_Closing sets the flag, there's no need to
reproduce it in the menu. Just do Me.Close in the menu.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top