Results 1 to 5 of 5

Thread: Code not obeying simple mathematics

  1. #1

    Thread Starter
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Code not obeying simple mathematics

    vb Code:
    1. While Not rstScheduleDtl.EOF
    2.     If rstScheduleDtl!StartTime < Me!StartTime And rstScheduleDtl!EndTime > Me!EndTime Then
    3.         Call ftest(rstScheduleDtl!Status, rstScheduleDtl![Gala/FF])
    4.     Else
    5.         If Me!StartTime < rstScheduleDtl!EndTime < Me!EndTime Then
    6.             Call ftest(rstScheduleDtl!Status, rstScheduleDtl![Gala/FF])
    7.         Else
    8.             If Me!StartTime < rstScheduleDtl!StartTime < Me!EndTime Then
    9.                 Call ftest(rstScheduleDtl!Status, rstScheduleDtl![Gala/FF])
    10.             End If
    11.         End If
    12.     End If
    13.     rstScheduleDtl.MoveNext
    14. Wend

    As you can see I am only using the > and < operands, and have not included anywhere an = or even a >=. However, as an example, when rstScheduleDtl!StartTime = Me!EndTime, which shouldn't fall into any of the categories above, the code is treating it as a conflict, meaning it thinks that case 3 is correct. Why is the code not honouring the < and > operands as they should be defined?

    Just to point out, all of the above fields are using the same Medium Time Format (e.g. 05:34PM)

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Code not obeying simple mathematics

    It is the Time < Time < Time in your IF statements:
    For example. Try this, what do you think result is? Debug.Print 1 < 2 < 1

    Change your IFs to a format like:
    If (Time1 < Time2) And (Time2 < Time3)

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

    Re: Code not obeying simple mathematics

    The conditional seems wrong. You need to handle multiple conditions differently.


    Code:
    If (Me!StartTime < rstScheduleDtl!EndTime) AND (Me!StartTime < Me!EndTime) Then
    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

  4. #4

    Thread Starter
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Code not obeying simple mathematics

    It worked! fantastic, thanks guys. Foolish of me to try and just slam out the code like an algebraic equation..

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

    Re: Code not obeying simple mathematics

    No prob. Actually in PHP you can do things like that logic.
    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

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