Results 1 to 4 of 4

Thread: [RESOLVED] Runtime Error 5: Help!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2011
    Posts
    31

    Resolved [RESOLVED] Runtime Error 5: Help!

    Hello All,

    I have the following piece of code that generates a runtime error 5: invalid call or argument error
    Code:
    Dim f as double
    chMExpHg.Column = 2
    For Z = 1 To (txtMExpT.Text * 60 / txtMExpRef.Text) + 1
        chMExpHg.Row = Z
    
     f = (txtMExpr0.Text * ((txtMExpA.Text * Exp(-0.693 * (Z - 1) * txtMExpRef.Text / 60 / txtMExpTd1.Text)) _
            + ((1 - txtMExpA.Text) * Exp(-0.693 * (Z - 1) * txtMExpRef.Text / 60 / txtMExpTd2.Text)) _
            - (txtMExpB.Text * Exp(-0.693 * (Z - 1) * txtMExpRef.Text / 60 / txtMExpTi.Text)))) / pos_radiation(position)
    
    chMExpHg.Data = -Log(f) / 0.122
    
    Next Z


    The error is generated on the line where the log of f is taken. I've been troubleshooting for quite some time and cannot find a solution.
    I've printed out f during runtime and none of its values are negative or 0. Its first value is 0.0167 and the error is thrown on the first iteration of my loop.
    Additionally, the error only occurs when the equation that sets f includes the part that starts with txtMExpB.Text is included (the user can enter either 0 or 1 into this textbox for this purpose at runtime).

    Any ideas?

    Thanks!

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Runtime Error 5: Help!

    this is probably your issue: -Log

    try changing it to this:
    chMExpHg.Data = (0-Log(f)) / 0.122

    since what you want is the negative log value, that should give you the desired results.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Runtime Error 5: Help!

    Quote Originally Posted by eagles555 View Post
    ...the error only occurs when the equation that sets f includes the part that starts with txtMExpB.Text is included (the user can enter either 0 or 1 into this textbox for this purpose at runtime)….
    Probably not a solution to your problem but instead of forcing the user to enter 0 or 1 in the textbox and, I assume, having to validate the data entered, why not instead use a pair of radio buttons or even a combobox?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jun 2011
    Posts
    31

    Re: Runtime Error 5: Help!

    Thank you for both of your responses! I found the problem. A bunch of the textboxes were named improperly so the data I was reading out to troubleshoot was incorrect. I was actually feeding a 0 to the log function.

    Thanks again!

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