PDA

View Full Version : Solved: Comple error



nickxx4360
10-14-2008, 05:21 AM
I get a "comple: Variable not defined" when i run this code

Sub CubeRoot()
Num = InputBox("Enter a positive number")
MsgBox Num ^ (1 / 3) & " is the cube root."
End Sub


what am I doing wrong??

Thanks

CreganTur
10-14-2008, 05:24 AM
The issue is that you have a variable- Num- in your code, but you don't dimension it within the sub.

Try:

Sub CubeRoot()
Dim Num As Long
Num = InputBox("Enter a positive number")
MsgBox Num ^ (1 / 3) & " is the cube root."
End Sub

GTO
10-14-2008, 05:29 AM
At the top of the module, you will see 'Option Explicit' which once stated, requires declaration of variables (a good idea).

Above "Sub..." enter "Dim Num" and your code will work.

GTO
10-14-2008, 05:39 AM
@ CreganTur:

Sorry - slow typist/laptop

@ nickxx4360:

Randy's explanation is better. You'll want to read help file reference declaring variables and scope of visibility.

A good day to all,

Mark

nickxx4360
10-14-2008, 05:42 AM
Both answers worked for me, many thanks!!

Is there a good beginner book i could get my hands on??

I got this code straight out the excel VBA programming book for dummies.

Thanks again.

GTO
10-14-2008, 05:50 AM
What Office/Excel version are you using? (ie - 2000/2003/2007)

Only my personal opinion, but I thought 2000's help was pretty good. Of course with '03, there's more connectivity to MS articles via internet...

On the (IN actually) the 2000 help files, it takes a bit to find stuff occassionally, but good examples (again, only in my opinion).

no books to recommend, sorry.

Mark

nickxx4360
10-14-2008, 05:52 AM
I am using Excel 2003.

I guess I will learn by trial and error. :-)

Thanks again.

GTO
10-14-2008, 06:03 AM
Greetings Nick,

Just noticed your join date. No reason for total trial-and-error. As a 'guest' for a couple of years, and member for like five minutes (okay a month or so), I can assure you that you will meet some fine folks here.

I have watched as questions get answered thru a series of questions/answers, and have always been impressed with the 'in-the-service-of-others' attitude most often displayed.

Have a terrific day, must hit the rack,

Mark

CreganTur
10-14-2008, 06:33 AM
Nick,

I would highly reccomend the book Access 2003: Programming by Example with VBA, XML, and ASP.

It takes you through the basics of VBA and then goes into more indepth programming constructs, like ADO and DAO connections, interacting with external office apps (Word, Excel).

It does require you to have a good grasp of Access's front end capabilities. If you want a good book for Access' front-end then I would suggest Microsoft Access 2003 Step by Step. It's a guide book for the MOS: Access 2003 exam, but it's got some very good information.

nickxx4360
10-14-2008, 08:28 AM
Guys, Thanks again.

This site is awesome. The people here are very very helpful and I am glad I found this site.

Cregan,

I won't be using access at all so you would still recommend that book?

CreganTur
10-14-2008, 08:36 AM
Cregan,

I won't be using access at all so you would still recommend that book?

Hmmm... forgot I was in the Excel forum when I posted that:doh:

I highly reccomend the VBA Training and Certification that's available through VBAX- click on 'certifiable' in my sig to go to the site. I took the training and it was very informative. It's also Excel specific.

nickxx4360
10-14-2008, 08:40 AM
Thanks, I will check it out.

That access book got very good reviews BTW ;-)