I've noticed, sometimes while running my program, that if i place messageboxes at certain points, my results are different, than if I left them out.
Would these act as doevents and allow my program to calculate things when normally it wouldnt?
Printable View
I've noticed, sometimes while running my program, that if i place messageboxes at certain points, my results are different, than if I left them out.
Would these act as doevents and allow my program to calculate things when normally it wouldnt?
No they dont do the same things. Msgboxs halt all processes until it is dismissed whereas DoEvents returns control to the OS so it can process stuff while your application is running.
hrm, why would my program output different numbers when I display a message box then? :/
I have no idea. What is the code that is being run with, and without, the message box?Quote:
Originally Posted by kfcSmitty
its the exact same code, just I have
msgbox "Campustotal: " & campustotal
placed in there :/
Are you running it compiled or just in the IDE? Are you using any Timer control(s)? Post some of the related code.
VB Code:
Public Sub GetIncreases(Account As String, Hours As Integer, Payband As String, IDed As String) If WorkerForm Or FirstTime Then total = 0 FirstTime = False End If Set rsIncreaseAmounts = New ADODB.Recordset rsIncreaseAmounts.Open "Increases", cn, adOpenKeyset, adLockPessimistic, adCmdTable rsIncreaseAmounts.MoveFirst Set RsIncreases = New ADODB.Recordset RsIncreases.Open "Increases", cn, adOpenKeyset, adLockPessimistic, adCmdTable RsIncreases.MoveFirst Increases = RsIncreases.Fields("NumofIncreases") NextDate = "4/1" For i = 0 To Increases Days(i) = 0 'If Not SelectForm Then If i > 1 Then rsIncreaseAmounts.MoveNext If i = 0 Then FirstTime = True IncreaseAmount(i) = 1 ElseIf i = 1 Then IncreaseSave = IncreaseSave + RsIncreases.Fields("Amount") IncreaseAmount(i) = (IncreaseSave / 100) + 1 ElseIf i > 1 And i <= Increases Then IncreaseSave = IncreaseSave + RsIncreases.Fields("Amount") IncreaseAmount(i) = (IncreaseSave / 100) + 1 End If If i <> 0 Then RsIncreases.MoveNext 'Sets the date to next date 'If no nextdate exists, input 31/3 (March 31) If i < Increases Then StartDate = CDate(NextDate) NextDate = CDate(RsIncreases.Fields("IncreaseDate")) Else StartDate = CDate(NextDate) NextDate = CDate("3/31") End If ' Else 'Splitter ' End If Anniversary 'If SomeVar Then dtmTestDate = CDate(StartDate) If CDate(NextDate) - CDate(StartDate) <= 0 Then NextDate = CDate(NextDate) + 365 End If Do Until CDate(dtmTestDate) >= CDate(NextDate) If Weekday(dtmTestDate) = vbSaturday _ Or Weekday(dtmTestDate) = vbSunday Then ' skip it Else Days(i) = Days(i) + 1 End If dtmTestDate = DateAdd("d", 1, CDate(dtmTestDate)) Loop If i = 0 Then Days(i) = Days(i) + 1 'End If End If Select Case Account Case "42000", "42500" 'Support Call Supports(Hours, Payband, Account) Forms![frmworkerinformation].txtID.SetFocus If AnniversaryHappened And anniversaryCurrent Then total = Days(i) * (newSupportDailyTotal * IncreaseAmount(i)) DoEvents Campustotal = Campustotal + total ElseIf AnniversaryHappened Then total = DaysBefore * (SupportDailyTotal * IncreaseAmount(i)) total = total + DaysAfter * (newSupportDailyTotal * IncreaseAmount(i)) anniversaryCurrent = True DoEvents Campustotal = Campustotal + total Else total = (Days(i) * (SupportDailyTotal * IncreaseAmount(i))) Campustotal = Campustotal + total End If Case "40100", "40300", "40400", "40800" 'FullTime Academics If AnniversaryHappened And anniversaryCurrent Then Call FullTimeAcademics(Payband, Account) total = (Days(i) * (newPaybandAmount * IncreaseAmount(i))) Campustotal = Campustotal + total ElseIf AnniversaryHappened Then total = DaysBefore * (PaybandAmount * IncreaseAmount(i)) total = total + DaysAfter * (newPaybandAmount * IncreaseAmount(i)) Campustotal = Campustotal + total Else total = (Days(i) * (PaybandAmount * IncreaseAmount(i))) Campustotal = Campustotal + total End If Case "41200", "40404" 'Parttime Sessional Call AcademicPTSS(Hours, Payband, Account) If AnniversaryHappened And anniversaryCurrent Then total = Days(i) * (newAcaPTSSDailyTotal * IncreaseAmount(i)) Campustotal = Campustotal + total ElseIf AnniversaryHappened Then total = total + DaysBefore * (AcaPTSSDailyTotal * IncreaseAmount(i)) total = total + DaysAfter * (newAcaPTSSDailyTotal * IncreaseAmount(i)) Campustotal = Campustotal + total Else total = (Days(i) * (AcaPTSSDailyTotal * IncreaseAmount(i))) Campustotal = Campustotal + total End If Case "41201" 'Partial Load Call AcademicPL(Hours, Payband, Account) If AnniversaryHappened And anniversaryCurrent Then total = Days(i) * (newAcaPLDailyTotal * IncreaseAmount(i)) Campustotal = Campustotal + total ElseIf AnniversaryHappened Then total = DaysBefore * (AcaPLDailyTotal * IncreaseAmount(i)) total = total + DaysAfter * (newAcaPLDailyTotal * IncreaseAmount(i)) Campustotal = Campustotal + total Else total = (Days(i) * (AcaPLDailyTotal * IncreaseAmount(i))) Campustotal = Campustotal + total End If Case "41500", "41900" Call Administration End Select Next rsIncreaseAmounts.Close RsIncreases.Close MsgBox "SupportBi-weeklyTotal: " & SupportDailyTotal * 10 MsgBox "Support New bi-weekly total: " & newSupportDailyTotal * 10 End Sub
thats a chunk of code..lots of other stuff..but this is where im pretty sure its happening...now withose msgboxes on the bottom, it gives me a value of 133,000 approx..but without them it gives me approxd 48,000
i threw in some doevents to see if that would clear ir up..but i have no idea as to whats happening
I think there are instances when we use a msgbox the cpu still processes some tasks/events like a timer or refreshing a webbrowser... I might be wrong though...
Correct Dee-U. If there is a timer of if this procedure is called from a timer event procedure then the compiled version will
continue to process lines of code and the msgbox will not have its Modal effect. This is why I asked about having a timer in
your app/project.
If you have loops rather than timers running, that'll do it too.
We subclass and capture the windows APPACTIVATE message - so we know when app loses and gains focus over other app's on the machine...
That event fires even when a modal message box is on the screen.
We needed to set a global variable before each and every modal event, so that the subclass function would know not to run...
If you remove the DOEVENTS does it still happen?
Place some debug.print's at the top of this function and others that call it (prior to it in the chain) - something is firing this function multiple times would be my guess...
MsgBox's don't halt processing. Your app is proceeding line by line in the same sub/function, but vb does have minor capabilities of multithreading. Therefore, if other subs/functions are running, they will not stop because a msgbox pops up.
On a seperate case: Let's say you're loading a page in the webbrowser and you pop up a message box. The browser will continue loading the page but most of the program's functionality is halted. Doevents simply allows to capture input from devices such as the mouse and keyboard, as well as visual processing of the application.
I read somewhere that there is an issue with the Timer control. IT works differently in a compiled EXE and in the IDE. In one of them msgbox halts the timer while in the other it allows it to continue.
So avoid timers in such situations where it would show a message box.
Pradeep :)