Page 1 of 1

Posted: Tue Aug 20, 2002 8:07 pm
by BackupUser
Restored from previous forum. Originally posted by cor.

What am I doing wrong?

I want to get a string return from a procedure

Error: trying to write a numeric value into a string

But I do return a string 'appdir' or ....

Code: Select all

Global appdir$
;
appdir$= GetAppDir()
;
Procedure.s GetAppDir()
appdir.s
appdir=Space(255)
GetCurrentDirectory_(255,appdir)
If Right(appdir,1)"\" 
 appdir=appdir+"\" 
EndIf
ProcedureReturn appdir 
EndProcedure

Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com

Posted: Tue Aug 20, 2002 8:12 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> Error: trying to write a numeric value into a string

Strange... I don't get that error from using your example, so it must
be due to something else in your code. But I'd suggest not using a
procedure anyway, because you only need to get appdir$ once because
it doesn't change during runtime. So just use this at the start of
your app and all will be well:

Code: Select all

Global appdir$
appdir$=space(255) : GetCurrentDirectory_(255,appdir$)
If right(appdir$,1)"\" : appdir$=appdir$+"\" : EndIf

PB - Registered PureBasic Coder

Posted: Tue Aug 20, 2002 8:25 pm
by BackupUser
Restored from previous forum. Originally posted by cor.

PB,

I think win98se and PB problem again.

Just run the code below and I get the error.

Trying to write a numeric value into a string.

I was using the code you gave me, but i wanted to do some tests with procedure string return.

And it seems it doesn't work on my system

Code: Select all

Declare GetAppDir()
;
Global appdir$
;
appdir$= GetAppDir()
;
End
;
;
Procedure.s GetAppDir()
appdir.s
appdir=Space(255)
GetCurrentDirectory_(255,appdir)
If Right(appdir,1)"\" 
 appdir=appdir+"\" 
EndIf
ProcedureReturn appdir 
EndProcedure


Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com

Posted: Tue Aug 20, 2002 8:38 pm
by BackupUser
Restored from previous forum. Originally posted by merendo.

Write: ProcedureReturn appdir$ ; you forgot the $

Cu @ll, merendo
--
I've been hiding - What am I hiding from???

Posted: Tue Aug 20, 2002 9:20 pm
by BackupUser
Restored from previous forum. Originally posted by cor.

merendo,

It must be appdir, because that's what I want to return from my procedure.

Cor
Originally posted by merendo

Write: ProcedureReturn appdir$ ; you forgot the $

Cu @ll, merendo
--
I've been hiding - What am I hiding from???
Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com

Posted: Tue Aug 20, 2002 9:48 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> I think win98se and PB problem again.

No, it's because you used Declare without .s, and so your declaration
is of numeric type.

Change Declare GetAppDir() to Declare.s GetAppDir() and it works.


PB - Registered PureBasic Coder

Posted: Tue Aug 20, 2002 10:03 pm
by BackupUser
Restored from previous forum. Originally posted by cor.

PB,

Thanks again, that works.

Where did you find the info that Declare.s can be used. I did not find it in the manual!!!

Using Windows 98 SE
Registered PB version : 3.2 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com

Posted: Tue Aug 20, 2002 10:15 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> Where did you find the info that Declare.s can be used.
> I did not find it in the manual!!!

It's in the manual, under the Procedure...EndProcedure link.
It says: Declare[.] name([,,...])

However, Declare is not in the manual's "Index" listing...


PB - Registered PureBasic Coder