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?

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 :wave:

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.

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

Quote:

Originally Posted by

**LaVolpe**
Since this looks like homework

**LIMS Basic** seems to be a scripting language used in this software that is a Laboratory information management system.

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.