Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 11th, 2006, 05:23 AM
Registered User
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB code that calls a function

Plesae, can somebody help me write a VB6 Code to call a Function or Procedure.

Thanks

 
Old January 11th, 2006, 06:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Here's kinda' the basics. Notice that functions return a value, where as sub procedures don't. If you pass a variable to a procedure by reference, however, you can modify the variable's value in the calling procedure. This has the same effect as assigning the return value of a function to the variable.

Run the code by typing either CallProcedure or CallFunction in the Immediate Window and hitting enter. Set a break point on the procedure or function header and step through the code to see how they work. Watch the variable values change in the Locals Window.

Sub CallProcedure()
    Dim intX As Integer, intY As Integer, intSum As Integer

    intX = 2
    intY = 2

    'intSum us passed by reference
    Call sCalculate(intX, intY, intSum)

    Debug.Print intSum

End Sub

Sub CallFunction()
    Dim intX As Integer, intY As Integer, intSum As Integer

    intX = 2
    intY = 2

    ' Assign functions return value to a variable
    intSum = fCalculate(intX, intY)

    Debug.Print intSum

End Sub

Sub sCalculate(ByVal intA As Integer, _
                    ByVal intB As Integer, _
                    ByRef intAddress As Integer)

    intAddress = intA + intB

End Sub

Function fCalculate(ByVal intA As Integer, _
                          ByVal intB As Integer) As Integer

    fCalculate = intA + intB

End Function

HTH,

Bob






Similar Threads
Thread Thread Starter Forum Replies Last Post
Nesting tags / function calls possible? Obsidian3d XSLT 4 March 30th, 2007 03:46 PM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
ASP Page hangs when calls a vb component king05 Classic ASP Components 0 March 28th, 2005 01:07 PM
function calls ricmar Access VBA 3 September 24th, 2004 09:15 AM
XSL calls java function - prob vetrikam XSLT 2 October 9th, 2003 10:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.