+ Reply to Thread
Results 1 to 13 of 13

Code snippet working intermittently?!

  1. #1
    Registered User
    Join Date
    02-23-2012
    Location
    York, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Cool Code snippet working intermittently?!

    Hi All,

    I'm new to this board, so please forgive me if I'm posting out of place.... I have a piece of code:


    Please Login or Register  to view this content.
    The first MsgBox is just so I can check that DiplexerOrNot is at 1 (Which it should be). The If...then statement just checks an activeX box value against another. My issue is that it sometimes seems to work, sometimes not. The code is inside a button click subroutine and all the other code inside this seems to work. Is there something obvious that could be causing the computer to ignore this?

    For example, if LowerRejectionOne2 is 1000 and LowerBandEdge2 is 10, I would expect an MsgBox. Sometimes this works, but other times, the code just goes on it's merry way!!

    Any help on this would be much appreciated

    Dave
    Last edited by bscdave; 02-24-2012 at 05:59 AM.

  2. #2
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Re: Code snippet working intermittently?!

    Wrap your code in Tags
    Mr MaGoo
    Magoo.Inc MMVII

    If i've helped please add to my Rep by Clicking on the Blue Scales in the top right hand corner of the post

  3. #3
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Re: Code snippet working intermittently?!

    Yes, if the LowerRejectionOne2.Value is < LowerBandEdge2.Value then nothing will occur, you need an else, this way iy will appear no matter what the situation.

    Please Login or Register  to view this content.
    Hope that helps?

  4. #4
    Registered User
    Join Date
    02-23-2012
    Location
    York, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Code snippet working intermittently?!

    Thank you for your help MacDave - I am getting so confused! I've written the following, and it's doing weird things:

    Please Login or Register  to view this content.
    Now this still says rejection is above band edge, even if it is not! I'm probably doing something really silly, I know! It seems to make a difference if one value is a four digit number, whilst the other is a three digit. If both are four digit numbers it seems to work.

    Thanks,

    Dave

  5. #5
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Re: Code snippet working intermittently?!

    Can you upload the workbook or an exmaple of one that way it'll be clearer for me to see exactly what you're doing

  6. #6
    Registered User
    Join Date
    02-23-2012
    Location
    York, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Code snippet working intermittently?!

    Thanks Dave,

    Unfortunately I might not be allowed to upload it because it's part of something I'm doing for work. I was hoping something might "jump out" at a more VBA experienced person

    Dave

  7. #7
    Registered User
    Join Date
    02-23-2012
    Location
    York, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Code snippet working intermittently?!

    Thanks OnError; would this solve my problem? What are the risks in using End on its own?

    Dave

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Code snippet working intermittently?!

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  9. #9
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Code snippet working intermittently?!

    Quote Originally Posted by bscdave View Post
    Thanks OnError; would this solve my problem?
    I think so - try it.

    What are the risks in using End on its own?
    it will destroy all variables including public ones. Might not be an issue for this workbook, but it's a bad habit to get into. (it's the code equivalent of shutting down your computer by pulling the plug out)
    Good luck.

  10. #10
    Registered User
    Join Date
    02-23-2012
    Location
    York, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Code snippet working intermittently?!

    OnError - Thank you - I will try that later today, and let you know how it goes

    RoyUK - sorry, code tags added to first post.

    Dave

  11. #11
    Registered User
    Join Date
    02-23-2012
    Location
    York, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Code snippet working intermittently?!

    Hi All,

    I have been playing around with a number of different ideas, and I finally discovered the problem - I was trying to perform calculations using the values of the input boxes directly, without declaring variables first. If I use

    Please Login or Register  to view this content.
    first, it works fine. Thanks for your help,

    Dave

  12. #12
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Code snippet working intermittently?!

    Val would also work since it converts the text to numbers.

  13. #13
    Registered User
    Join Date
    02-23-2012
    Location
    York, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Code snippet working intermittently?!

    That's one of the things I tried, but it didn't seem to work for me. But having said that I may have used it wrongly. I'll just declare a shedload of variables upfront next time! It's a work in progress...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1