Results 1 to 14 of 14

Thread: Can Msgbox act as DoEvents?

  1. #1

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Can Msgbox act as DoEvents?

    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?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Can Msgbox act as DoEvents?

    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.

  3. #3

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Can Msgbox act as DoEvents?

    hrm, why would my program output different numbers when I display a message box then? :/

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Can Msgbox act as DoEvents?

    Quote Originally Posted by kfcSmitty
    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?

  5. #5

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Can Msgbox act as DoEvents?

    its the exact same code, just I have

    msgbox "Campustotal: " & campustotal

    placed in there :/

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Can Msgbox act as DoEvents?

    Are you running it compiled or just in the IDE? Are you using any Timer control(s)? Post some of the related code.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Can Msgbox act as DoEvents?

    VB Code:
    1. Public Sub GetIncreases(Account As String, Hours As Integer, Payband As String, IDed As String)
    2. If WorkerForm Or FirstTime Then
    3.     total = 0
    4.     FirstTime = False
    5. End If
    6. Set rsIncreaseAmounts = New ADODB.Recordset
    7. rsIncreaseAmounts.Open "Increases", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    8. rsIncreaseAmounts.MoveFirst
    9. Set RsIncreases = New ADODB.Recordset
    10. RsIncreases.Open "Increases", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    11. RsIncreases.MoveFirst
    12. Increases = RsIncreases.Fields("NumofIncreases")
    13. NextDate = "4/1"
    14.     For i = 0 To Increases
    15.         Days(i) = 0
    16.         'If Not SelectForm Then
    17.             If i > 1 Then rsIncreaseAmounts.MoveNext
    18.             If i = 0 Then
    19.                 FirstTime = True
    20.                 IncreaseAmount(i) = 1
    21.             ElseIf i = 1 Then
    22.                 IncreaseSave = IncreaseSave + RsIncreases.Fields("Amount")
    23.                 IncreaseAmount(i) = (IncreaseSave / 100) + 1
    24.             ElseIf i > 1 And i <= Increases Then
    25.                 IncreaseSave = IncreaseSave + RsIncreases.Fields("Amount")
    26.                 IncreaseAmount(i) = (IncreaseSave / 100) + 1
    27.             End If
    28.             If i <> 0 Then RsIncreases.MoveNext
    29.             'Sets the date to next date
    30.             'If no nextdate exists, input 31/3 (March 31)
    31.             If i < Increases Then
    32.                 StartDate = CDate(NextDate)
    33.                 NextDate = CDate(RsIncreases.Fields("IncreaseDate"))
    34.             Else
    35.                 StartDate = CDate(NextDate)
    36.                 NextDate = CDate("3/31")
    37.             End If
    38.        ' Else
    39.             'Splitter
    40.        ' End If
    41.         Anniversary
    42.         'If SomeVar Then
    43.         dtmTestDate = CDate(StartDate)
    44.         If CDate(NextDate) - CDate(StartDate) <= 0 Then
    45.             NextDate = CDate(NextDate) + 365
    46.         End If
    47.         Do Until CDate(dtmTestDate) >= CDate(NextDate)
    48.             If Weekday(dtmTestDate) = vbSaturday _
    49.             Or Weekday(dtmTestDate) = vbSunday Then
    50.                 ' skip it
    51.             Else
    52.                 Days(i) = Days(i) + 1
    53.             End If
    54.             dtmTestDate = DateAdd("d", 1, CDate(dtmTestDate))
    55.         Loop
    56.         If i = 0 Then
    57.              Days(i) = Days(i) + 1
    58.         'End If
    59.         End If
    60.         Select Case Account
    61.             Case "42000", "42500" 'Support
    62.                 Call Supports(Hours, Payband, Account)
    63.                     Forms![frmworkerinformation].txtID.SetFocus
    64.                    If AnniversaryHappened And anniversaryCurrent Then
    65.                        total = Days(i) * (newSupportDailyTotal * IncreaseAmount(i))
    66.                        DoEvents
    67.                        Campustotal = Campustotal + total
    68.                    ElseIf AnniversaryHappened Then
    69.                        total = DaysBefore * (SupportDailyTotal * IncreaseAmount(i))
    70.                        total = total + DaysAfter * (newSupportDailyTotal * IncreaseAmount(i))
    71.                        anniversaryCurrent = True
    72.                        DoEvents
    73.                        Campustotal = Campustotal + total
    74.                    Else
    75.                        total = (Days(i) * (SupportDailyTotal * IncreaseAmount(i)))
    76.                        Campustotal = Campustotal + total
    77.                    End If
    78.             Case "40100", "40300", "40400", "40800" 'FullTime Academics
    79.                 If AnniversaryHappened And anniversaryCurrent Then
    80.                     Call FullTimeAcademics(Payband, Account)
    81.                     total = (Days(i) * (newPaybandAmount * IncreaseAmount(i)))
    82.                     Campustotal = Campustotal + total
    83.                 ElseIf AnniversaryHappened Then
    84.                     total = DaysBefore * (PaybandAmount * IncreaseAmount(i))
    85.                     total = total + DaysAfter * (newPaybandAmount * IncreaseAmount(i))
    86.                     Campustotal = Campustotal + total
    87.                 Else
    88.                     total = (Days(i) * (PaybandAmount * IncreaseAmount(i)))
    89.                     Campustotal = Campustotal + total
    90.                 End If
    91.             Case "41200", "40404" 'Parttime Sessional
    92.                 Call AcademicPTSS(Hours, Payband, Account)
    93.                 If AnniversaryHappened And anniversaryCurrent Then
    94.                     total = Days(i) * (newAcaPTSSDailyTotal * IncreaseAmount(i))
    95.                     Campustotal = Campustotal + total
    96.                 ElseIf AnniversaryHappened Then
    97.                     total = total + DaysBefore * (AcaPTSSDailyTotal * IncreaseAmount(i))
    98.                     total = total + DaysAfter * (newAcaPTSSDailyTotal * IncreaseAmount(i))
    99.                     Campustotal = Campustotal + total
    100.                 Else
    101.                     total = (Days(i) * (AcaPTSSDailyTotal * IncreaseAmount(i)))
    102.                     Campustotal = Campustotal + total
    103.                 End If
    104.             Case "41201" 'Partial Load
    105.                 Call AcademicPL(Hours, Payband, Account)
    106.                 If AnniversaryHappened And anniversaryCurrent Then
    107.                     total = Days(i) * (newAcaPLDailyTotal * IncreaseAmount(i))
    108.                     Campustotal = Campustotal + total
    109.                 ElseIf AnniversaryHappened Then
    110.                     total = DaysBefore * (AcaPLDailyTotal * IncreaseAmount(i))
    111.                     total = total + DaysAfter * (newAcaPLDailyTotal * IncreaseAmount(i))
    112.                     Campustotal = Campustotal + total
    113.                 Else
    114.                     total = (Days(i) * (AcaPLDailyTotal * IncreaseAmount(i)))
    115.                     Campustotal = Campustotal + total
    116.                 End If
    117.             Case "41500", "41900"
    118.                 Call Administration
    119.         End Select
    120.     Next
    121.     rsIncreaseAmounts.Close
    122.     RsIncreases.Close
    123.     MsgBox "SupportBi-weeklyTotal: " & SupportDailyTotal * 10
    124.     MsgBox "Support New bi-weekly total: " & newSupportDailyTotal * 10
    125. 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

  8. #8
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Can Msgbox act as DoEvents?

    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...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Can Msgbox act as DoEvents?

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Can Msgbox act as DoEvents?

    If you have loops rather than timers running, that'll do it too.

  11. #11
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Can Msgbox act as DoEvents?

    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...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  12. #12
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Can Msgbox act as DoEvents?

    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...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  13. #13
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Re: Can Msgbox act as DoEvents?

    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.
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  14. #14
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Can Msgbox act as DoEvents?

    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
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width