Solved

i want to know whether ordinery function slows down a appplication

Posted on 2004-10-01
4
180 Views
Last Modified: 2013-11-13
Hi experts,
 my question is that iam having a lot of function in my form to reduce complexity and have genral flexibility i placed them in modules.. the think i want to know is does this function  really help in speeding upof a application as it is reducing complexity code wise.... so i want to know having more function is help ful or not

2.. i like have some sample codes for function passing mutilple parameters and returning multiple parameters

looking for  a solution


regards
vairavamuthu
0
Comment
Question by:vairavamuthu
4 Comments
 
LVL 3

Accepted Solution

by:
sgayatri earned 20 total points
Comment Utility
You can use procedures or functions for reducing complexity in code and better readability.
Functions always return single value.
for ex:
private function abc () as string

abc = "xxxx"
end function

If you want a function to return values
then you must declare them as byref parameters
In General declarations,
dim x as integer
dim y as string
dim func_val as string
...
...
...
''' somewhere in your code call the function abc
x=10
y="somestring"

func_val = abc(x,y)  '' you are passing x, y to function called abc

private function abc (byref x as integer, byref y as string) as string

''' use x and y here
...
...
''' change x,y here
x=12
y="someotherstring"
abc = "xxxx"
end function

Hope I am clear in my explanation

0
 
LVL 16

Expert Comment

by:JohnBPrice
Comment Utility
Functions reduce complexity, but slightly slows down your application.

VB is not the fastest language in the world, and if your app is performance critical, VB is not a great choice, but if your application is otherwise fine, but you have one bit that is too slow, you might be able to speed it up.  For example, look at this code, a simple loop doing simple math, one way in a function, the other with inline code.  The function loop takes about 16 seconds on my machine, the inline loop takes 2 seconds.  e.g. each function call takes about 0.00000056 seconds.  Not much, but it adds up if you are doing 25,000,000 calls.

Option Explicit

Private Sub CmdWithFunction_Click()
    Dim starttime As Date
    Dim stoptime As Date
    Dim i As Integer, j As Integer
    Dim result As Long
    Screen.MousePointer = vbHourglass
    starttime = Time
        For i = 1 To 5000
            For j = 1 To 5000
                result = MyFunction(i, j)
            Next j
        Next i
    stoptime = Time
    Screen.MousePointer = vbDefault
    MsgBox DateDiff("s", starttime, stoptime)
End Sub

Function MyFunction(i As Integer, j As Integer) As Long
    MyFunction = i + j
End Function

Private Sub CmdNoFunction_Click()
    Dim starttime As Date
    Dim stoptime As Date
    Dim i As Integer, j As Integer
    Dim result As Long
    Screen.MousePointer = vbHourglass
    starttime = Time
        For i = 1 To 5000
            For j = 1 To 5000
                result = i + j
            Next j
        Next i
    stoptime = Time
    Screen.MousePointer = vbDefault
    MsgBox DateDiff("s", starttime, stoptime)

End Sub
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you don't know how to downgrade, my instructions below should be helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now