DoEvents resetting variables

  • Thread starter Thread starter Tym
  • Start date Start date
T

Tym

Made the change from vb6 to vb.net and have found that DoEvents()
doesn't work!!

Well, the replacement

System.Windows.Forms.Application.DoEvents()

is causing hell!!

I have a loop such as

for X = 1 to 10
do some things
Next x
System.Windows.Forms.Application.DoEvents()



and the DoEvents command resets the variables and the loop starts all
over again!

What the hell is going on??? I've noticed this a few times,
System.Windows.Forms.Application.DoEvents()
actually causes variables to revert to old values....
 
Do you really need to be using DoEvents()? Try removing the DoEvents calls.
I could help you better if you provided a more detailed code sample.

Regards,
Phil Harvey
 
Do you really need to be using DoEvents()? Try removing the DoEvents calls.
I could help you better if you provided a more detailed code sample.

I tend to use them when the display need "updating". Question is, this
never happed in vb6, so why does it happen in dotnet?


Friend Sub Populate_Cells()
Dim iCurrentPeriod As Integer
Dim iPeriodCount As Integer
Dim iPerInc As Integer

Me.Text = sSURNAME & ", " & sFORENAME & " " & sMIDDLE
Me.txtName.Text = sSURNAME & ", " & sFORENAME & " " & sMIDDLE
Me.txtFORM.Text = sFORM

If sMIDDLE = "" Then
dROp = dsPUPILS.Tables(0).Select("SURNAME = '" & sSURNAME
& "'AND FORENAME = '" & sFORENAME & "'")(0)
Else
dROp = dsPUPILS.Tables(0).Select("SURNAME = '" & sSURNAME
& "'AND FORENAME = '" & sFORENAME & "' AND MIDDLE = '" & sMIDDLE &
"'")(0)
End If

For dayINDEX = 1 To iNoDays
Select Case dayINDEX
Case 1
iPeriodCount = iMonN
Case 2
iPeriodCount = iTueN
Case 3
iPeriodCount = iWedN
Case 4
iPeriodCount = iThuN
Case 5
iPeriodCount = iFriN
Case 6
If iSatN <> 0 Then
iPeriodCount = iSatN
End If
End Select
iPerInc = 1
For periodINDEX = 1 To iPeriodCount
txtDISPLAY(dayINDEX, periodINDEX).BackColor =
System.Drawing.SystemColors.Window
If dayINDEX = Weekday(Now) Then
If dtTIMES(dayINDEX, periodINDEX) <
CDate(TimeString) Then
iCurrentPeriod = periodINDEX
End If
End If
'search through the BREAKS table to see if the current
period is a break
dRO = dsBREAKS.Tables(0).Select("PERIOD = " &
periodINDEX)
If dRO.GetUpperBound(0) < 0 Then ' not a break - add
the field
sCrit = dROp("P" & dayINDEX.ToString &
(Format(iPerInc, "00").ToString))
txtDISPLAY(dayINDEX, periodINDEX).Text = sCrit
iPerInc += 1
Else
'it is a break - Populate with break type
For Each Row In dRO
If Row(1) = "B" Then
txtDISPLAY(dayINDEX, periodINDEX).Text =
"BREAK"
ElseIf Row(1) = "L" Then
txtDISPLAY(dayINDEX, periodINDEX).Text =
"LUNCH"
ElseIf Row(1) = "R" Then
txtDISPLAY(dayINDEX, periodINDEX).Text =
"REGISTRATION"
End If
Next
End If
System.Windows.Forms.Application.DoEvents()
Next periodINDEX
Next dayINDEX

txtDISPLAY(Weekday(Now) - 1, iCurrentPeriod).BackColor =
System.Drawing.Color.Yellow
Call LockCells()
End Sub
 
Tym,
Well, the replacement

System.Windows.Forms.Application.DoEvents()

is causing hell!!

One of the situatons I know that this can be is when your method is actualy
an event what is done and by that starting the same event method again new.

And exactly as well as I call it causing a "Hell" because you loose all
control.

:-)

Cor
 
Tym said:
I have a loop such as

for X = 1 to 10
do some things
Next x
System.Windows.Forms.Application.DoEvents()



and the DoEvents command resets the variables and the loop starts all
over again!

Is the code above the same as you use in your project? 'DoEvents' will be
called /after/ the loop was executed, so I don't see a problem here.
 
Is the code above the same as you use in your project? 'DoEvents' will be
called /after/ the loop was executed, so I don't see a problem here.

I know - that's what I thought - but it does!!!!

~bangs head on desk~

Forget it guys.... I think I've just realised what happens..... I have
a timer on another for run this routine. When debugging, it just keeps
cycling round - because the timer keeps running it

~embarrassing shade of beetroot~


Sorry guys!!!!

~Ahem~

~wanders off nonchalantly into the sunset, whistling~
 
Tym,
Forget it guys.... I think I've just realised what happens..... I have
a timer on another for run this routine. When debugging, it just keeps
cycling round - because the timer keeps running it

That is almost the same as I wrote did you not read that?

Cor
 

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

Similar Threads


Back
Top