3_/\/\_ ]}-{[ 3LP _/\/\_3

Okay I think this should be very simple but I can't get it to work how i want it to!! I want to have three variables in their own seperate sub procedures, all from textbox's that the user puts their information into, 1 as a string the other two as numbers.

I have it working without breakin it up into sub procedures, but when i do put them in their own subs, it doesnt work...at all for me... Here is how I have it working:

Code Snippet

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click

Dim occupation As String = txtOccupation.Text

Dim rate As Double = txtRate.Text

Dim hour As Double = txtHour.Text

Dim amount As Double

amount = (rate * hour)

lblResults.Text = ("The " & occupation & " earned $" & amount)

End Sub

And this is what I tried to do but cant figure out why it wont work:

Code Snippet

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click

occ()

pay()

hr()

Dim amount As Double

amount = (rate * hour)

lblResults.Text = ("The " & occupation & " earned $" & amount)

End Sub

Sub occ(ByVal occupation As String)

occupation = txtOccupation.Text

End Sub

Sub pay(ByVal rate As Double)

rate = txtRate.Text

End Sub

Sub hr(ByVal hour As Double)

hour = txtHour.Text

End Sub

Does anyone know what i'm doin wrong Its for my intro to programming class and we have to have 3 working variables... Thanks for any and all help.


Re: Visual Basic Express Edition Assigning variables to their own sub procedures to be called to work in a "formula" type sub

Philly

im not sure if this is what your after but if you want to use vars from another sub, then the var must be defined outside the sub if that makes any sence,

take a look at this

Code Snippet

' I defined the strings here

Dim occupation As String

Dim rate As String

Dim hour As String

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click

occ()

pay()

hr()

Dim amount As Double

amount = (rate * hour)

lblResults.Text = ("The " & occupation & " earned $" & amount)

End Sub

Sub occ()

occupation = txtOccupation.Text

End Sub

Sub pay()

rate = txtRate.Text

End Sub

Sub hr()

hour = txtHour.Text

End Sub

hope this helps,
Philly





Re: Visual Basic Express Edition Assigning variables to their own sub procedures to be called to work in a "formula" type sub

ReneeC

Those are referred to as "member variables", short for "Class member" variables.




Re: Visual Basic Express Edition Assigning variables to their own sub procedures to be called to work in a "formula" type sub

js06

When i see threads from students i am usually confused as to why these questions aren't explained in the class.

I am thinking that either they are explained and something is missed, which i can understand, or they want to see what you can come up with on your own.

Do they give you assignments just to see if you will find the answer on your own

Or are they expecting you to work together as a class outside the classroom to figure it out

Or do they give you a book and say have at it

I am just curious because sometimes it seems like variables should be a high priority in the classroom.

What kind of program can you make without them.

Could you explain how they teach you students.

What do they teach you first

Either way the problem seems to be where you have declared the variables.

Did they go over variable declaration with you

The key is to declare at the form level or class level.

If you don't mind explaining some of the class to me then i will give some more help than just little hints.

I know the forum community doesn't like to do people's homework for them but i will give you more help than many will.

I believe that sometimes you have to see it to learn it.

Books don't cut it for me. I have to see some code and be told what it does and then i can change and combine with other code to make it work for me.

edit --------------------------------

I see there was some help given while i was writing my post

I would still be interested in how the class is taught






Re: Visual Basic Express Edition Assigning variables to their own sub procedures to be called to work in a "formula" type sub

SaTaNsR3Ject

The way my teacher teaches is well but the classroom is fairly large and I am in the back, with the humming of the computers and other students talking I find it hard to actually get what the teacher is saying during the lectures.

How the class usually goes is; A short lecture with powerpoint slides with a problem, then we have an excercise we work out. After a bit of time the answer is posted and thats the end of class. The teacher encourages us to help one another but more often then not the people I sit beside look to me to answer the problems, which is a problem because I know just about as much as them.

This past class period the teacher discussed quickly about variables and how they make it easier to read what you had written for code by looking to the exact sub procedure that you need to for the variables you have, then we got this worksheet which showed us in which order the program reads it, like how it sees the "call(phrase)" and then goes to the sub procedure for it. And that was the class basically.


If that makes any sense or if you wanna know more just ask, thanks.