Results 1 to 4 of 4

Text Boxes (Values) if blank equal to 0

Threaded View

  1. #1
    Registered User
    Join Date
    06-29-2012
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    4

    Text Boxes (Values) if blank equal to 0

    Hello,

    This is my first post, so I apologize if was posted in the wrong forum. Thank you in advance for reading and any assistance you provide to rectify the issue.

    I have created a form with multiple (7) Text Boxes a user will enter data into. There is one Command Button that if clicked will perform multiple (3) calculations simultaneously and display the results of the calculation in a respective Label for that data. The problem is, some of the Text Boxes could be equal to "0". I would prefer a user to have the option of either entering "0" into the box or simply leave it blank. If left blank, clicking the Command Button would calculate as it should, but uses "0" for the blank fields. At the moment, if the fields are left blank, I receive an error.

    Here is what I have so far, which works if I enter "0" into the text fields I would like to leave blank:
    Private Sub cmdCalculate_Click()
        '- convert text values to Double precision. Add. Convert result to a string
        lblCSccb.Caption = Format((CStr(CDbl(txtSUcs.Value) * CDbl(txtNAV.Value)) + CDbl(txtCSstgl.Value) + CDbl(txtCSltgl.Value)), "00.00")
        lblNCSccb.Caption = Format((CStr(CDbl(txtSUncs.Value) * CDbl(txtNAV.Value)) + CDbl(txtNCSstgl.Value) + CDbl(txtNCSltgl.Value)), "00.00")
        lblTccb.Caption = Format((CStr(CDbl(txtSUcs.Value) * CDbl(txtNAV.Value)) + CDbl(txtCSstgl.Value) + CDbl(txtCSltgl.Value)) + (CStr(CDbl(txtSUncs.Value) * CDbl(txtNAV.Value)) + CDbl(txtNCSstgl.Value) + CDbl(txtNCSltgl.Value)), "00.00")
    End Sub
    Last edited by Leith Ross; 06-29-2012 at 03:10 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1