Page 1 of 1

Adding string$ variable and string together

Posted: Sat Jan 19, 2008 11:04 pm
by PresFox
Hello

I am trying to compile this:

Code: Select all

runprogram(configvalue$(0)+"mysqld-nt.exe")
configvalue$(0) holds the path, mysqld-nt.exe is the filename. However, this doesnt work, what is the way to get string variables and strings together?

Regards

Posted: Sat Jan 19, 2008 11:11 pm
by AND51
Maybe the path does not end with a backslash.
Example:

Code: Select all

path$="C:\WINDOWS"
file$="notepad.exe"

Debug path$+file$

RunProgram(path$+file$) ; DOESN'T WORK
This won't work, because every path in PureBasic usually ends with a trailing Backslash!

Two codes how to check+correct this mistake:

Code: Select all

path$="C:\WINDOWS"

If Right(path$, 1) <> "\"
   path$+"\"
EndIf

Debug path$
Shorter, but Windows-Only:

Code: Select all

path$="C:\WINDOWS"

PathAddBackslash_(@path$)

Debug path$
Both codes do the same. The second code uses API, so it should be faster, but it's only available on Windows. If you use the second code, don't forget the @ in front of the variable name!
PathAddBackslash_() expects the pointer to the variable, that's why you must type the @.



If a missing backslash is not the reason, the variable could be emptry or the path/file doesn't exist. Another reason might be insufficient rights or ressources to execute the destination program.

Posted: Sat Jan 19, 2008 11:21 pm
by PresFox
Got it fixed, thank you for your help

Posted: Sat Jan 19, 2008 11:31 pm
by AND51
No problem, mate. :wink:

Posted: Sat Jan 19, 2008 11:36 pm
by freak
The API code is dangerous, as it will write over the end of the PB allocated memory.
You are asking for trouble with that one.

Posted: Sun Jan 20, 2008 1:09 am
by AND51
Oh, you mean the API replaces the trailing NULL with a Backslash?
I though this almost, but I wasn't sure. Although I never had problem with it, I now tend to use the PB code then.
Thank you for this information! :)

Posted: Sun Jan 20, 2008 2:10 am
by PB
@AND51: See this post where PathAddBackslash was discussed in detail:
http://www.purebasic.fr/english/viewtopic.php?t=25578