locked
Syntax error when using For Each RRS feed

  • Question

  • I want to write the path of a file that has been selected from an openfiledialog to an .ini file and it worked. But I now want to do it for each file that's selected as my openfiledialog has multiselect to true. I used For Each but it gave me a Syntax error at the end of 'For Each OpenFileDialog1.FileName'.

    Code:

            For Each OpenFileDialog1.FileName 
                Dim fullPath As String
                fullPath = Path.GetFullPath(OpenFileDialog1.FileName)
                My.Computer.FileSystem.WriteAllText("SInject settings.ini", fullPath & vbCrLf, True)
            Next

    Friday, January 4, 2013 5:12 PM

Answers

  • Thats because OpenFileDialog1.FileName only returns a single string and a For Each statement must specify a item variable and a collection to iterate.

    You want to do:

    For Each fileName As String In OpenFileDialog1.FileNames

    Then the "fileName" varaible will contain the path of each selected file.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Proposed as answer by Andrew Morton Friday, January 4, 2013 6:08 PM
    • Marked as answer by Rionto Friday, January 4, 2013 6:30 PM
    Friday, January 4, 2013 5:16 PM