Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27153

Command line args not working once built

$
0
0
i have some command line arguments that work to launch my program if i click on a file for the program but it does not load the data from this file into the program. If I am debugging the app it works fine. BUt once built it only load the program.
Code:

Imports System.IO
Imports System.Drawing


Public Class MyTVShowList
    Private mDataTable As New DataTable
    Private mBindingSource As New BindingSource
    Dim mIsEditMode As Boolean
    Dim mIndex, bCount As Integer
    Dim dChanged As Boolean

    Private mstrFileName As String
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''Load Program''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub TV_Show_List_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'This section Loads the program and checks to see if a file was clicked on and if so reads the file
        Dim bc As New DataGridViewButtonColumn
        bc.Tag = False 'button does not work if false
        BindGrid() 'set up the Data grid view
        Dim args = Environment.GetCommandLineArgs()
        ' --------
        For Each sArg As String In args
            MessageBox.Show(sArg)
        Next
        ' --------
        'The first commandline argument is the path of the EXE.
        'If there is just one more argument and it's a file, read it as text and display it.
        If args.Length = 2 AndAlso File.Exists(args(1)) Then 'IF the arguments are more than one and the file exits
            ReadFile(args(1)) 'Read the file
        End If
    End Sub
    Private Sub BindGrid()
        'This section sets up the DataGrid View with the appropriate columns and binds it to a DataSource
        mDataTable.Columns.Add("TV Show")
        mDataTable.Columns.Add("Air Day")
        mDataTable.Columns.Add("Next Episode")
        mDataTable.Columns.Add("Next Air Date")
        mDataTable.Columns.Add("Web Link")
        mBindingSource.DataSource = mDataTable
        ShowListView.DataSource = mDataTable
    End Sub


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''Menu'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub ReadFile(ByVal strFileName As String)
        'This section tells the program what to do with the data from the opened file and where to put it.
        If IO.File.Exists(strFileName) Then
            Try
                For Each line As String In System.IO.File.ReadAllLines(strFileName)
                    mDataTable.Rows.Add(line.Split(","))
                Next
            Catch ex As Exception
                MessageBox.Show("Cannot read file from disk. Original error: " & ex.Message)
            End Try
        Else
            MessageBox.Show("Cannot find " & strFileName, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

As you can see I have a MSG box that should show me the args. Again it works in debug but once built I only get the first MSG box showing the path of my program. I never get the second msgbox showing the path of the file like I should.

Viewing all articles
Browse latest Browse all 27153

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>