none
creating a sub procedure and getting an error RRS feed

  • Question

  • I'm trying to create a sub procedure, followed by a function procedure, but keep getting the errors

    • 'Argument not specified for parameter 'iMnth' of 'Public Function calcInv(nUns As Double, iMnth As String) As Double'
    • 'Argument not specified for parameter 'nUns' of 'Public Function calcInv(nUns As Double, iMnth As String) As Double'
    • 'Argument not specified for parameter 'iMnth' of 'Public Function calcInv(nUns As Double, iMnth As String) As Double'

    I have the following:

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            displayAmount()
        End Sub
    
        Sub displayAmount()
    
    
    
    
    
    
    
            TextBox3.Text = (((("Amount due in " & TextBox2.Text) & " ") & (calcInv(CDbl(TextBox1.Text)) & (calcInv.ToString("C")))))
        End Sub
    
        Function calcInv(nUns As Double, iMnth As String) As Double
            Dim amountdue As Double
            If iMnth = "June" Or iMnth = "July" Then
                If nUns > 100 Then
    
                    amountdue = (nUns * 3)
                Else
    
                    amountdue = (nUns * 2)
                End If
            Else
    
                amountdue = (nUns * 2.1)
            End If
            Return amountdue
        End Function
    
    End Class

    The bold & underlined 'calcInv' is where the error lines are showing up. I'm not really sure what to do to fix it.

    Thursday, February 21, 2019 10:31 PM

Answers

  •  Your calcInv function requires 2 different pieces of data to be passed to it and you are only passing 1 to it.  It requires 1 Double type value and 1 String type value.  I think what you want to do in that line is simply this...

    TextBox3.Text = "Amount due in " & TextBox2.Text & " " & calcInv(CDbl(TextBox1.Text), TextBox2.Text).ToString("C2")
     


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Thursday, February 21, 2019 11:06 PM
    • Marked as answer by knenok Friday, February 22, 2019 12:03 AM
    Thursday, February 21, 2019 10:46 PM

All replies

  •  Your calcInv function requires 2 different pieces of data to be passed to it and you are only passing 1 to it.  It requires 1 Double type value and 1 String type value.  I think what you want to do in that line is simply this...

    TextBox3.Text = "Amount due in " & TextBox2.Text & " " & calcInv(CDbl(TextBox1.Text), TextBox2.Text).ToString("C2")
     


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Thursday, February 21, 2019 11:06 PM
    • Marked as answer by knenok Friday, February 22, 2019 12:03 AM
    Thursday, February 21, 2019 10:46 PM
  • Hi

    Your function calcInv needs 2 parameters - a Double and a String, and you have one call with one parameter and a second call with no parameters.

    Something like  (guess)

    TextBox3.Text = "Amount due in " & TextBox2.Text & " " & calcInv(CDbl(TextBox1.Text), TextBox2.Text)

    Regards Les, Livingston, Scotland

    Thursday, February 21, 2019 10:47 PM