Solved

i want to know whether ordinery function slows down a appplication

Posted on 2004-10-01
4
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Accepted Solution

by:
sgayatri earned 20 total points
ID: 12198610
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
ID: 12199283
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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

695 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