1. #1
    Nny's Avatar
    Registered
    28/10/07
    Location
    Gent
    Posts
    132
    iTrader
    1 (100%)
    Mentioned
    0 Post(s)
    Reputation
    0/1

    Vb.net Commandline Argumenten meegeven aan een windows form

    Ik ben bezig met een kleine windows form applicatie die checkt hoeveel tekens er in een file zitten. Ik zou graag de applicatie ook via commandline kunnen opstarten en hierbij een bestandslocatie meegeven.

    Enig idee hoe ik dit kan doen?
    Hier vind je de code die ik tot nu toe heb.
    Code:
    Public Class CharacterCounter
    
        Private Sub BrowseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrowseButton.Click
            Dim commandLineArgs As String() = Environment.GetCommandLineArgs()
    
            Try
                If ContentOpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
                    Me.InputFileTextBox.Text = ContentOpenFileDialog.FileName
                End If
    
                Dim path As String = ContentOpenFileDialog.FileName
                Dim myReader As New System.IO.StreamReader(path)
                Dim fileContent As String = myReader.ReadToEnd()
    
                Me.CountTextBox.Text = fileContent.Length
    
            Catch ex As System.IO.FileNotFoundException
                MessageBox.Show(ex.ToString())
                MessageBox.Show("Gelieve een bestand te selecteren.")
            Catch ex As System.ArgumentException
                MessageBox.Show(ex.ToString())
                MessageBox.Show("Er is een onverklaarbare fout opgetreden, start het programma opnieuw op aub.")
            Catch ex As Exception
                MessageBox.Show(ex.ToString())
                MessageBox.Show("Er is een fout opgetreden, probeer opnieuw")
            End Try
        End Sub
    
    
    End Class
    Lucky charms of DOOM!
    no votes  

  2. #2
    Mee's Avatar
    Registered
    19/02/03
    Location
    Herent
    Posts
    13,647
    iTrader
    8 (100%)
    Mentioned
    0 Post(s)
    Reputation
    0/17
    Google wat beter leren gebruiken...

    How to: Access Command-Line Arguments (Visual Basic)

    Maw:
    Code:
    For Each argument As String In My.Application.CommandLineArgs
    no votes  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in