We help IT Professionals succeed at work.
Get Started

Type Mismatch string

Gemini532
Gemini532 asked
on
2,261 Views
Last Modified: 2007-12-19
Hello Everyone, I want in my number fields to have commas be added to it after the user clicks Tab....
After the page is submitted it goes to a page called 2.asp which is a validation page, and here the commas are removed before the number is entered into the database, however, when I return to the original page to make the changes suggested on 2.asp, I sitll want the numbers to retain the commas, no decimaal points, and no dollar sign in front of the number in the textbox... because there is a dollar sign outside the text box:
                    ______________
Like this:   $ |_________1,000|    
Also I cannot have the $ inside the box because the computer will think it's a number and add a comma after it like this:   $,345    :(

The datatype in the database for this field is money  
The problem is that my code is giving me the following ERROR which comes from the first page:

Microsoft VBScript runtime error ‘800a000d’
Type Mismatch: ‘FormatNumber’

Error comes from Line 636 which is this line:    <input style="font-family: Verdana; font-size: 8pt" type="text" value="<%=FormatNumber(strSales,0)%>" name="txtSales" size="14" maxlength="11" align="right" onblur="this.value = Comma(this.value)"; />


And I also get this  ERROR: from line 305 from the second page: "2.asp"
This line is:          <% if (strSales="" or strSales = 0) Then %><span class="reqfld">Required Field</span><% Else %>$<%=strSales%><% End If %></td>

Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: ""]'

This comes from line


‘**********************************Code on the first page:  *****************************************************

<form name="save50P1" method="post" action="2.asp" onsubmit="return ValidateSubmit();" onkeypress="return event.keyCode!=13">

<table cellpadding="0" cellspacing="3" border="0" width="558">
<tr>
<td valign="top" align="left" width="15"></td>
<td valign="top" align="left">Contact<font color = "red"> * </font>:</td>
<td valign="top" align="left"><input style="font-family: Verdana; font-size: 8pt" type="text" value="<%=strContact%>" size="50"   name="txtContact" /></td>            
</tr>
<tr>
<td valign="top" align="left" width="440">Annual sales:</td>
<td valign="top" align="left">$&nbsp;
<span id="rInputs">
<input style="font-family: Verdana; font-size: 8pt" type="text" value="<%=FormatNumber(strSales,0)%>" name="txtSales" size="14" maxlength="11" align="right" onblur="this.value = Comma(this.value)"; />
 </span> </td></tr></table>
</td>            
</tr>      
</table>

<script>
function Comma(number) {
number = '' + number;
      if (number.length > 3) {
            var mod = number.length % 3;
            var output = (mod > 0 ? (number.substring(0,mod)) : '');
            for (i=0 ; i < Math.floor(number.length / 3); i++) {
            if ((mod == 0) && (i == 0))
            output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
      else
            output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
      }
      return (output);
  }
else return number;
}
</script>

‘*******************************8Code on the second page (2.asp): the VALIDATION PAGE***********************

<script>
function CheckWord(CheckValue)
  CheckValue = replace(CheckValue, "&" , "&amp;")
  CheckValue = replace(CheckValue, "<", "&lt;")
  CheckValue = replace(CheckValue, ">", "&gt;")
  CheckValue = replace(CheckValue, "'", "''")
  CheckValue = replace(CheckValue, "%20", " ")
  CheckValue = replace(CheckValue, ";"," " )
  CheckValue = trim(CheckValue)
  CheckValue=replace(CheckValue,",","")
  CheckWord=CheckValue
end function

function fnCheckForNumber(strNum)
      If NOT isNumeric(replace(fnStripCommas(strNum),".","")) Then
            strNum="NULL"
            'Angie H. -- Change NULL to blank
            strNum=""
            totalblank=totalblank+1
      End If
      if (strNum="") Then
            strNum="NULL"
            'Angie H. -- Change NULL to blank
            strNum=""
      End If
      fnCheckForNumber=fnStripCommas(strNum)
End Function

function fnStripCommas(sInput)
  if isNull(sInput) or isEmpty(sInput) or sInput="$" then
'    fnStripCommas="NULL"
      'Angie H. -- Change NULL to blank
      fnStripCommas=""
  else
    fnStripCommas=replace( replace(sInput,",",""), "$", "" )
  end if
end function
</script>


<%
if not objRS.eof then
strContact=fnEmptyIfNull(objRS("txtContact"))
strSales=fnEmptyIfNull(objRS("txtSales"))
End If      


strSQL = "UPDATE form50 set "
strSQL = strSQL & " txtContact='" & CheckWord(fnNullIfEmpty(request.form("txtContact"))) & "', "
            if (Len(request.form("txtSales"))<1) Then
                  tempsales="NULL"
            Else
                  tempsales=fnCheckForNumber(CheckWord(request.form("txtSales")))
            End If
strSQL = strSQL & " txtSales=" & tempsales & " "            
strSQL = strSQL & " WHERE UserID=" & Session("UserID")
objConn.Execute(strSQL)

Any ideas what is wrong, is it the fact that I used FormatNumber() instead of FormatCurrency
If that is the case, how do I use FormatCurrency without the $ to show up because that would give me other problems such as the comma thinking it's a number and adding itself after it like this

$,323,000


BTW: I am coding in ASP, using SQL Server 2000 as the database
Comment
Watch Question
Top Expert 2004
Commented:
This problem has been solved!
Unlock 1 Answer and 16 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE