473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

creating a function in a module then call from a form

Hello,

I am trying to create a math function in a module and then call the function from a VB form. For some reason I get errors each time I try.

on the VB Form

A = 1
B = 2

how do I call the functin below?

Module
Function Add (A,B)
Add = A + B
End Function
Mar 11 '08 #1
9 1659
kadghar
1,295 Expert 1GB
Hello,

I am trying to create a math function in a module and then call the function from a VB form. For some reason I get errors each time I try.

on the VB Form

A = 1
B = 2

how do I call the functin below?

Module
Function Add (A,B)
Add = A + B
End Function
the functions are public by default, any way, specify it, just to make sure, you should also change the functions name, since Add is a method.
may be this will do:

Expand|Select|Wrap|Line Numbers
  1. Public Function MyAdd(A, B)
  2.     MyAdd = A + B
  3. End Function
Also check the event's sub where you're calling it from.
HTH
Mar 12 '08 #2
the functions are public by default, any way, specify it, just to make sure, you should also change the functions name, since Add is a method.
may be this will do:

Expand|Select|Wrap|Line Numbers
  1. Public Function MyAdd(A, B)
  2.     MyAdd = A + B
  3. End Function
Also check the event's sub where you're calling it from.
HTH
Thank you for the help. How do I call MyAdd in the VB5 form?
Mar 12 '08 #3
Thank you for the help. How do I call MyAdd in the VB5 form?
Here is the code from the Sub on the main form,

Private Sub Command2_Click()

Dim A, B, x
Dim MyAdd
A = 2
B = 2

Label11.Caption = Format(MyAdd, "##0.0")

It will not return a value to label 11.
Mar 12 '08 #4
kadghar
1,295 Expert 1GB
Here is the code from the Sub on the main form,
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2.  
  3.     Dim A, B, x
  4.     'Dim MyAdd <-- no need to do this
  5.     A = 2
  6.     B = 2
  7.  
  8.     Label11.Caption = Format(MyAdd(A,B), "##0.0") 'Call the function properly
  9. end sub
HTH
Mar 12 '08 #5
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2.  
  3.     Dim A, B, x
  4.     'Dim MyAdd <-- no need to do this
  5.     A = 2
  6.     B = 2
  7.  
  8.     Label11.Caption = Format(MyAdd(A,B), "##0.0") 'Call the function properly
  9. end sub
HTH
To: HTH, thank you provided the information that I needed.
Mar 12 '08 #6
kadghar
1,295 Expert 1GB
To: HTH, thank you provided the information that I needed.
HTH = hope that helps.

call me Kad,
Mar 12 '08 #7
Killer42
8,435 Expert 8TB
HTH = hope that helps.
Hahaha... last year I was calling someone "Tia" for a while, not realising it was short for thanks in advance.
Mar 14 '08 #8
kadghar
1,295 Expert 1GB
Hahaha... last year I was calling someone "Tia" for a while, not realising it was short for thanks in advance.
Just for you not to feel bad, 'Tía' means 'aunt' in Spanish. And in Spain (not in Mexico), they call friends Tío (he) or Tía (she), it's like saying buddy.
Mar 14 '08 #9
Killer42
8,435 Expert 8TB
In this case, the poster had simply put TIA at the end meaning Thanks In Advance, and I misinterpreted it. But thanks for trying... :)
Mar 14 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
4
by: Edvard Majakari | last post by:
Greetings, fellow Pythonistas! I'm about to create three modules. As an avid TDD fan I'd like to create typical 'use-cases' for each of these modules. One of them is rather large, and I wondered...
0
by: James Fortune | last post by:
Here is an example of Access creating a single page PDF file. The text in the textbox is scaled to fit horizontally into a grey box 100 pixels wide that is fontsize pixels high. Clicking the...
2
by: Lumpierbritches | last post by:
I have code that is currently placed in the OnClose Event, and it's duplicated in multiple forms, I would like to convert it to a module and call that module instead of copy and pasting the code....
3
by: Richard Hollenbeck | last post by:
Back in the old days before I started learning about menubars (the day before yesterday,) I based all my operations on command buttons on the forms. Now the forms are all cluttered up with buttons...
2
by: MLH | last post by:
I would like to call a function stored in a form module in Access 2.0 from an Access 2.0 procedure in a global module. Function EmailTheOutletters () in module AppSpecific... .... 560 SSNtext...
7
by: deko | last post by:
I have a function with a number of long loops. While the function is running, I want to be able to click a Stop button and exit the function as quickly as possible. The abbreviated code looks...
5
by: tech.rawsteak | last post by:
I have a function that retrieves a user's login name from their workstation and looks it up on an employee table to return their full name (ie: jsmith -John Smith). Their full name is then...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.