Jump to content
Sign in to follow this  
Dieter @ DWorks

FUNCTIONS

Recommended Posts

Why can't I use functions on their own?

I always get the errormessage: 'expect the beginning of a statement' OR 'expected a procedure'

So functions can't be used on their own, they need to be in procedures?

If this is so, then can someone answer this question:

How can I use a function in a subroutine? I want a pio to call the function for a certain value.

Any other suggestions?

Share this post


Link to post

Short answer: Because they are functions and return a value.

Long answer: In order to use a function, you must set a variable to the return value

MyVariable := Function(Parameter);

Or you must use the return value of the function as input to a procedure.

Message(Gettype(FSActLayer);

will work by itself as a one line script.

You can only define a variable inside of a Procedure. Therefore, to use a function by itself, you need at least the following code:

Procedure Test;

Var MyVariable:Boolean; {or whatever type you need}

Begin

MyVariable:=Function(Parameter);

End;

Run(Test);

It is just the way it is.

Pat

Share this post


Link to post

Well put Pat. I was just going to add that it does make sense. If you have a function that returns say 12 as the value, the compiler sees a line of code that says 12, and in effect says "yeah..so what...whaddya wanna do with that?" You get the same kind of errors if you have a line that just says: NIL;

Share this post


Link to post

Well, I know that! I know how to use functions, I only want to place them in a subroutine and then with {$include} use them in my main program.

But I need to see if there is no syntax errors when making the functions, but if you just type the function withouth a procedure around it, The compiler gives errors.

So my question was: How to use functions in a subroutine?

Share this post


Link to post

You can place functions in an $Include file without wrapping them in a procedure. I do it extensively in my Reshaper program - hundreds of them. Try placing a blank line at the end of each included file. A little white space at the end of each makes sure the compiler won't join two keywords when it reassembles your code.

Raymond

Share this post


Link to post

If you are using $Include files, you need to be using something other than the built in VS editor. It will not save them as files on disk as you need them to $Include.

If you inport and $Include file to the built in editor and try to compile it, yes, it will give errors, because is it not a legal procedure.

If you want to test a procedure, wrap a test Procedure (see my post of yesterday) around it first. You can even leave it in the $Inlcude file and bring it in that way. You can even test individual functions one ata time if you want.

One of the best ways to work on routines (especially PIOs) is to use an external editor, Make the basic PIO have nothing other than the $Include statement, and turn on the VS Compiler option that recompiles on every execution. That way, you can change the code and run it, without ever having to change the mode that VW is running in. No long delay while the PIO list builds, no VS Editor popping up.

Pat

Share this post


Link to post

Sorry for the mis-understanding,but from the info in your first post it wasn't clear that you did know how to use them. You didn't mention include, and subroutines can be in the main script or in a source file. But they must be declared at a certain point in the the main script regardless. After the definition statements and before the main script body.

At the risk of stating the obvious, the minimum requirement for a script (for the most part) is a Procedure(name) statement, a main script body (begin and end) and a Run(name) statement.

It sounds like your source file is basically a simple list of subroutines, and you want to test these independant from the main script. If so you could create a tester shell with the include and compile that.

Hope I'm not making more erroneous assumptions.

Share this post


Link to post

I worked it out, I need to compile the file that includes the functions I want to use. And it works fine now, thx.

And to Pat: Can you tell me some external editor? This may come in handy and be a faster way to write scripts.

Share this post


Link to post

For Windows, the one I have heard about, but not used is called UltraEdit. I believe there are some scripts you can use with it to do syntax coloring availoable at vectordepot.com (search on ultraedit).

For Mac, there are resources available for BBEdit, TextWrangler and TextMate.

Here is a link to the archive of the VectorScript Mail list that talks about how to use an external editor and include files. < http://lists.nemetschek.net/cgi-bin/wa.exe?A2=ind0509&L=VECTORSCRIPT-L&P=R872&I=-3&X=45176B395E3B19F7C9 >

Pat

Share this post


Link to post

That's too bad D. This is an excellent resource with searchable archive going back almost 10 years. Generally more active than this forum, with frequent contributions from some very knowledgable people. I'd say it would be well worth getting some kind of registerable e-mail address for you. You'd probably have an answer to your post below by now.

Also, you can choose to use it without receiving emails, but still being able to post them. You still need an address to join.

Charles

Share this post


Link to post

Well, I just subscribed using a Yahoo.com address. It is a three step process.

1. Sign up for a password and confirm it.

2. Sign up for the Vectorscript list and confirm it.

3. Search the Archive

4. (if you don't want to get the mail) go the the Subscribers Corner and change your settings to No Mail.

Pat

Share this post


Link to post

I use TextPad on the PC. It took me 10-20 minutes to create a file that gave me syntax colouring and line numbering.

NotePAD2 is also good as it doesnt need to install on your harddrive, you can run it from your USB stick - good for portability. Syntax colouring can be done here also but requires a compiler but at least you get line numbering.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...