|
-
Sep 29th, 2015, 08:44 PM
#1
Thread Starter
New Member
Need a little help.
So I'm working with subs
I need three subs.
Input, Processing and Output.
I got something for Input and Processing. I don't know if input is right, but first let me say the PROGRAM WORKS. It calculates right and give me what I need. But I was just asked to have 3 one for each IPO.
Again my program works. Here it is:
Public Class MainForm
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnCal_Click(sender As Object, e As EventArgs) Handles btnCal.Click
Call Input()
Call Calculate()
End Sub
Private Sub Input()
Dim Len As Decimal = 0
Dim Wid As Decimal = 0
Dim Hei As Decimal = 0
Dim Cov As Decimal = 0
Dim Rolls As Decimal = 0
End Sub
Private Sub Calculate()
lblRolls.Text = txtLen.Text * txtWid.Text * txtHei.Text / txtCov.Text
End Sub
End Class
This is originally what I had for the Output sub:
lblRolls.Text = Convert.ToString(Rolls)
(Rolls) kept getting a blue error line because it was not declared.
Now this is completely wrong to use for the output I get that now.
And I'm honestly not worried about having in my program seeing how the program does exactly what I need but any advice would be great thanks.
-
Sep 29th, 2015, 08:53 PM
#2
Re: Need a little help.
Firstly, everyone who posts needs a little help so your thread title is as good as no title at all. The title should summarise the topic of the thread. We should have to open every thread to find out which ones are relevant.
Secondly, please format code snippets for easy reading.
vb.net Code:
Public Class MainForm
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnCal_Click(sender As Object, e As EventArgs) Handles btnCal.Click
Call Input()
Call Calculate()
End Sub
Private Sub Input()
Dim Len As Decimal = 0
Dim Wid As Decimal = 0
Dim Hei As Decimal = 0
Dim Cov As Decimal = 0
Dim Rolls As Decimal = 0
End Sub
Private Sub Calculate()
lblRolls.Text = txtLen.Text * txtWid.Text * txtHei.Text / txtCov.Text
End Sub
End Class
As for the question, your Input method doesn't actually appear to be inputting anything and your Calculate method is both calculating and outputting. Given that you haven't actually provided an explanation I will have to guess what is actually required. I would guess that Input is supposed to gather user input into variables, Calculate is supposed to use those variables to calculate a result and Output is sypposed to display that result to the user. None of your methods do what they're supposed to in that case, with Input doing nothing useful, Output not existing and Calculate doing all three jobs.
As for why your original code for Output didn't work, it's because you were trying to use a variable that was declared in a different method. Variables declared within a method only exist within that method. Any variable that must be used in multiple methods must be declared outside all, i.e. a member variable.
-
Sep 29th, 2015, 10:16 PM
#3
Thread Starter
New Member
Re: Need a little help.
Actually the program gives me what the problem ask for. Period.
And the problem originally stated one or more. We were told to use a many as we though we needed, originally, and honestly the only one I need is the calculation one. So with what was originally said I've got a perfect program...OK not perfect. Just through long talking it was a brilliant idea to have on for all three IPO. I know that the input and output aren't right, and that Calculation does everything.
I'm happy with the program as it gives me the outcome I need. So I'm done.
I'm new to programming but doing good enough myself to pass, and no I'm not looking to make a career out of it. So, tomorrow I'm deleting this account. B/c you people are the kind of people I hate, why I ever looked for help here I will never know.
-
Sep 30th, 2015, 12:12 AM
#4
Re: Need a little help.
 Originally Posted by Firebender
I'm new to programming but doing good enough myself to pass, and no I'm not looking to make a career out of it. So, tomorrow I'm deleting this account. B/c you people are the kind of people I hate, why I ever looked for help here I will never know.
I'm just one person so to judge "us people" on my one post is really rather silly. Apart from that, if you had provided a CLEAR explanation of the problem then things might have been different. We can't read your mind. You said:
I need three subs.
Input, Processing and Output.
I took you at your word. If you didn't need three Subs then why did you say that you did? If you want to think that the big bad people were mean to little old you then so be it, but maybe you should think about whether you could provide total strangers with no previous exposure to what you're doing with a clearer explanation of what you're actually doing and what you actually need. We who do do this as a career and volunteer our time to help others don't want to have to divine what you really need from what you haven't said.
-
Sep 30th, 2015, 09:32 AM
#5
Re: Need a little help.
I assume that "the people he hates" are those who burst his self-delusions. After all, the code doesn't really work, it just works for the narrow test cases he has tried. Breaking it would be trivial. All you'd have to do is leave something blank, or even worse, make a pretty simple typo.
I guess it doesn't matter, though, as the OP said they'd be deleting the account today and all they are trying to do is skate.
My usual boring signature: Nothing
 
-
Sep 30th, 2015, 09:34 AM
#6
Re: Need a little help.
tomorrow I'm deleting this account
That is your perogative but I hope you won't. We're happy to support all levels of ability here from beginners to professionals.
What JM is saying is correct, though. In order for us to help you we need you to be very clear in exactly what you want and to provide a clear and succinct title for your thread. This isn't about us battering you with a bunch of archaic rules, it's about making sure you get the best help possible. If you're not clear about what you want it's likely we'll take you up some blind alleys and waste both our time and, just as importantly, yours.
The other thing JM pointed out to you is that it doesn't look like your program is doing what you think it is. I urge you to take that on board because it's likely to lose you marks. With a smal amount of effort you make some changes so that you keep hold of those marks which, surely, has to be a positive. So lets take another look:-
1. Your Input routine is intialising a bunch of variables with values of zero. Note that these variable are just values in memory, they do not relate to the text boxes on your form.
2. Your Calculate routine is taking the values from the text boxes on your form, doing the calculation and assigning the result to another text box on your form. Note that it is not referring to the variables you initialised in your Input routine.
Presumably, what you intended to do was have your initialise routine set some variable to hold the values from the text boxes on the form. The calculate routine would then do it's work based on thise variables and assign the result to a further variable. Your output routine would then assign the value of the result to the results text box on your form.
In order to achieve all that you will first need to understand the concept of "scope". Scope refers to where a variable or function can be used. Variables declare in a function can be used anywhere in that function but not anywhere outside it. Variables declared in a form can be used anywhere within the form (including in any functions that are in the form) but not outside it, e.g. in another form.
The reason you need to understand scope is that the variables you have declared in your input routine are only usable in your input routine. They are not usable in your calculate routine and would also not not usable in an output function. To fix that you simply move their declarations out of the input routine and into the form (just after the public clas MainForm line. That will make them available in your input routine so you can set their values, in the calculate routine so that you can use them in your calculation, and in your output routine so that you can use teh resulst variable to output the result.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|