Basically, I'm building a aspx calculator page for a client. What the visitor has to do is fill out the textboxes with a number. it takes the sum of all the text boxes, multiplies the sum by one number to get the minimum value and then another to get the max value and the final result is a string saying "you need at at least min and max sq footage" The code I wrote works perfectly if you give all the text boxes a value, but not if you leave them blank. Here is my code:

<script runat="server">

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        'Declaring varibles 
        Dim OutputLabel As String        
         Dim Min As New Integer
        Dim Max As New Integer
        Dim Sum As New Integer
        'Giving variables values 
        Sum = Val(ExecTextBox.Text * 200) + Val(ManageTextBox.Text * 150) +       Val(AssoTextbox.Text * 100) 
        Min = Sum * 1.1
        Max = Sum * 1.35
     
        'Output 
        OutputLabel = "You will need to search for office space from" & Min & "   ft<sup>2</sup>" & " to " & Max & " ft<sup>2</sup>"
        Me.lblOutput.Text = OutputLabel
         
    End Sub
</script>

My original code had more textboxes(about 15) but I deleted some them for clarity on here.

What I want to do is set all the textboxes that are left blank to have the automatic value of zero. I think the solution to this is using the If TypeOf Ctrl Is operator but I don't know how to use it. First of all, VS is saying Ctrl isn't declared. is there a namespace for it?

I don't see one used on this page:http://msdn2.microsoft.com/en-us/library/s4zz68xc.aspx

I'm just a webdesigner for this company, I don't' normally do this kinda of coding but I have come a long ways.


ah, i just noticed that msdn page is specific to VS 2008 and .NET 3.5, i'm using VS 2005 with .NET 2.0, will that operator still work?

This code running good in desktop application, you can try in web application :

Dim i As Integer
    Dim Con As Control
        
    For i = 0 To Me.Controls.Count - 1
        Con = Me.Controls(i)
        If TypeOf Con Is TextBox Then
            Con.Text = 0
        End If
    Next

An error is showing up with that code. It says 'Text' is not a member of System.Web.UI.Control, does that belong to a namespace? I tried searching for it but had not luck.

Sum = Val(ExecTextBox.Text * 200) + Val(ManageTextBox.Text * 150) + Val(AssoTextbox.Text * 100)

should be:

Sum = Val(ExecTextBox.Text) * 200 + Val(ManageTextBox.Text) * 150 + Val(AssoTextbox.Text) * 100

Changing the syntax worked! Thanks a lot, I really appreciate it. and to think i was going to add unnecessary operators.

Thought I already marked this one as solved. Sorry if I didn't...I remember thinking about doing that.

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