Sign in to follow this  
Followers 0
ThaSatelliteGuy

Creating New Functions?

4 posts in this topic

I realize that this prog has no GOTO cmd, so I have learned the looping trick to return where I was. (Like a Main Menu)

Is there a way to create Subs and Funtions? Cuz it would clean up my programming A LOT! I am a real neat freak, and ADHD to boot, and I hate getting to a point where I can't keep straight what my code is doing!

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

;create a function by doing this

Func OpentheFile($s_FileName,$i_OpenValue = 0);These are the values that you input, the second value is optional, so if you don't use it, it defaults to 0

;Put whatever you want the function to do in here:
Local $h_File
$h_File = FileOpen($s_FileName,$i_OpenValue )
Return $h_File
;you could also do everything above in the following line
;Return FileOpen($s_FileName,$i_OpenValue )
EndFunc

;Now to call the function, you do something like this:

Dim $h_OpenFile = OpentheFile("test.txt"); i made the second parameter optional by making it equal to something when i declared the function, it will now open it with a second value of 0

FileClose($h_OpenFile)

;you can also open

Dim $h_OpenFile2 = OpentheFile("test.txt",1);since the second parameter is specified, the file will now open with the second parameter equal to 1.  It will ignore the fact that you had it equal to zero when you declared the function.

FileClose($h_OpenFile2)

There is a little example i whipped up.

-The Kandie Man

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

ok, so....

Func OpentheFile($s_FileName,$i_OpenValue = 0) defines the funciton CALL and any defaults I want to build in....

EndFunc - obviously closes out the Function definition,

Local $h_File - ? I assume this would be like a DIM, but DIMmed only within this function, right?

$h_File = FileOpen($s_FileName,$i_OpenValue ) - No Brainer - action within the function

Return $h_File is obviously what it'll give me back

OMG! Thank you, this'll clean up my codes a LOT!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0