Return value for functions

Posted by Edgeofforever on Sat 01 Jan 2005 07:37 PM — 3 posts, 29,014 views.

#0
This is basically what I'm trying to do:

weaponOne = Call weaponConvert(weaponOne)


sub weaponConvert(wName, newName)

if wName = "the ancient sword of the kami" then
newName = "Kami"
end if
end sub


I want weaponOne to go from "the ancient sword of the kami" to "kami". I don't see exactly how to do this with the vbscripting, this format just gives me an error.

Appriciate any help.
Poland #1
That's because in VB (and VBScript) you don't use subs this way, you need to use functions, like:

Function weaponConvert(wName)
if Name = "the ancient sword of the kami" then weaponConvert = "Kami"
End Function

Also, if you use the 'if.. then.. else' subroutine within one line, you don't need to use 'end if'.
You can also use functions in place of subs - this way you can trap errors and easily get return values, like:
if LoadFile(file)=true then ..
#2
Works perfectly, thanks for the advice.