Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42215

VS 2010 too many arguments specified, check source?

$
0
0
so i have this little application here. pretty simple, it requires a few inputs then passes the arguments along to a dos app and goes from there.
having issues with part of the argument inputting though. the dos part of it says too many arguments specified and i cant figure out why. :eek2:

can someone take a look and see where the fault lies? thanks.

the gui calls a file named me7_95040.exe and inputs the arguments.
im having problem with the write portion. a correct input would be "me7_95040.exe -p 2 -b 57600 --bootmode -w filename.bin"
i attached both current exe files.

source:

Code:

Imports System.IO.Ports
Imports System.Text.RegularExpressions

Public Class frmMain



    Public fileName As String = Nothing

    Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
        If validateSelections("read") Then
            Dim connType As String
            Dim port As String
            Dim RegexObj As New Regex("[^\d]")
            port = RegexObj.Replace(cboPorts.Text, "")

            If rdoBootmode.Checked Then
                connType = "--bootmode"
            Else
                connType = "--OBD"
            End If
            runME7_EEPROM(port, cboBauds.Text, "-r", connType)
        End If
    End Sub

    Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click
        If validateSelections("write") Then
            Dim connType As String
            Dim port As String

            Dim fd As OpenFileDialog = New OpenFileDialog()

            fd.Title = "Select e2p File"
            fd.InitialDirectory = My.Application.Info.DirectoryPath
            fd.Filter = "BIN files (*.bin*)|*.bin*|BIN files (*.bin*)|*.bin*"
            fd.FilterIndex = 2
            fd.RestoreDirectory = True

            If fd.ShowDialog() = DialogResult.OK Then
                fileName = fd.FileName
            End If

            Dim RegexObj As New Regex("[^\d]")
            port = RegexObj.Replace(cboPorts.Text, "")

            If rdoBootmode.Checked Then
                connType = "--bootmode"
            Else
                connType = "--OBD"
            End If
            runME7_EEPROM(port, cboBauds.Text, connType, "-w", fileName)
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        setDefaults()
    End Sub
    Private Sub setDefaults()

        cboBauds.SelectedIndex = -1
        rdoBootmode.Checked = True
        rdoOBD.Checked = False
        txtOutput.Clear()

        loadPorts()
        cboPorts.SelectedIndex = -1
        cboPorts.Focus()
    End Sub
    Private Function validateSelections(ByVal txtToggle As String) As Boolean

        If cboPorts.Text = "" Then
            MessageBox.Show("Please select a appropriate comm port.", "Comm port Error!", MessageBoxButtons.OK)
            cboBauds.Focus()
            Return False

        ElseIf cboBauds.Text = "" Then
            MessageBox.Show("Please select a appropriate baud rate.", "Baud rate Error!", MessageBoxButtons.OK)
            cboBauds.Focus()
            Return False

        ElseIf txtFileName.Text = "" Then
            If txtToggle = "read" Then
                MessageBox.Show("Please enter a filename to save.", "Filename Error!", MessageBoxButtons.OK)
                txtFileName.Focus()
                Return False
            Else
                Return True
            End If
        Else
            Return True

        End If

    End Function

    Private Sub rdoBootmode_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoBootmode.CheckedChanged
        If rdoOBD.Checked = True Then
            rdoOBD.Checked = False
            rdoBootmode.Checked = True
        End If
    End Sub

    Private Sub rdoOBD_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoOBD.CheckedChanged
        If rdoBootmode.Checked = True Then
            rdoBootmode.Checked = False
            rdoOBD.Checked = True
        End If
    End Sub
    Private Sub loadPorts()
        Dim ports As String() = SerialPort.GetPortNames()
        Dim port As String
        Array.Reverse(ports)
        For Each port In ports
            cboPorts.Items.Add(port)
        Next port

    End Sub

    Private Sub runME7_EEPROM(ByVal port As String, ByVal baud As String, ByVal ReadOrWrite As String, ByVal mode As String, Optional ByVal fileName As String = "")
        Dim procString As String
        procString = Strings.Trim(mode) & " -b " & Strings.Trim(baud) & " -p " & Strings.Trim(port) & " " & ReadOrWrite & " "
        If Strings.Trim(ReadOrWrite) = "-r" Then
            procString = procString + Strings.Trim(txtFileName.Text)
        Else
            procString = procString + Strings.Trim(fileName)
        End If
        Dim me7ProcRun As New Process
        Dim me7ProcStartInfo As New ProcessStartInfo()
        With me7ProcStartInfo
            .FileName = "me7_95040.exe"
            .UseShellExecute = False
            .CreateNoWindow = True
            .Arguments = procString
            .RedirectStandardOutput = True
        End With
        Try
            me7ProcRun.StartInfo = me7ProcStartInfo
            me7ProcRun.Start()

            Dim strOut As String = Nothing
            Dim rdOut As IO.StreamReader = me7ProcRun.StandardOutput

            Do While rdOut.EndOfStream = False
                strOut = strOut + rdOut.ReadLine() + vbNewLine
            Loop

            txtOutput.Text = strOut
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error!", MessageBoxButtons.OK)
            setDefaults()
        End Try
    End Sub

    Private Sub txtOutput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtOutput.TextChanged

    End Sub

    Private Sub lblFileName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblFileName.Click

    End Sub
End Class

Attached Files

Viewing all articles
Browse latest Browse all 42215

Trending Articles