Private Sub Command3_Click()
Dim a, b As Integer
Dim divide As Double
a = 10
b = 3
divide = div(a, b)
MsgBox (divide)
End Sub

Private Function div(a, b)
div = a / b
End Function

Function return type by default is integer in C. & if we do the same prog in C,it returns 3 not 3.333333....But in VB the function return type is Variant????Right or Wrong?

variant is data type which can hold the data of any type like integer,string,double...Right or wrong?

I want that the fn. return can integer value only by default, if we write
Private Function div(a, b) as double

only then it returns decimal value??

Plz reply frnds.:(

Recommended Answers

All 6 Replies

see the answers in inline...

Function return type by default is integer in C. & if we do the same prog in C,it returns 3 not 3.333333....But in VB the function return type is Variant????Right or Wrong?

yes its right

variant is data type which can hold the data of any type like integer,string,double...Right or wrong?

yes its right again

I want that the fn. return can integer value only by default, if we write
Private Function div(a, b) as double

only then it returns decimal value??

Plz reply frnds.:(

Just a little modification in your code and you will get exactly what you want..

Private Function div(byval a as integer,byval b as integer)as integer
div = a / b
End Function

or you can try this also...

Private Function div(byval a as integer,byval b as integer)
div = a / b
div=Cint(div)
End Function

hope this helps..

regards
Shouvik

Ya,it helped me, thx. I m fresher in Vb, but with all ur frnds help,thru daniweb, I M sure I will be Expert one day....

you r welcome.
just ask us whenever you stucked..

bye.

and one more thing my frnd, if you got your answer then please mark this thread as solved. this will help other perople to easily find solved threads which signifies a definite solution to their problem having same doubts like you.

regards
Shouvik

Hi,I mark as Solved,pls tell me 4m where we can see these are solved or unsolved

when you open this forum you can see a Solved word just beside the threads. this signifies that the related thread has been solved. it means the person which started the thread has got an answer for his/her problem/question that he/she posted.

or another way,
when you login using your username and password, you can see there is a link just below the page which is Show Solved Threads. just click this and you can see all threads solved so far.

ok....
bye

regards
Shouvik

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.