Discussion:
Return Value of Function ?!?!
(too old to reply)
Alen Hopek
2006-01-18 17:46:58 UTC
Permalink
Hello,

I have a problem with my function here.
The Function read out a Description from a Norton Ghost Image File.

This works mostly with this Function. The Problem is when i try
to return the value "Chars" out of my function at the end of the
Function like:
...
FUNCTION = Chars
END FUNCTION

then i get an Error:
Relational operator expected
Line 230: FUNCTION = Chars

when i try it like this:
FUNCTION = LEN(Char)
the function returns a numeric value.

The Return Value of this function should be the Variable "Chars".

Any Idea what went wrong ?

Greetings
Alen Hopek



FUNCTION read_gho_description(ghofile AS ASCIIZ * 50) AS LONG
LOCAL Chars AS ASCIIZ * 255
LOCAL start, ende, laenge AS INTEGER

start = &h100
ende = &h1FE
laenge = ende - start

OPEN "C:\" + ghofile FOR BINARY AS #1
SEEK #1, start
GET$ #1, laenge, Chars
REPLACE CHR$(0) WITH CHR$(32) IN Chars
CLOSE #1

FUNCTION = LEN(Chars)
END FUNCTION
buck huffman
2006-01-18 18:27:26 UTC
Permalink
If you want to get the numeric long integer value of chars, try

FUNCTION = VAL(chars)

if you're trying to retrieve the text or "string" representation of chars then
you need to declare the function as such, like this

DECLARE FUNCTION read_gho_description(ghofile AS ASCIIZ * 50) AS STRING

Note the "AS STRING" on the end. Then the rest is simple.

FUNCTION read_gho_description(ghofile AS ASCIIZ * 50) AS STRING
...
FUNCTION = chars
END FUNCTION


I hope this helps
Buck
Greg Neill
2006-01-18 18:26:40 UTC
Permalink
Post by Alen Hopek
Hello,
I have a problem with my function here.
The Function read out a Description from a Norton Ghost Image File.
This works mostly with this Function. The Problem is when i try
to return the value "Chars" out of my function at the end of the
...
FUNCTION = Chars
END FUNCTION
Relational operator expected
Line 230: FUNCTION = Chars
FUNCTION = LEN(Char)
the function returns a numeric value.
The Return Value of this function should be the Variable "Chars".
Any Idea what went wrong ?
Did you define your function type as STRING when you
tried to return a string?

For example:

FUNCTION MYFUN() as STRING
DIM Z as ASCIIZ*10
Z = "12345"
MYFUN = "AAA" & Z & "BBB"
END FUNCTION

CLS
PRINT ":";MYFUN();":"
END

Will produce:

:AAA12345BBB:

Loading...