Gemini532
asked on
Type Mismatch string
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(str Sales,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
‘************************* *********C ode 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">$
<span id="rInputs">
<input style="font-family: Verdana; font-size: 8pt" type="text" value="<%=FormatNumber(str Sales,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>
‘************************* ******8Cod e on the second page (2.asp): the VALIDATION PAGE********************** *
<script>
function CheckWord(CheckValue)
CheckValue = replace(CheckValue, "&" , "&")
CheckValue = replace(CheckValue, "<", "<")
CheckValue = replace(CheckValue, ">", ">")
CheckValue = replace(CheckValue, "'", "''")
CheckValue = replace(CheckValue, "%20", " ")
CheckValue = replace(CheckValue, ";"," " )
CheckValue = trim(CheckValue)
CheckValue=replace(CheckVa lue,",","" )
CheckWord=CheckValue
end function
function fnCheckForNumber(strNum)
If NOT isNumeric(replace(fnStripC ommas(strN um),".","" )) 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=fnStripCo mmas(strNu m)
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(o bjRS("txtC ontact"))
strSales=fnEmptyIfNull(obj RS("txtSal es"))
End If
strSQL = "UPDATE form50 set "
strSQL = strSQL & " txtContact='" & CheckWord(fnNullIfEmpty(re quest.form ("txtConta ct"))) & "', "
if (Len(request.form("txtSale s"))<1) Then
tempsales="NULL"
Else
tempsales=fnCheckForNumber (CheckWord (request.f orm("txtSa les")))
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
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(str
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
‘*************************
<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">$
<span id="rInputs">
<input style="font-family: Verdana; font-size: 8pt" type="text" value="<%=FormatNumber(str
</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>
‘*************************
<script>
function CheckWord(CheckValue)
CheckValue = replace(CheckValue, "&" , "&")
CheckValue = replace(CheckValue, "<", "<")
CheckValue = replace(CheckValue, ">", ">")
CheckValue = replace(CheckValue, "'", "''")
CheckValue = replace(CheckValue, "%20", " ")
CheckValue = replace(CheckValue, ";"," " )
CheckValue = trim(CheckValue)
CheckValue=replace(CheckVa
CheckWord=CheckValue
end function
function fnCheckForNumber(strNum)
If NOT isNumeric(replace(fnStripC
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=fnStripCo
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(o
strSales=fnEmptyIfNull(obj
End If
strSQL = "UPDATE form50 set "
strSQL = strSQL & " txtContact='" & CheckWord(fnNullIfEmpty(re
if (Len(request.form("txtSale
tempsales="NULL"
Else
tempsales=fnCheckForNumber
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
ASKER
No the number does not contain commas, I am adding a function in javaScript called Comma() to add commas to the number when the person tabs out of the field...
The reason is that we want to display the number with the commas on the screen, but not in the database
The problem is that on the second page 2.asp I have function which removes the commas in order to insert the number without commas in the database, when I return back to the first page in order to see the number with the commas again, I added:
value="<%=FormatNumber(str Sales,0)%> "
...but it seems to be giving me errors...
I hope this helps clear it up, I will try your suggestion... THe worst part is that the error does not ALWAYS show up... it only shows up sometimes so it's very difficult to test
The reason is that we want to display the number with the commas on the screen, but not in the database
The problem is that on the second page 2.asp I have function which removes the commas in order to insert the number without commas in the database, when I return back to the first page in order to see the number with the commas again, I added:
value="<%=FormatNumber(str
...but it seems to be giving me errors...
I hope this helps clear it up, I will try your suggestion... THe worst part is that the error does not ALWAYS show up... it only shows up sometimes so it's very difficult to test
ASKER
I even tried calling the Comma function from onload but it didi not work:
window.onload = main;
function main(){
Comma(document.save50P1.tx tSales.val ue);
}
It did not add the commas after I returned from 2.asp to the first page
window.onload = main;
function main(){
Comma(document.save50P1.tx
}
It did not add the commas after I returned from 2.asp to the first page
the function i gave you will add the commas.
ASKER
Thank you WMIF, I added your code and it worked on my computer...
I will send the application to my boss for testing to see if it works for him too...
Even with my code it worked on my computer but when he tested it it gave those 2 errors, so hopefully now they will no longer be there I will let you know
I will send the application to my boss for testing to see if it works for him too...
Even with my code it worked on my computer but when he tested it it gave those 2 errors, so hopefully now they will no longer be there I will let you know
ASKER
HI WMIF,
Thank you for your function but it did not eliminate the errors, right now I also received the error...
Now that I"ve been able to replicate it, I can give you more information about it or maybe even solve it myself... I'll keep you updated.
Thank you for your function but it did not eliminate the errors, right now I also received the error...
Now that I"ve been able to replicate it, I can give you more information about it or maybe even solve it myself... I'll keep you updated.
can you print out the exact content of the variable? put this at the top of the page where it has a value.
||<%=strSales%>||
||<%=strSales%>||
ASKER
I keep getting this error:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'FormatCurrency'
/angieapps/50/50-01.asp, line 695
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'FormatCurrency'
/angieapps/50/50-01.asp, line 695
ASKER
maybe that's the problem strSales does not have a value until AFTER THE USER ENTERS it in the FORM, and then it gets UPDATED to the databse on the second page 2.asp
So in the meantime, strSales is NULL
it's possible that that's why I get a type mismatch
strSales is there to show retain the value when the user comes back from 2.asp to correct any errors or any field he or she left black because 2.asp is a validation page but it also inserts in the database whatever the user entered in the from
then when they come back to the form, there's a select statment which takes these values:
CODE ON THE FIRST PAGE: that's how the variable strSales gets a value from the second page where it was inserted in the database
<%
strSQL = "SELECT txtSales from tableName where userid=" & Session("userid")
set objRS = server.createObject("adodb .recordset ")
objRS.Open strSQL, objConn
if not objRS.eof then
strSales=fnEmptyIfNull(obj RS("txtSal es"))
'Angie H. (April 25 2007) -- ***This field is key because it denotes when the form is complete.***
'***Once the form is COMPLETE, the users are no longer allowed to return to it.***
totalErrors=objRS("totalEr rors")
'************************* ********** ********** *
End If
%>
So in the meantime, strSales is NULL
it's possible that that's why I get a type mismatch
strSales is there to show retain the value when the user comes back from 2.asp to correct any errors or any field he or she left black because 2.asp is a validation page but it also inserts in the database whatever the user entered in the from
then when they come back to the form, there's a select statment which takes these values:
CODE ON THE FIRST PAGE: that's how the variable strSales gets a value from the second page where it was inserted in the database
<%
strSQL = "SELECT txtSales from tableName where userid=" & Session("userid")
set objRS = server.createObject("adodb
objRS.Open strSQL, objConn
if not objRS.eof then
strSales=fnEmptyIfNull(obj
'Angie H. (April 25 2007) -- ***This field is key because it denotes when the form is complete.***
'***Once the form is COMPLETE, the users are no longer allowed to return to it.***
totalErrors=objRS("totalEr
'*************************
End If
%>
ASKER
it explains why the error only comes up when we start a new blank form
try adding a preceeding 0 then.
<%=FormatNumber("0" & strSales,0)%>
<%=FormatNumber("0" & strSales,0)%>
>>it's possible that that's why I get a type mismatch
Yes, NULL value would trigger that message.
Yes, NULL value would trigger that message.
ASKER
so how do I get around it?
How can I still add commas in the value, without making the form fail when there is no value, and the value is NULL?
How can I still add commas in the value, without making the form fail when there is no value, and the value is NULL?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or, use FormatNumber, in the same fashion.
or you can use the code i gave you above which preceeds a null with a 0 making it 0...
<%=FormatNumber(replace(st
ref: http://www.w3schools.com/vbscript/func_formatnumber.asp