Adding string$ variable and string together

Just starting out? Need help? Post your questions and find answers here.
PresFox
User
User
Posts: 33
Joined: Sat Jan 19, 2008 9:30 am

Adding string$ variable and string together

Post 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
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post 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.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
PresFox
User
User
Posts: 33
Joined: Sat Jan 19, 2008 9:30 am

Post by PresFox »

Got it fixed, thank you for your help
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

No problem, mate. :wink:
PB 4.30

Code: Select all

onErrorGoto(?Fred)
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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.
quidquid Latine dictum sit altum videtur
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post 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! :)
PB 4.30

Code: Select all

onErrorGoto(?Fred)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

@AND51: See this post where PathAddBackslash was discussed in detail:
http://www.purebasic.fr/english/viewtopic.php?t=25578
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply