Results 1 to 4 of 4

Thread: [RESOLVED] Argument not specified for parameter

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Location
    Mundelein, IL
    Posts
    3

    Resolved [RESOLVED] Argument not specified for parameter

    I'm making a console application, but I get the error shown below and I don't understand the problem.

    I will be passing command-line arguments like this:
    prog.exe 192.168.0.1 80 On

    Code:
    Imports System
    Imports System.Text
    Imports System.Net.Sockets
    
    Module Module1
    
        Public Sub Main()
            Dim arguments As [String]() = Environment.GetCommandLineArgs()
            Dim ip As String
            Dim port As String
    
            ip = Environment.GetCommandLineArgs(1)
            port = Environment.GetCommandLineArgs(2)
            If Environment.GetCommandLineArgs(3) = "On" Then
                sendRequest("ip, port, 1") <--- underlined and says "Argument not specified for parameter 'port' of 'Private Sub sendRequest(ip As String, port As Integer, val as String)
            End If
            If Environment.GetCommandLineArgs(3) = "Off" Then 
                sendRequest("ip, port, 0") <--- underline here too
            End If
        End Sub
    
        Private Sub sendRequest(ByVal ip As String, ByVal port As Integer, ByVal val As String)
    
            Dim tcpClient As New System.Net.Sockets.TcpClient()
    
            Try
                'Connect to device
                tcpClient.Connect(ip, port)
    
                If tcpClient.Connected Then ...
    Can someone point out where I went wrong?

  2. #2

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Location
    Mundelein, IL
    Posts
    3

    Re: Argument not specified for parameter

    Sorry, I'm new, I think it's relevant that I'm using VB 2010

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Argument not specified for parameter

    In this code:
    vb.net Code:
    1. sendRequest("ip, port, 1")
    you have created a literal String containing the text "ip, port, 1" and you're passing that as an argument. What you actually need to do is pass those three separate values as arguments:
    vb.net Code:
    1. sendRequest(ip, port, "1")
    That passes three arguments, i.e. the value of the 'ip' variable, the value of the 'port' variable and the literal string "1".

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Location
    Mundelein, IL
    Posts
    3

    Re: Argument not specified for parameter

    Thank you jmcilhinney, works perfectly!

Posting Permissions

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



Click Here to Expand Forum to Full Width