Jump to content
Developer Wiki and Function Reference Links ×

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?

Link to comment

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

Link to comment

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;

Link to comment

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?

Link to comment

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

Link to comment

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

Link to comment

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.

Link to comment

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

Link to comment

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

Link to comment

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.

Link to comment

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.

×
×
  • Create New...