Results 1 to 10 of 10

Thread: I know the logic, but its killing me why this isn't working

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    3

    I know the logic, but its killing me why this isn't working

    Basically I have a program thats supposed to gather information, both as string and as double.

    There are to be two sub procedures used

    One for gathering input and another for printing that input out into a listbox

    I'm not sure how to pass the information that I got using Input() sub procedure to Output() sub procedure.

    I know once I have it passed its a gravy train, all I need to use is ListBox1.Items.Add function to print what I want in the listbox


    However I'm getting errors like "Error 1 Too many arguments to 'Public Sub Input()'. C:\Users\Documents\Visual Studio 2008\ProjectsForm1.vb 16 15 Lab6
    "

    So the way he wants me to do this, I can't just declare variables on the class level as far as I'm aware. The input() sub procedure (which I have to declare myself, it's not built in) has to pass data to output() sub procedure again which I have to declare) and then I can get it from there.

    There are several variables

    Organization Visited, Dates, and Location are all string variables
    Expenses for meals and entertainment, airline fees, lodging, and taxi fares are all variables defined as Double


    heres my source code

    Public Class Lab6




    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

    lstResults.Visible = True ' list box is only to appear once button pushed
    lstResults.Items.Clear() ' clears out previous results
    Input()
    Output()




    End Sub
    Sub Input() ' gathers all the information the form asks for and assigns
    ' it to variables so that sub Output() can read the variables
    ' and then print them in the list box


    End Sub

    Sub Output() ' prints out items gathered from sub Input()
    ' * note that meal and entertainment expenses are only
    ' 50% decutable, not the whole amount
    ' Calculation must be made where 50% meals and entertainment expense = CDBL(meals and entertainment expenses) * .50

    End Sub


    End Class

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: I know the logic, but its killing me why this isn't working

    Use a different name besides Input and Output.... Input at least is actually a keyword in VB, and that may be causing a conflict.... You could try GetInput and SetOutput for your sub names

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    3

    Re: I know the logic, but its killing me why this isn't working

    Ok here is my source code now, I have changed the sub procedure names.

    As you can see I have declared seven variables... the first 3 are string variables as they relate to "Organization visited", "Dates", and "Location" and the next 4 are are double as they are "Expenses for meals and entertainment", "Airline Fee's", "Expenses for lodging" and "Taxi Fares"

    I have just assigned the first 3 varibles A,B,C as String = TextBox1.Text (2 and 3 for B and C)

    The next 4 I have assigned as Double using D,F,G,H as Double = CDBL(TextBox4.Text) (5,6,7 for F,G,H respectively)

    Now that I have gathered values for the variables in the sup procedure GatherData how do I pass that so that Sub ResultsShown can have access for me to do some calculations and print data in a list box using those variables. IE something like I wanted that ResultsShown to take the variable D and multiply it by .50 (because only 50% is deductible) and then print that in the list box

    Right now, if I use ResultsShown(A,B,C,D,F,G,H) it tells me

    "Error 1 Too many arguments to 'Public Sub ResultsShown()'. C:\Users\Documents\Visual Studio 2008\Projects\Form1.vb 15 22
    "



    Public Class Lab6

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
    Dim A As String
    Dim B As String
    Dim C As String
    Dim D As Double
    Dim F As Double
    Dim G As Double
    Dim H As Double

    lstResults.Visible = True ' list box is only to appear once button pushed
    lstResults.Items.Clear() ' clears out previous results
    GatherData(A, B, C, D, F, G, H)
    ResultsShown()




    End Sub
    Sub GatherData(ByVal A As String, ByVal B As String, ByVal C As String, ByVal G As Double, ByVal H As Double, ByVal D As Double, ByVal F As Double)

    ' gathers all the information the form asks for and assigns
    ' it to variables so that sub ResultsShown() can use the variable
    ' and then print them in the list box
    A = TextBox1.Text
    B = TextBox2.Text
    C = TextBox3.Text
    D = CDbl(TextBox4.Text)
    F = CDbl(TextBox5.Text)
    F = CDbl(TextBox6.Text)
    H = CDbl(TextBox7.Text)


    End Sub

    Sub ResultsShown() ' prints out items gathered from sub GatherData()
    ' * note that meal and entertainment expenses are only
    ' 50% decutable, not the whole amount


    End Sub


    End Class

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: I know the logic, but its killing me why this isn't working

    this looks like dot net code, ask a mod to move to correct forum
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: I know the logic, but its killing me why this isn't working

    a couple of things.... first for the sake of sanity - yours as well as anyone else... try giving the variable meaningful names....not jsut A B C D, etc... call them what they are, it'll make debugging easier later - trust me.

    Next.... I would declare the varaibles as private module level variables... and not inside the click sub....plus then you don't need to pass them around, they are just there....

    lastly, in your gaterdata sub, since you are assigning values to the variables, you should pass them as ByRef rather than ByVal.... otherwise, when you get back to the calling sub.... their values will be gone. But then, if you declare them at the module level, you don't need to pass them around and this becomes moot.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    3

    Re: I know the logic, but its killing me why this isn't working

    I had given the variables meaningful names, I just changed them to make it easier since I totally re wrote this code like 10 different times with none of them working. They will all be changed back to the text values "Organization attended" "Date" "Location" "Expenses of meals" "Airline Fee" "Lodging Fee" "Taxi Fee" after I have the code itself worked out... thats an easy thing to do.

    from what you say at a module level... I take this as making them global variables since this program has no other procedures then the ones I have declared now.

    The point isn't to just assign the variables and write everything inside the one private sub when the button... the point of using the sub procedures GatherData and ResultsShown to get data entered into the form and storing it as variables and then using another sub to read those variables, do a calculation and print values in a listbox. Using the subs would be pointless for this if they weren't gathering information and storing as variables.

    And yea, the ByRef thing was just an oversight... this program has me a little ticked off... since I know what I want to do is easy I just can't seem to make it work.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: I know the logic, but its killing me why this isn't working

    Quote Originally Posted by brkick2005
    I had given the variables meaningful names, I just changed them to make it easier since I totally re wrote this code like 10 different times with none of them working. They will all be changed back to the text values "Organization attended" "Date" "Location" "Expenses of meals" "Airline Fee" "Lodging Fee" "Taxi Fee" after I have the code itself worked out... thats an easy thing to do.
    OK.

    Quote Originally Posted by brkick2005
    from what you say at a module level... I take this as making them global variables since this program has no other procedures then the ones I have declared now.
    Not global... they would still be private, but declared at the top of the code, before any subs... it makes them available to any running code inside the file.

    Quote Originally Posted by brkick2005
    The point isn't to just assign the variables and write everything inside the one private sub when the button... the point of using the sub procedures GatherData and ResultsShown to get data entered into the form and storing it as variables and then using another sub to read those variables, do a calculation and print values in a listbox. Using the subs would be pointless for this if they weren't gathering information and storing as variables.
    I understand the point of the subs, and I don't think I ever mentioned getting rid of them. if this is in reference to what I think, what I meant was that if you use module-level variables, you wouldn't need to pass them around as parameters to the subs... that's not to say don't use the subs, or you wouldn't need them.... what you wouldn't need is the parameters.


    Quote Originally Posted by brkick2005
    And yea, the ByRef thing was just an oversight... this program has me a little ticked off... since I know what I want to do is easy I just can't seem to make it work.
    It comes with experience and learning some of those quirks... I've been doing this a long time, and I still get tripped up on some of the simple things.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: I know the logic, but its killing me why this isn't working

    Quote Originally Posted by westconn1
    this looks like dot net code, ask a mod to move to correct forum
    While correct (look at the sub start lines) the code within the sub is not specific to VB.NET and there is no reason why he shouldn't be able to ask here as it doesn't use anything not present in VB6 :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: I know the logic, but its killing me why this isn't working

    Thread moved from 'VB6 and Earlier' forum to VB.Net (VB2002 and later) forum

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: I know the logic, but its killing me why this isn't working

    So you have a class, declare the variables as such:
    Code:
    Public Class lab6
     Private A As String
     Private B As String
     Private C As String
     Private D As Double
     Private F As Double
     Private G As Double
     Private H As Double
    
     'Now for the sub
     Sub GatherData() 
      dim d2 as double 
      ' gathers all the information the form asks for and assigns
      ' it to variables so that sub ResultsShown() can use the variable
      ' and then print them in the list box
      A = TextBox1.Text
      B = TextBox2.Text
      C = TextBox3.Text
      If Double.TryParse(Textbox4.Text, d2)
        D = d2
      Else
        Windows.Forms.MessageBox.Show("That's not a number! Shape up!")
      End If
      
      If Double.TryParse(Textbox5.Text, d2)
        E = d2
      Else
        Windows.Forms.MessageBox.Show("That's not a number!")
      End If
    
      If Double.TryParse(Textbox6.Text, d2)
        F = d2
      Else
        Windows.Forms.MessageBox.Show("That's not a number! Shape up!")
      End If
    
      If Double.TryParse(Textbox7.Text, d2)
        G = d2
      Else
        Windows.Forms.MessageBox.Show("That's not a number! Shape up!")
      End If
    
     If Double.TryParse(Textbox8.Text, d2)
        H = d2
      Else
        Windows.Forms.MessageBox.Show("That's not a number! Shape up!")
      End If
     End Sub
    End Class
    With that, the button click event can call the sub and it will fill in all the variables. The variables are not global, but declared private such that they are visible to all methods of the form, but not to anything outside the form. I also changed your CDbl to the safer Double.TryParse which will not throw an exception if the user either leaves a textbox empty, or puts some characters or non-numeric symbols into the textbox (such as dollar signs).
    My usual boring signature: Nothing

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