locked
application and file path RRS feed

  • Question

  • Hi! I do not want to write in every button same part of code:

    ChDir("C:\Programme\ProgramName\place")
            Const quote As String = """"
            Dim path As String = "--pause-exit --config " & quote & "C:\Programme\ProgramName\place\folder\file.file" & quote
            Process.Start("C:\Programme\ProgramName\bin\program.exe", path)

    and I want to make a function and to everybutton just use function. But in every button place and folder / file.file are changing. How could I do that?


     I have more than 200 buttons! So I would be grateful for fast reply.

    • Edited by MatthewGr Tuesday, September 24, 2013 9:03 AM
    Tuesday, September 24, 2013 9:00 AM

Answers

  • Closing topic - it is working.

       Dim pathFile As String

    Function Y()

            Dim name() As String = Split(pathFile, "-")
            ChDir("C:\Programme\xxx\yyy\" + name(0))
            Const quote As String = """"
            Dim path As String = "--pause-exit --config " & quote & "C:\Programme\xxx\yyy\" + name(0) + "\" + name(1) & quote
            Process.Start("C:\Programme\xxx\zzz\prog.exe", path)

    Return 0

    End function

    in button:

          pathFile = "ooo-ppp"
            Y()


    • Edited by MatthewGr Tuesday, September 24, 2013 10:09 AM
    • Marked as answer by Angie Xu Thursday, October 10, 2013 7:39 AM
    Tuesday, September 24, 2013 10:08 AM
  • I would recommend against using a private field to store the value first and then call the method. You should just add a parameter to your method:

    Private Function Y(filePath As String) As Integer
       ...
    End Function

    and then call the method with an argument:

    Me.Y("ooo-ppp")


    Justin Anderson, LightSwitch Development Team

    • Marked as answer by Angie Xu Monday, September 30, 2013 5:05 AM
    Wednesday, September 25, 2013 7:10 AM
    Moderator

All replies

  • Hi

    You can write the function and pass the place and file paths as parameters so that you can call the function by passing the corresponding parameters.

    Hope this helps. Good luck 

    Tuesday, September 24, 2013 9:07 AM
  • That is my idea, but not working. Could you help me with code of that function?
    Tuesday, September 24, 2013 9:14 AM
  • I would recommend configuring this via data. You could make it so that you could change the path and the filenames without resorting to code changes, if you deployed to different environments.

    You would pass a key or enum to the function. The function retrieves configured data  and runs your code.

    Just a suggestion.


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.


    • Edited by Xpert360 Tuesday, September 24, 2013 9:48 AM
    Tuesday, September 24, 2013 9:47 AM
  • Closing topic - it is working.

       Dim pathFile As String

    Function Y()

            Dim name() As String = Split(pathFile, "-")
            ChDir("C:\Programme\xxx\yyy\" + name(0))
            Const quote As String = """"
            Dim path As String = "--pause-exit --config " & quote & "C:\Programme\xxx\yyy\" + name(0) + "\" + name(1) & quote
            Process.Start("C:\Programme\xxx\zzz\prog.exe", path)

    Return 0

    End function

    in button:

          pathFile = "ooo-ppp"
            Y()


    • Edited by MatthewGr Tuesday, September 24, 2013 10:09 AM
    • Marked as answer by Angie Xu Thursday, October 10, 2013 7:39 AM
    Tuesday, September 24, 2013 10:08 AM
  • I would recommend against using a private field to store the value first and then call the method. You should just add a parameter to your method:

    Private Function Y(filePath As String) As Integer
       ...
    End Function

    and then call the method with an argument:

    Me.Y("ooo-ppp")


    Justin Anderson, LightSwitch Development Team

    • Marked as answer by Angie Xu Monday, September 30, 2013 5:05 AM
    Wednesday, September 25, 2013 7:10 AM
    Moderator