Consulting

Page 3 of 3 FirstFirst 1 2 3
Results 41 to 53 of 53

Thread: VBA Project help and overflow error

  1. #41
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    ..moving swiftly on:
    I'm guessing that the cup is cylindrical, like the straw so you need to use similar formulae to calculate the volumes of each.
    Regarding your cup volume calculation:
    Volc = Pi * 16 * Cuph
    If you already know how to calculate the volume of a cylinder then I reckon that the 16 in the formula means the cup has a radius of 4. You have Dimmed a variable Rc, but you've neither set nor used it. You should set its value somewhere, then instead of 16 in the formula do something to Rc in there.

    Now your formula for the straw's volume should be similar. Rather than
    Vols = Rs * Cuph
    you should see Pi in there somewhere, as well as doing a bit more with Rs.

    When you've finished, both formula should look very similar, the only difference being two substitutions of lower case c for lower case s.

    Your formula for the new water level
    Cuph = Volc / (Pi * 16) will work fine, but only if the cup's radius is 4. Again, it might be an idea to use Rc in there, as above.

    If all that's put right, you're looking for results where for a straw radius of 0.2 you expect some 1200 dips required.

    Your graphs might look like:
    Attachment 3598
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  2. #42
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by p45cal
    ...then I reckon that the 16 in the formula means the cup has a radius of 4....

    Your formula for the new water level
    Cuph = Volc / (Pi * 16) will work fine, but only if the cup's radius is 4....

    If all that's put right, you're looking for results where for a straw radius of 0.2 you expect some 1200 dips required...
    Greetings Pascal,

    If I am mis-reading, I'll certainly ask forgiveness/apologize. From my current understanding, I respectfully/humbly disagree.

    If the diameter is 16, the radius is 8.

    The OP's functions's formula construction appear incorrect to me, as the radius is not being squared.

    reference:
    [vba]
    Function CupVolume()
    Volc = Pi * 16 * Cuph

    End Function
    [/vba]
    I guessed at the 16 being the radius and got 19k+ dips for the .2 straw.

    Mark

  3. #43
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by GTO
    If the diameter is 16, the radius is 8.
    Quite true.. but I didn't think 16 was the diameter, rather I guessed that 16 was supposed to be the square of something.. perhaps 4.

    It was only mdmckillop who used the word diameter, Goallie11 always used radius, referring to both cup and straw, and the variable names Rs and Rc (the latter currently unused) imply radii rather than diameters.

    But this has already given perhaps too much info, so to Goallie11, see here.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #44
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I did use the diameter in the description, and in the context, consider it the correct figure to use as a constant. I've never heard of a cup size being measured by the radius. The calculation would of course be revised to use this new constant. As an exercise, I would leave this to the student to figure out.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #45
    Sorry it's taken me so long to respond, I was out last night.

    But to answer some questions, yeah the radius of the cup is 4, with 16 being the square. That gives the formula of Pi * 16 * Cuph for the volume of the cup.

    The cup is cylindrical and so is the straw. And oh man I can't believe I missed the pi in the calculate for the straw volume! It worked so I just never looked at it. That shows you always have to be vigilant.

    So I went through and changed everything and also added a new formula as we also have to graph an analytical vs numerical for Rs = 0.5 chart. This has been added at the bottom, and I believe everything works fine now.

    GTO you were right, I cleared off the numbers in the workbook and it made it small enough. So it's finally attached now for everyone to see!

  6. #46
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Regarding Single and Double and the 0.5 error, refer to this post
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #47
    What 0.5 error are you talking about? I don't want to sound ignorant but it looks to me like it works fine. The little differences in rounding don't affect this assignment too much.

  8. #48
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by p45cal
    Quite true.. but I didn't think 16 was the diameter, rather I guessed that 16 was supposed to be the square of something.. perhaps 4.
    My utter bad, you were obviously spot-on with what the OP was doing. (I suppose the absurdity of a 16 or 32 inch wide cup should have struck me harder... )

    Goallie,

    Very nice progress

    Mark

  9. #49
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by Goallie11
    I copied your code and put it in place of mine and it works but it only goes to Rs = 0.45 for me, where it needs to go until Rs = 0.5

    I don't think it should do that as there is still the While Rs <=0.5 loop in there. What would cause it to stop there instead of continuing?
    I was meaning this issue, and the reason it occurred.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #50
    Oh yeah, changing Rs to double solved that issue.

    Thanks GTO, I couldn't have done it without the help of this forum, all you guys are great.

  11. #51
    VBAX Contributor
    Joined
    May 2010
    Location
    Sydney, NSW, Australia
    Posts
    170
    Location
    Quote Originally Posted by mdmackillop
    There is no advantage in Interger over Long, so always use Long
    I disagree, using a long where only integer is needed is a waste of memory space. Being that the OP is learning I think it is good practice to push them towards being memory efficient.

    Just because we have gigs and gigs of ram these days, doesn't mean we should be wasteful, this is why modern PC's need constant reboots and the like because of corners being cut.

  12. #52
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    It may not be as straightforward.. storage space/speed/overhead; see
    here and here and here and here.

    Quote Originally Posted by Blade Hunter
    I disagree, using a long where only integer is needed is a waste of memory space. Being that the OP is learning I think it is good practice to push them towards being memory efficient.

    Just because we have gigs and gigs of ram these days, doesn't mean we should be wasteful, this is why modern PC's need constant reboots and the like because of corners being cut.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  13. #53
    VBAX Contributor
    Joined
    May 2010
    Location
    Sydney, NSW, Australia
    Posts
    170
    Location
    Quote Originally Posted by p45cal
    It may not be as straightforward.. storage space/speed/overhead; see
    here and here and here and here.
    Hmmmm, I could have sworn I already replied to this.

    Thanks for the links, I have learned something .

    I stand corrected .

    Cheers

    Dan

Posting Permissions

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