0

Apologies if this is really simple but I'm fairly new to programming. I've created a program that uses an open dialog box and outputs the names of the file to a textbox.

Where I'm having issues is trying to get the textbox to display more than one line as all it seems to be doing is writing one line in the textbox.

The code I'm using is below, could someone please advise what I need to change so that I can get this to work.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click    
    Dim strFileName As String

    OpenFD.Multiselect = True
    OpenFD.InitialDirectory = "\\server\filename\"
    OpenFD.Title = "Open a Text File"
    OpenFD.Filter = "Text Files(.txt)|*.txt"
    Dim DidWork As Integer = OpenFD.ShowDialog()
    strFileName = OpenFD.FileName


    If DidWork = DialogResult.Cancel Then

        MsgBox("Cancel Button Clicked")

    Else

        strFileName = OpenFD.FileName
        TextBox1.Text = strFileName += 1

    End If
End Sub

I've managed to get everything else to work correctly but it's just this one thing.

SysDragon
  • 9,692
  • 15
  • 60
  • 89
user2039317
  • 3
  • 1
  • 4

2 Answers2

1
Dim strFileName() As String

'...

Dim DidWork As Integer = OpenFD.ShowDialog()

If DidWork = DialogResult.Cancel Then
    MsgBox("Cancel Button Clicked")
Else
    strFileName = OpenFD.FileNames
    TextBox1.Multiline = True
    TextBox1.Text = ""

    For Each sFile as String in strFileName
        TextBox1.Text &= sFile & System.Enviroment.NewLine()
    Next
End If
SysDragon
  • 9,692
  • 15
  • 60
  • 89
  • Thanks for this. It's saying 'Environment' is not a member of 'System' and asking me to generate 'Class Environment'. If I do that, then all the code falls over. – user2039317 Feb 04 '13 at 11:09
  • Hi, Sorry.. Not sure what's happened but it's working now and I haven't changed anything. Thanks again for your help. – user2039317 Feb 04 '13 at 11:14
  • Glad to help. Please mark the answer as correct if thats the case. Thanks. – SysDragon Feb 04 '13 at 11:26
  • you can use `chr(10)` instead of `system.enviroment.newline` – Pezzzz Feb 04 '13 at 12:47
  • 1
    @Pezzzz No. On Windows systems, a newline marker is `CR` + `LF` (ascii character 13 and 10), not just `LF` (ascii 10). – sloth Feb 04 '13 at 14:31
0

Set TextBox.Multiline property to True

Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162