I have a class assignment where i have to calculate the total cost of a parking garage from hours but i have to do it with a method function. So this might be a stupid question but can you read the user input values from a textbox in the function itself or do they have to be read in and recalled from the Private Sub Button1_Click section?

ok I've moved on hoping that I've done some things right but when i try to put in the method I get an error message telling me that what should be my method isn't a method and therefore won't work

Public Class Form1




    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim charges As Decimal
        Dim HOURS As Double = Convert.ToDouble(HOURSTXT.Text)
        Dim CHARGE As Decimal
        Dim CalculateCharges As Decimal




        CHARGE = CalculateCharges(HOURS)

        CHARGETXT.Text = FormatCurrency(CHARGE)

    End Sub

    Private Function CalculateCharges(ByVal hours As Double) As Decimal

        Dim hour As Double
        Dim charge As Decimal



        hour = hours
        charge = 0.0

        If hours <= 3 Then
            charge = 3.0

        End If

        If hours > 3 Then
            charge = 3.0 + (0.5 * (hours - 3))
        End If

        Return charge




    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        HOURSTXT.Clear()
        CHARGETXT.Clear()
    End Sub
End Class

Yes you can read from a text file if the textbox is referenced. In your function you will have something like -

Private Function CalculateHours (txtReadFrom As Textbox)

GetTheHours = txtReadFrom.Text

'And all other codes...
End Function

Private Sub Command1_Click

CalculateHours Text1 'Text1 is the actual textbox on your form with the data to read from
End Sub

hi there!calling for help
I have this program/project that is more on loops that says,write a program that will display a Fibonacci series when you click on a button.The first number entered should be indicator how many numbers of the series should be displayed a generated.So im confused whether using For...Next or While loop.
help!

Hi,
You do not define the function or method with in your sub routine, it is available to all subroutines and functions with your form. Take line 10 out and it should work.

Dim CalculateCharges As Decimal 'not needed as CalculateCharges is a function

You have specified that the function takes in a double and returns a decimal when you defined it:

CalculateCharges(ByVal hours As Double) As Decimal

I can't see where your code (or posting,) mentions reading from a text file though.

Edited 6 Years Ago by G_Waddell: typos

hi there!calling for help
I have this program/project that is more on loops that says,write a program that will display a Fibonacci series when you click on a button.The first number entered should be indicator how many numbers of the series should be displayed a generated.So im confused whether using For...Next or While loop.
help!

Hi
You really should post this under your own thread.
As for your question you can use For... next, While...End While, Do While...Loop and Do Until...Loop they are all valid for looping. Basically use whatever you are more comfortable with.:)

dim i  as integer

for i=0 to Mylimit 
'do something
next

While i < limit
'do something
  i=i+1
End While

Do While i< limit
 'do something
 i=i+1
Loop

Do Until i = Limit
 'do something
 i=i+1
Loop

Okay Sir i get u so can you plz show me the whole program what at the end will display,i mean starting from the inputs,proccessing and outputs,and plz do this kind of loops For...Next,while and do untill bcoz im familiar to them.I hope you still remember my program statement.Still vesh2009

Comments
Asking to have project coded for them

Okay Sir i get u so can you plz show me the whole program what at the end will display,i mean starting from the inputs,proccessing and outputs,and plz do this kind of loops For...Next,while and do untill bcoz im familiar to them.I hope you still remember my program statement.Still vesh2009

Hi,

So you want me to do your assignment / project for you???

You can pay me at Euro 25 /hour or try it yourself. If you get stuck come back and post a new post with your code on the part you are stuck on.

The only place success comes before work is in a dictionary

Thanks ^_^ I didn't realize i had already defined that and it works just fine ^_^ I appreciate all your help

This question has already been answered. Start a new discussion instead.