hi all

I have created a web application and have a number of textboxes on a web page. I have created a new class with carries out a number of calculations and if there is no text in the box it enters 0.00 so I dont get a null exception.

Public Sub calculate_monday()


If TextBox207.Text = "" Then TextBox207.Text = "0.00"

but when I debug it i get :
Object reference not set to an instance of an object.

if the code is in the defualt class it works obviously but I am trying to do this from another class. what do I have to do.....do I reference it etc?

dave

Instead of trying to change the text value of a textbox in another class, why don't you code it so that a value is passed back.

how do I go about doing that? sorry been out of coding for a while.....bit rusty

his is a code sample
This will pass the text value in TextBox207 into calculate_monday() function in another class.

''Change Class1 to the name of your class
    Dim cls As Class1
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        ''This line of codes will execute calculate_monday with parameter.
        cls.calculate_monday(TextBox207.Text)
    End Sub

This is something you can use in your class

Public Class Class1
    Public Function calculate_monday(ByRef txtValue As String)
        Dim returnValue As String
        returnValue = txtValue

        If txtValue = Nothing Or txtValue = "" Then
            returnValue = "0.00"
        End If
        Return returnValue
    End Function
End Class

thanks so much ill let you know how I get on.

correction

Dim cls As New Class1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    TextBox207.Text = cls.calculate_monday(TextBox207.Text)
End Sub

got it working thanks.......took me ages

Mark this post solved so people can see the solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.