Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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 August 10th, 2003, 11:43 PM
Authorized User
 
Join Date: Jul 2003
Location: Metropolis, ILLinois, USA.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calling subs & Functions

I can't call a sub or function in a module from a form even thought I've made the sub or function Public. How do I call a sub or function from a form thats in a Module or Vice Versa?

It took me 74 years to get this stupid!
__________________
It took me 74 years to get this stupid!
 
Old August 11th, 2003, 04:08 AM
Registered User
 
Join Date: Aug 2003
Location: Vadodara, Gujarat, India.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think it's so simple, if i'm not stupid,

just type function name and pass para.

ex. MyFunction(para1,para2)
or abc=MyFunction() if it returns something

or if module is created,

   myModule.MyFunction(para1,para2)
or abc=myModule.MyFunction()

is it ok ?

Vipul.
 
Old August 11th, 2003, 08:53 AM
Authorized User
 
Join Date: Jun 2003
Location: , FL, USA.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One other thing to add to Vipul's answer. If the function is on another form than the one you are calling it from you will need to use this syntax...

Call myForm.myFunction

along with any parameters that you may be passing.

Kenny Alligood
 
Old August 11th, 2003, 08:56 AM
Authorized User
 
Join Date: Aug 2003
Location: Penn Yan, New York, USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Zooker,

Calling Subs & Functions can be somewhat tricky until you get the hang of it. Generally, a function is returning a value and takes the same form as built-in functions:
  x = FunctionToDoSomething(WhatI'mSendingIt)

if you Call the same function (i.e., you don't expect a return value) it would look like this:

  Call FunctionToDoSomething "WhatI'mSendingIt"

Note how the parentheses are no longer present.

While a Subroutine is simply performing a function -- with or without passed parameters.

Then there's the matter of Scope (where these procedures are placed); How parameters are specified in the declaration, etc. etc.

For more info recommend http://www.vba-programmer.com
(there's an excellent discussion on Functions and Subs)

CarlR

 
Old August 20th, 2003, 07:09 PM
Authorized User
 
Join Date: Jul 2003
Location: Metropolis, ILLinois, USA.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Splash Sreen is on Form 1 along with a DriveListBox which is made invisible

'---------------------------------------------------------------
Form1


Private Sub Form_Load()
   Drive1_Change When Form1 Loads it should call Drive1 Change which In turn call s FindDir But it
                                      Doesn't
End Sub


Private Sub Drive1_Change()
ListCount = 0
Item$ = Drive1.List(ListCount)
'Form1.Print Item$
'CurrentY = 600
'Form1.Print "This should work"
FindDir (Item$)
End Sub



'--------------------------------------------------------------------------------------
'Module1
Option Explicit
Public Item$



Sub FindDir(Item$)
'ListCount = 0
'Item$ = Drive1.List(ListCount)
CurrentY = 500
Form1.Print Item$
CurrentY = 900
Form1.Print "This should work"

End Sub
I just can't get the module to recognize Item$, Why? thank's for all the help ! !

It took me 74 years to get this stupid!




Similar Threads
Thread Thread Starter Forum Replies Last Post
Help calling and using a functions in visual c++ 6 method Visual C++ 0 July 8th, 2006 05:20 PM
Calling external classes and/or subs/funcs jmischo VBScript 2 December 16th, 2004 08:45 AM
Calling functions ejmichaud Access VBA 2 July 16th, 2004 10:03 AM
calling functions with conditions Toka1 Javascript How-To 2 February 5th, 2004 09:29 AM
Calling functions in Windows? jacob C# 0 November 5th, 2003 03:57 PM





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