User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 427,205 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,165 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 443 | Replies: 7 | Solved
Reply
Join Date: Jul 2007
Posts: 25
Reputation: swaters86 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
swaters86 swaters86 is offline Offline
Light Poster

set TextBoxes equal to zero

  #1  
Apr 29th, 2008
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?
Last edited by swaters86 : Apr 29th, 2008 at 10:36 am. Reason: fix code tags, fix spelling/grammar mistake
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: � Jogja �
Posts: 2,585
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Rep Power: 11
Solved Threads: 235
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: set TextBoxes equal to zero

  #2  
Apr 29th, 2008
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
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
Join Date: Jul 2007
Posts: 25
Reputation: swaters86 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
swaters86 swaters86 is offline Offline
Light Poster

Re: set TextBoxes equal to zero

  #3  
Apr 29th, 2008
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.
Reply With Quote  
Join Date: Feb 2008
Posts: 52
Reputation: bwkeller is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
bwkeller bwkeller is offline Offline
Junior Poster in Training

Re: set TextBoxes equal to zero

  #4  
Apr 29th, 2008
visualbasic Syntax (Toggle Plain Text)
  1. Sum = Val(ExecTextBox.Text * 200) + Val(ManageTextBox.Text * 150) + Val(AssoTextbox.Text * 100)
should be:

visualbasic Syntax (Toggle Plain Text)
  1. Sum = Val(ExecTextBox.Text) * 200 + Val(ManageTextBox.Text) * 150 + Val(AssoTextbox.Text) * 100
Reply With Quote  
Join Date: Jul 2007
Posts: 25
Reputation: swaters86 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
swaters86 swaters86 is offline Offline
Light Poster

Re: set TextBoxes equal to zero

  #5  
Apr 29th, 2008
Changing the syntax worked! Thanks a lot, I really appreciate it. and to think i was going to add unnecessary operators.
Reply With Quote  
Join Date: Feb 2008
Posts: 52
Reputation: bwkeller is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
bwkeller bwkeller is offline Offline
Junior Poster in Training

Re: set TextBoxes equal to zero

  #6  
Apr 29th, 2008
No problem. Mark this one solved!
Reply With Quote  
Join Date: Jul 2007
Posts: 25
Reputation: swaters86 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
swaters86 swaters86 is offline Offline
Light Poster

Re: set TextBoxes equal to zero

  #7  
Apr 29th, 2008
Thought I already marked this one as solved. Sorry if I didn't...I remember thinking about doing that.
Reply With Quote  
Join Date: Feb 2008
Posts: 52
Reputation: bwkeller is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
bwkeller bwkeller is offline Offline
Junior Poster in Training

Re: set TextBoxes equal to zero

  #8  
Apr 30th, 2008
I think you already had; I was just to lazy to look before speaking!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 10:56 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC