+ Reply to Thread
Results 1 to 5 of 5

How to have many arguments in a module without it breaking

  1. #1
    Registered User
    Join Date
    09-02-2022
    Location
    Iceland
    MS-Off Ver
    MS 365 Enterprise
    Posts
    10

    How to have many arguments in a module without it breaking

    Hi everyone,
    Hope you're having a lovely day. I was hoping if you could point me into the right direction regarding this code. It works in single module parts but not as a whole in one three part module. I would love to be able to make a continuous module without breaking it up.
    Input:
    Returns: [ 0.25 , 0.10 , -0.25 ]
    Probability: [ 0.5 , 0.3 , 0.2 ]
    Result: 0.357

    I just get a " 0,0 " result from this function so it's breaking somewhere but I just can't figure out where.

    Please Login or Register  to view this content.
    Last edited by HappyExcelLife; 09-09-2022 at 10:01 AM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,826

    Re: How to have many arguments in a module without it breaking

    I didn't fully debug it, but I will make a couple of comments and leave some debugging to you. Remember that only half of coding is writing the procedure. Debugging is the other half.

    1) As I explain in my little primer on UDFs (https://www.excelforum.com/tips-and-...uild-udfs.html ), one of the first things I do with a UDF is add at least one stop statement or breakpoint to bring up debug mode. Somewhere at the top of the procedure I would add a stop statement.

    2) What is the purpose of the On Error Resume Next statements? What error(s) are you expecting and why is "ignore error and continue" the best way to trap and handle those errors? I think sometimes we get into a habit of putting "On Error Resume Next" into our code rather than really thinking through the error trapping and handling. In your procedure, there appears to be at least one fatal error that ignoring and continuing is definitely the wrong approach. If you have included "On Error Resume Next" out of habit rather than real thought about the expected errors, then I would remove all "On Error Resume Next" statements and let VBA raise the errors or fail or whatever it is going to do or not do so you know where the errors are.

    3) As an example of an error that I see, in part 2, you have a "Returns - ExpectedReturn" operation. Returns is a Range, and ExpectedReturn is also a Range (that has never been assigned anything). I could be wrong, but I don't think VBA knows what "Range-Range" or "Range-Nothing" means. With On Error Resume Next active, VBA just ignores and continues, so nothing gets assigned to Arg2(). When you get to part 3 where you want to do something with the results in Arg2(), there is nothing there, so nothing further happens. Again, any errors are just ignored, so you get to the end without really doing anything and no errors are raised.

    To recap -- I would add Stop statements for debugging. Then I would suggest you think through your error trapping and handling more carefully, because "ignore and continue" doesn't seem like the correct error handling strategy for the errors that are present. As I said, I didn't fully debug, because I didn't want to fully reverse engineer what you are wanting to do and figure out the corrections. I'm hopeful that, by not ignoring errors and entering debug mode, you will be able to figure out what needs to be done differently.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    09-02-2022
    Location
    Iceland
    MS-Off Ver
    MS 365 Enterprise
    Posts
    10

    Re: How to have many arguments in a module without it breaking

    Thank you so much Mrshorty! I'll take this info and go into debugging it

  4. #4
    Registered User
    Join Date
    09-02-2022
    Location
    Iceland
    MS-Off Ver
    MS 365 Enterprise
    Posts
    10

    Re: How to have many arguments in a module without it breaking

    Hi Mr.Shorty

    It seems that my problem is moving information that I have already calculated and storing it inside vba for further use seems to be my problem. I've used the stop command and debug.print command to narrow down the problem to the second module, and I've also tried to clean up the code. But I'm stuck on this. I have already named C as double so I don't see the problem why VBA won't just subtract it from AB.

    I'd love to hear what you think if you have the time, thank you very much for your help so far.

    input:
    A: [ 0.25 , 0.10 , -0.25 ]
    B: [ 0.5 , 0.3 , 0.2 ]

    Output:
    Want= [0.020 , -0.075 , -0.155 ]
    What I actually get: #VALUE!

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-02-2022
    Location
    Iceland
    MS-Off Ver
    MS 365 Enterprise
    Posts
    10

    Re: How to have many arguments in a module without it breaking

    OMG \(^o^)/ IT WORKED!!
    I'll be honest I have no idea how this was the reason it worked but it somehow did... \_◉‿◉_/
    Thank you so much for the help

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. upload a new Module to overwrite previous module to update expriration date!
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-10-2021, 07:41 PM
  2. [SOLVED] Error Wrong number of arguments to IF. Expected between 2 and 3 arguments, but got 4 argum
    By tommystanek in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-11-2019, 12:10 PM
  3. Formula breaking module code
    By Milos87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2018, 08:07 PM
  4. [SOLVED] Extra Sheet not a Chart or Old Macro Module or Worksheet - Appears to be normal module???
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 06-06-2017, 04:10 AM
  5. Compile error in hidden module: Module 1 when workbook opened on different machine!?
    By MathUKTeacher in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-06-2015, 04:38 PM
  6. [SOLVED] Code locks cells when inserted in sheet module but returns error in standard module
    By yoda66 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2014, 07:39 AM
  7. how to access Sheet module, normal module, Worbook module to type code
    By alibaba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2009, 07:51 AM

Tags for this Thread

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