dcsimg
Results 1 to 4 of 4

Thread: How to round to the nearest 40 using Basic ocde

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2019
    Posts
    2

    How to round to the nearest 40 using Basic ocde

    I am a novice with basic code, but need to develop a calculation where, if my SampleVol variable = 10, the final reported value gets rounded to the nearest multiple of 40 i.e. 136 would round to 120, and 157 would round to 160 etc. If anything else, its rounded to the nearest 200 (which i was going to acheive using the ROUNDTO function.)

    'Calculate SO3 in process liquors according to SOP LQ07

    Variables are defined as an inherent part of the LIMS basic subroutine, but have been declared here for testing.

    DECLARE VolSample, VolIodine, NIodine, VolNa2S2O3, NNa2S2O3

    IF ( VolSample = 0 ) THEN
    RETURN
    ELSEIF
    VolSample = "10" THEN

    ***

    ELSE
    SO3 = 40000 * ( ( ( VolIodine * NIodine ) - ( VolNa2S2O3 * NNa2S2O3 ) ) / VolSample )

    ENDIF

    RETURN SO3

    How would people best recommend this be achieved?

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

    Re: How to round to the nearest 40 using Basic ocde

    Not sure what code you are planning on using, but the above won't compile in VB.

    Here is one simple method to round to nearest multiple of 40. I don't know if it will handle all of your data and you should verify it and rework it if it fails on some fringe cases:
    Code:
    adjVolume = CLng(inValue / 40) * 40
    136 returns 120 and 157 returns 160

    Regarding "anything else is rounded to nearest 200"... no idea what you are saying there. If you mean round to nearest 200 if greater than 179, then you'll want to use an IF statement and test for the incoming value, along with invalid values, i.e., negatives.

    Edited: Welcome to the forums
    Above provided to get your feet wet. Since this looks like homework, you likely won't get anyone here to do it all for you.
    Last edited by LaVolpe; Jul 9th, 2019 at 06:30 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,901

    Re: How to round to the nearest 40 using Basic ocde

    Quote Originally Posted by LaVolpe View Post
    Since this looks like homework
    LIMS Basic seems to be a scripting language used in this software that is a Laboratory information management system.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2019
    Posts
    2

    Re: How to round to the nearest 40 using Basic ocde

    I thank you for your help; though slightly condescending, it does provide me with an avenue to try.

    This is not homework, rather a project given to me with no proper notice or training. I am trying to develop a calculation within a Lab Information management system, using the native LIMS basic language.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width