|
-
Nov 19th, 2011, 10:51 AM
#1
Thread Starter
Member
Rounding Up function ??
Guys will u please let me know the function (in vba) equivalent to the "roundup" fn available in excell
i.e i need to round up a value may it be 3.00009 or 3.99999999 the result should be ---> 4
i can make it up with an if statement but it looks handy with a roundup function
Secondly I want to create different modules of a program that i have coded into a command button click.
my purpose is that, the module1 i have created should access the variables declared under the userforum---->cmd_clk
and also the value i got from the module1 should be accessible to the userforum-->cmd_clk
Eg.
under userform---> cmd_clk
dim a as integer
dim b as integer
dim c as integer
a=a1.text ' a1 is the text box used in userform
call m1
c=a+b 'the value of b should be got from module1
Msgbox(c)
end sub
under ---> Module1
**** m1()
b=2*a 'b should access the declaration what i made in the cmd_clk
msgbox(b)
end sub
I hope you understand my question.It may be silly for u guys...but i'm new to these coding and stuffs...please just tolerate this..
waiting for your reply.
Last edited by dmanojkmr; Nov 21st, 2011 at 12:42 PM.
-
Nov 19th, 2011, 01:06 PM
#2
Re: Rounding Up function ??
RoundUp
There is a function which truncate all decimalparts (Int(Yournumber), if you add just 1 to the result you are done.
Variable-Scope
Declare all variables in the module and then your done.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Nov 19th, 2011, 09:34 PM
#3
Member
Re: Rounding Up function ??
Last edited by yo mismo; Nov 19th, 2011 at 10:13 PM.
-
Nov 19th, 2011, 10:30 PM
#4
Thread Starter
Member
Re: Rounding Up function ??
@ceiling fn is used in excel not in vba i want something similar to it......int(value)+1 is one way of rounding up a value...but i want to know where there is a direct fn or not.....
and for my second question
if i declare the variables in 1 module can other models access these variables and the values in one module are to accessed by other modules and forms.....
will u please take some more time to correct the above given example of mine to my requirement..
Last edited by dmanojkmr; Nov 19th, 2011 at 10:40 PM.
-
Nov 20th, 2011, 01:53 AM
#5
Member
Re: Rounding Up function ??
No there is not a premade function in vba. Only round and fix function.
I cannot fix any example because i do not do vba since access 2000 and i have no office at hand.
-
Nov 20th, 2011, 02:29 AM
#6
Thread Starter
Member
Re: Rounding Up function ??
it needn't be a VBA code...try a vb program for it...i'll change it accordingly....
-
Nov 20th, 2011, 04:32 AM
#7
Re: Rounding Up function ??
you can use excel ceiling function in excel vba
vb Code:
rndup = worksheetfunction.ceiling(1.1, 1)
if i declare the variables in 1 module can other models access these variables
yes if declared public
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 20th, 2011, 05:24 AM
#8
Thread Starter
Member
Re: Rounding Up function ??
@westconn
did u read my first post ( above)
can u make a code as per my requirement ????
-
Nov 20th, 2011, 05:46 AM
#9
Re: Rounding Up function ??
can u make a code as per my requirement ????
what is your requirement, that is not covered by suggestions above?
in excel VBA, you can use either ceiling or roundup worksheetfunctions, or the int function as suggested by opus
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 20th, 2011, 07:04 AM
#10
Thread Starter
Member
Re: Rounding Up function ??
 Originally Posted by dmanojkmr
Secondly I want to create different modules of a program that i have coded into a command button click.
my purpose is that, the module1 i have created should access the variables declared under the userforum---->cmd_clk
and also the value i got from the module1 should be accessible to the userforum-->cmd_clk
Eg.
under userform---> cmd_clk
dim a as integer
dim b as integer
dim c as integer
a=a1.text ' a1 is the text box used in userform
call m1
c=a+b 'the value of b should be got from module1
Msgbox(c)
end sub
under ---> Module1
**** m1()
b=2*a 'b should access the declaration what i made in the cmd_clk
msgbox(b)
end sub
I hope you understand my question.It may be silly for u guys...but i'm new to these coding and stuffs...please just tolerate this..
waiting for your reply.
I want u to make the above codes as per my requirement....
-
Nov 20th, 2011, 03:37 PM
#11
Re: Rounding Up function ??
b=2*a 'b should access the declaration what i made in the cmd_clk
best way is to pass a to function, rather than using global variables,
c=a+b 'the value of b should be got from module1
b should be the return value from a function
vb Code:
'under userform---> cmd_clk dim a as integer dim b as integer dim c as integer a=a1.text ' a1 is the text box used in userform b = m1(a) c=a+b 'the value of b should be got from module1 Msgbox(c) end sub
vb Code:
public funtion m1(a as integer)as integer b=2*a 'b should access the declaration what i made in the cmd_clk msgbox(b) m1 = b end sub
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 20th, 2011, 03:42 PM
#12
Re: Rounding Up function ??
Can't you just use the built in rounding function and pass it the number to be rounded + .499999999 ?
Like: MyNumber = Round(TheNumber + 0.4999999)
Which means if TheNumber is 3.1 or even 3.9 then MyNumber will be 4.0 in either case
-
Nov 20th, 2011, 09:08 PM
#13
Thread Starter
Member
Re: Rounding Up function ??
wow...gr8 thankyou west conn and all other who supported it.....I'l b grateful
I'll try the above code and reply you...
thankyou again..
-
Nov 21st, 2011, 12:47 PM
#14
Thread Starter
Member
Re: Rounding Up function ??
Hey...guys i got a another problem.....
actually i thought of using the int()+1 function. but if i want to have the value of 2.1 as 3 but this int+1 fn. makes even 2.0 as 3 which is not desirable .....
also i can't use the worksheet fn. as i'm in another software called MicroStation a drafting software for mechanical engineers....
but though i used an if else statement to solve this prob...but it would be nice to have a handy function like Roundup as in excel.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|