PDA

View Full Version : Just a question about Do/While Loops


crono.Serge
06-16-2006, 10:44 PM
Hi, everybody (Hi Doctor Nick!)

I had a question. I'm working on an assignment for my VB.Net class, and I was wondering, if its possible to implement a Do/Until Loop using the Me.Close() function.

Let me see if I make sense. Create the Do/Until Loop and have the loop stop with the program closes. Kinda like

Do Until Me.Close() = True
'statements go here'
Loop

Is that possible. I try doing that but, I get an error of "Expression does not produce value". Just out of curiosity, if not...ehh, I'll try some other things that pop into my head. Thank guys!

oracleguy
06-17-2006, 06:04 AM
That probably doesn't work since Close() doesn't return a value I'd suspect.

Does this loop run inside the form? I'd assume so since you are using Me. What exactly are you trying to do? There might an different solution to do what you want.

However to get a loop to run continuously inside of a form you could just do:

Do
'statements
Loop

However I've never really done that before so I'm not sure how well that will work. Another thing to try would be to make a private boolean variable that is global for the form and have it set to true when the form opens and then on the close event have it set to false. Then you could have your loop run while that boolean is true.

crono.Serge
06-17-2006, 09:41 PM
I'd kinda look like

Dim blnMeOpen As Boolean = True

....That don't look right. I can kinda picture it in my head, but, it's not coming out right. I've never worked the Boolean data types before. Would I have to put that in a Do/Until loop with If statements?

I think I'm confused....

crono.Serge
06-18-2006, 03:29 AM
I think it just came to me....I'll try it out, and I'll come back to tell you what happend.

Thanks!

crono.Serge
06-20-2006, 06:07 AM
Just not sure wha it is. I created a function to handle all the calculations...but, I think I get stuck in my loop. Can someone point me in the right direction. Thanks!


'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'This function preforms all calculations and checking of errors and input
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Private Function Execute() As Double
'convert text inputed to decimal variable
decFTemp = CDec(txtTemp.Text)
'Do while loop to handle all calculations
Do
'If statement to check wether tempature is between correct range
If decFTemp < 32.0 Or decFTemp > 80.0 Then
MsgBox("Enter a tempature between 32.0 or 80.0", MsgBoxStyle.Critical, "Enter different tempature")
End If
'If statement to see if a techie has been selected
If radJoe.Checked = False Or radJohn.Checked = False Then
'MsgBox("Please Select a Techie before continuing", MsgBoxStyle.OKOnly, "Select A Techie")
End If
'If statement to see if celsius is checked
If chkCelY.Checked = True Then
decCTempEq = ((decFTemp - 32) * 5 / 9)
lblCelsius.Text = CStr(decCTempEq)
End If
decTempAvg += (decFTemp + decFTemp)
lblDispAvg.Text = CStr(decTempAvg)
Loop Until blnStartup = False
End Function

Gox
06-20-2006, 08:25 AM
I don't know my know my VB syntax but the loop condition looks suspect to me. See if changing it to the following helps.
Loop Until blnStartup == False
You're IF conditions also use a single "=", so maybe that's just VB syntax?

Other than that, I don't see anywhere in your loop where blnStartup would ever be set to FALSE thus you loop (exit) condition would never be met and the loop would be infinite.

Fatmumuhomer
06-22-2006, 08:58 PM
I don't know my know my VB syntax but the loop condition looks suspect to me. See if changing it to the following helps.
Loop Until blnStartup == False
You're IF conditions also use a single "=", so maybe that's just VB syntax?

Other than that, I don't see anywhere in your loop where blnStartup would ever be set to FALSE thus you loop (exit) condition would never be met and the loop would be infinite.

VB syntax uses '=' for both comparison and assignment whereas C++ uses '=' for assignment only.

I think his problem is like you said: there's no place that I can see that he actually assigns his blnStartup to be FALSE. Also, crono.Serge, are you sure you declared the variable with the name blnStartup and not blnMeOpen like you mentioned earlier?

crono.Serge
06-23-2006, 12:22 AM
I forgot to do that, but, I fixed it. I got my loop and my program to work. Thanks guys!