?
Solved

i want to know whether ordinery function slows down a appplication

Posted on 2004-10-01
4
Medium Priority
?
192 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 60 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

777 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