Results 1 to 17 of 17

Thread: [resolved]Argument not Optional....

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Location
    Hidden in a dark corner, of a dark room, in a dark house, on a dark island, on a dark planet.
    Posts
    92

    Resolved [resolved]Argument not Optional....

    Everytime I go to use the button in my form it says Argument not Optional and highlights "Private Sub btnCalc_Click()" and I don't know why
    Last edited by Kesk; May 2nd, 2006 at 02:18 PM.
    If there is somebody here more of a noob you can have my spot as noob.

  2. #2
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Argument not Optional....

    post all the code from the sub...
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Location
    Hidden in a dark corner, of a dark room, in a dark house, on a dark island, on a dark planet.
    Posts
    92

    Re: Argument not Optional....

    VB Code:
    1. Private Sub btnCalc_Click()
    2.     Dim a As Double
    3.     Dim b As Double
    4.     Dim c As Double
    5.     Dim p As Double
    6.     Dim s As Double
    7.     a = 0
    8.     b = 0
    9.     c = 0
    10.     p = 0
    11.     s = 0
    12.    
    13.     a = Val(txtNum1)
    14.     b = Val(txtNum2)
    15.     c = Val(txtNum2)
    16.  
    17.     Label2 = CStr(a + b)
    18. End Sub
    Last edited by Kesk; May 1st, 2006 at 04:00 PM.
    If there is somebody here more of a noob you can have my spot as noob.

  4. #4
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Argument not Optional....

    hmm.. well u got me?? (Works fine for me)


    try copying the whole sub to notepad.. save and close the project (and VB)
    open it back up..
    run it.. click the button

    nothing? good

    paste the code back in then run.. see what happens?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,425

    Re: Argument not Optional....

    That looks ok???

    Justa few points:
    a = Val(txtNum1.Text)
    Label2.Caption = CStr(a + b)

    And you may find it usefull to use Hungarian Notation for yout Variables, and give them usefull names.
    Lets say that 'a' will hold the Price value, and is a Double datay type, therefore: dblPrice dbl signifies its a Double, and Price lets you know what it holds
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,425

    Re: Argument not Optional....

    In addition to what Static asked, do the other buttons work?
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Argument not Optional....

    you've probably got one of the controls as a control array.

    have any of them got a value in the Index Property?

  8. #8
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Argument not Optional....

    Are you by chance calling the sub from a click event of another button?

  9. #9
    Member
    Join Date
    Apr 2006
    Location
    Serbia
    Posts
    32

    Re: Argument not Optional....

    you're getting that error cuz one of the TextBoxs don't contain numeric value and you're passing that value to Val() which excepts numeric input, you should first check for that values if ther're numeric with IsNumeric...
    if thats not working, well.... i dunno what is the error (try debugging)

  10. #10
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Argument not Optional....

    that's not the problem, Val won't error on string values:

    Val("hello") = 0
    Val("1hello") = 1
    Val("hello1") = 0

  11. #11
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,425

    Re: Argument not Optional....

    Quote Originally Posted by bushmobile
    that's not the problem, Val won't error on string values:
    @krckoorascic - And... a Val() line wasnt the one highlited (as stated in the first post)
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

  12. #12
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Argument not Optional....

    Probably btnCalc has it's index set. so it is considered part of as control array.
    If this is the only btnCalc you have, just remove the index.
    Frans

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Location
    Hidden in a dark corner, of a dark room, in a dark house, on a dark island, on a dark planet.
    Posts
    92

    Re: Argument not Optional....

    It highlights the btnCalc line as yellow and selects one of the Val() statements with the usual blue highlight. It also didn't have an index.

    VB Code:
    1. [COLOR=Orange]Private Sub btnCalc_Click()[/COLOR]  
    2.     Dim a As Double
    3.     Dim b As Double
    4.     Dim c As Double
    5.     Dim p As Double
    6.     Dim s As Double
    7.     a = 0
    8.     b = 0
    9.     c = 0
    10.     p = 0
    11.     s = 0
    12.    
    13.     a = Val(txtNum1[COLOR=Lime].Text[/COLOR])
    14.     b = Val(txtNum2.Text)
    15.     c = Val(txtNum2.Text)
    16.  
    17.     Label2.Caption = CStr(a + b)
    18. End Sub

    the lime is what is selected and the orange is what is highlighted yellow
    Last edited by Kesk; May 1st, 2006 at 04:04 PM.
    If there is somebody here more of a noob you can have my spot as noob.

  14. #14
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Argument not Optional....

    could you please upload the form here?? maybe then we could help you!!
    Show Appreciation. Rate Posts.

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Location
    Hidden in a dark corner, of a dark room, in a dark house, on a dark island, on a dark planet.
    Posts
    92

    Re: Argument not Optional....

    The tex boxes had their indexes set
    If there is somebody here more of a noob you can have my spot as noob.

  16. #16
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Argument not Optional....

    then it should be something like:
    VB Code:
    1. a = Val(txtNum1([i]index value[/i]).Text)
    2.     b = Val(txtNum2([i]index value[/i]).Text)
    3.     c = Val(txtNum2([i]index value[/i]).Text)

    EDIT: sorry it happens with me when i try editing some else's code
    Show Appreciation. Rate Posts.

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Location
    Hidden in a dark corner, of a dark room, in a dark house, on a dark island, on a dark planet.
    Posts
    92

    Re: Argument not Optional....

    I just changed their index values
    If there is somebody here more of a noob you can have my spot as noob.

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