Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

VBA Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mikeyj - 14 Jan 2005 02:53 GMT
Hello, I am just starting out trying to learn a little VBA code and was
trying to understand an example at the following address:

http://office.microsoft.com/en-us/assistance/HA010188011033.aspx

I typed the code as requested but I am receiving the following error:

"Compile Error, sub or function not defined"

the hilighted area points to the word "AdditionResult".  I am not sure how
to make it work.  I tried typing it carefully a couple of different ways and
even just copied the code directly from the webpage, but it will not work.  
what am I doing wrong?
saschamps9903 - 14 Jan 2005 03:09 GMT
of note, I am using Windows XP and Office XP 2002, forgot to mention this in
my original post.

> Hello, I am just starting out trying to learn a little VBA code and was
> trying to understand an example at the following address:
[quoted text clipped - 9 lines]
> even just copied the code directly from the webpage, but it will not work.  
> what am I doing wrong?
Greg Maxey - 14 Jan 2005 03:40 GMT
Mike,

Hard to say exactly what you are doing wrong without seeing your code.  The
problem with posting your code is that it sometimes doesn't look the same on
both ends.  I pasted the code from the site you mentioned and abbreviated it
some in hopes that each line of execution will fit on one line.  I mostly
just substitued shorter terms.  Note I also changed integer throughout to
Double.  While the example you provide will return 2+2=4 it will also return
2.1+2.1=4.  Double is just a different data type that will provide better
results.  See if you can paste the following in your VBA editor and get it
to work.

Sub CallAR()

Dim iFN As Double 'instead of integer
Dim iSN As Double 'instead of integer
iFN = InputBox(Prompt:="Type the first number.")
iSN = InputBox(Prompt:="Type the second number.")
MsgBox Prompt:=iFN & " + " & iSN & " = " & AR(A:=iFN, B:=iSN)

End Sub

Public Function AR(ByVal A As Double, ByVal B As Double) As Double
AR = A + B
End Function

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> Hello, I am just starting out trying to learn a little VBA code and
> was trying to understand an example at the following address:
[quoted text clipped - 9 lines]
> different ways and even just copied the code directly from the
> webpage, but it will not work. what am I doing wrong?
saschamps9903 - 14 Jan 2005 04:33 GMT
Thanks Greg, it worked but I don't understand how.  If you look at the
original code, my problem seemed to come when I got to "MsgBox Prompt" and so
on through the code.  From first Dim to the prompt of type the second
integer, it was working perfectly.  I changed the code back to the original
way it was written except I left your change where A:=intFirstNumber,
B:=intSecondNumber and it worked.  As someone who is just starting to dip
their toe in the VBA waters, could you recommend any reading material that
will help me learn VBA?  

> Mike,
>
[quoted text clipped - 35 lines]
> > different ways and even just copied the code directly from the
> > webpage, but it will not work. what am I doing wrong?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.