Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add()
#1
Hehe Tongue You wanted more tutorials Wink hehe.

Add:
Code:
Public Function Add(ByVal a As Long, ByVal b As Long)
Add = a + b
End Function

Usage:
Code:
Dim i As Long
i = Add(3, 5)

"i" would result in 8 Smile Aint I good ?
Reply
#2
Congradulations, you managed to needless slow down and obfuscate the most simple form of math. :lol: :wink:

Though learning how to use functions appropriate is a pretty good thing. Just keep in mind that if you have:

Code:
Public Function MyFunc()

You need to define what type of format it is working in as MyFunc will be handled as a variable. In your example, you are making "Add" a variant (default variable format of a variable without a specified format).

Code:
Public Function MyFunc() As Long

Would make Add return a long.

Sorry, just wanted to point that out in case you didn't know. :wink:
Reply
#3
I never really added that to my mind.. that part has been so obvious so I kinda never learned it Tongue So thanks for reminding me.
Reply
#4
At least Add() looks professional Tongue hehe
Reply
#5
Code:
Public Function Add(ByVal a As Long, ByVal b As Long)
        Add = a + b
End Function


Awww there ya go Verrigan... lol
Reply
#6
Thats too big of an indent Tongue
Reply
#7
and you forgot as long after the function Tongue
Reply
#8
Too long of an indent cuz I did it manually with the spacebar lmao.

Code:
Public Function Add(ByVal a As Long, ByVal b As Long) As Long
     Add = a + b
End Function
There...
Reply
#9
i HATE when people don't nest their code...

isn't it faster just to do

i = 5+3

instead of

i = Add(5,3)

it's less to type... but congrats for submitting something new :wink:
Reply
#10
Haha..Obsidian, the whole topic was a joke. And you were the only one who didnt get it Tongue
Reply
#11
oh no i figured it was... :roll:
Reply
#12
We cant leave subtraction out of the mix.

Code:
Public Function Subtract(ByVal a As Long, ByVal b As Long) as Long
         Subtract = a - b
End Function

Code:
Public Function Multiply(ByVal a As Long, ByVal b As Long) as Long
         Multiply = a * b
End Function

Code:
Public Function Divide(ByVal a As Long, ByVal b As Long) as Long
         Divide = a / b
End Function

There now the basic math functions don't feel left out.
Reply
#13
I dare somebody to do square root without the "Sqrt()" functon...
Reply
#14
Code:
Public Function SquareRoot(ByVal a As Double) as Double
         SquareRoot=a^(1/2)
End Function
Reply
#15
Rofl, how about percentage? :p
Reply
#16
http://en.wikipedia.org/wiki/Methods_of ... uare_roots
Reply
#17
Code:
Public Sub TestOne(ByVal Index As Long)
Dim a As Single
    
    a = Sqr(LookupTable(Index))
    
End Sub

Code:
Public Sub TestTwo(ByVal Index As Long)
Dim a As Single
    
    a = LookupTable(Index) ^ 0.5
    
End Sub

Code:
%Faster   -98.4|   -98.4|   -98.4|   -98.4|   -98.4|   -98.4|   -98.5|   -98.4|   -98.4|   -98.4
Test1       162|     160|     169|     161|     160|     161|     159|     161|     160|     161
Test2     10272|   10262|   10263|   10283|   10281|   10274|   10278|   10267|   10258|   10265

Nope. Not by a long shot. :wink:
Reply
#18
Leighland Wrote:Rofl, how about percentage? :p

What do you mean?
Reply
#19
Right, raising to the .5 is generally much slower in most programing languages than the buit in sqrt function.
Reply
#20
Compiled, 5000 loops per each result. :wink:
Reply
#21
Haha.. So my Add command developed itself into a massive math lesson. Well, one thing is good about these. They can easilt be used for sadscript Tongue
Reply
#22
Why, does functions run faster in VB.net?
Reply
#23
I think he means that its not good in VB. But in VB.net.. maybe I missunderstood it..
Reply
#24
William Wrote:I think he means that its not good in VB. But in VB.net.. maybe I missunderstood it..

I think you misunderstood Tongue
Reply
#25
Yeah, guessed so. You ment that it doesn't support Math.Tan etc?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)