Sign in to follow this  
Followers 0
Blackstar

Whats wrong here?

2 posts in this topic

Im trying to clean up codes a bit without having to open files with 24 lines of code that does same job as 6 liners so I wanted to convert it into 1 function that only take 6 lines of code but I could not get the function to work...

Originally I had this:

CODE

$s_Path = @ScriptDir & "\summary.txt"

If Not FileExists($s_Path) Then

MsgBox(4096, "Error!", "summary.txt does not exist.")

Else

Run('notepad "summary.txt"')

EndIf

I wanted to call this function below but how? And also why Run doesn't work when opening notepad on that file:

Example:

CODE

;Open Files types: summary.txt=1, names.txt=2, settings.ini=3, status.log=4

OpenFile(1)

CODE

Func OpenFile($filetype)

Local $Files = StringSplit("summary.txt,names.txt,settings.ini,status.log", ","), $filestype, $s_Path

$s_Path = @ScriptDir & "\" & $Files[$filetype]

If Not FileExists($s_Path) Then

MsgBox(4096, "Error!", $Files[$filestype] & " does not exist.")

Else

Run('notepad.exe' $Files[$filestype])

EndIf

EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

OpenFile("summary.txt,names.txt,settings.ini,status.log")

Func OpenFile($arg)
    $Files = StringSplit($arg, ",")
    For $i = 1 To $Files[0]
        $s_Path = @ScriptDir & '\' & $Files[$i]
        If FileExists($s_Path) Then
            Run('notepad.exe ' & $s_Path)  ;edit - forgot the &
        Else
            MsgBox(4096, "Error!", $s_Path & " does not exist.")
        EndIf
    Next
EndFunc

edit - Maybe not exactly what you were looking for, but it should give you an idea of how to do it your way.

Edited by xcal

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