Problem Adding Negative NumbersRSS

3 replies

Last post Feb 10, 2020 02:49 AM by Jalpa Panchal

  • Problem Adding Negative Numbers

    Feb 06, 2020 11:20 AM|CamTW|LINK

    Hi


    But stuck for a while now on this, any help would be much appreciated. I've been asked to update an old site that runs a sales report to allow negative numbers.
    The page runs fine using positive numbers but as soon as a negative number is sumbitted it throws a mismatch error.
    Microsoft VBScript runtime
    error '800a000d'

    Type mismatch: 'CSng'

    Here is an a example of one of the lines of code causing a problem have spent a while looking and don't know what I'm missing?

    TotalSales = CSng(Cash1) + CSng(Card1) + CSng(Web1)

    Thanks

  • Re: Problem Adding Negative Numbers

    Feb 07, 2020 06:45 AM|Jalpa Panchal|LINK

    Hi,

    The CSng function Converts an expression to a variant of subtype Single.

    CamTW

    Microsoft VBScript runtime error '800a000d'

    Type mismatch: 'CSng'

    The error indicates the type mismatch. make sure you enter the numbers not character. 

    I can not reproduce your issue. could you please share the whole code?

    you could also try below sample code:

    <html>
    <body>
     
    <form method="post">
    First number:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="no1" size="20" />
    &nbsp;
    <p>
    Second number: <input type="text" name="no2" size="20" />
    &nbsp;</p>
    <p>
     
     
    </p>
    <p>&nbsp;
    <input type="submit" name="submit"  value="submit" />
    </p>
     
    
     
    </form>
     <%
    btnv=Request.form("submit")
    
    If btnv = "submit" Then
    
    dim n1,n2,n3 
    n1=cint(Request.form("no1"))
    n2=cint(Request.form("no2"))
    n3=n1+n2
    Response.write(n3)
    End If
    %>
    </body>
    </html>

    To learn more about the function you could refer this below link:

    https://www.w3schools.com/asp/asp_ref_vbscript_functions.asp

    Regards,

    Jalpa

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: Problem Adding Negative Numbers

    Feb 07, 2020 11:23 AM|CamTW|LINK

    Hi Jalpa,

    Thanks very much for help, I could run you example with out any problem but the page we have is dealling with money so has to be able to handle 2.50 etc so not able to use Cint.

    The page has over 1000 line of code to have tried to condense the relevant bit below:

    Submission form:

    <html>
    <head>
    <meta charset="UTF-8">
    <title>Untitled Document</title>
    </head>
    <body>
    <form action="processform.asp" method="post" id="ddr"> <input type="hidden" name="id" value="1"> <input type="hidden" name="formName" value="form1"> <table class="table table-striped table-hover table-sm border"> <tr> <td>Name</td> <td align="center">Code</td> <td align="center">Cash</td> <td align="center">Card</td> <td align="center">Web</td> </tr> <tr> <td>Item 1 <input type="hidden" name="ItemName1" value="Item1"> <input type="hidden" name="Item1" value="1"> <input type="hidden" name="ItemCode1" value="R9470.034"> <input type="hidden" name="VatCode1" value="s"> <input type="hidden" name="Vat1" value="0.166666667"></td> <td align="center">R9470.034</td> <td align="center"><input type="number" placeholder="0.00" name="cash1" min="-1000" step="0.01" title="Currency" pattern="^[\-]{0,1}[0-9]+[\.][0-9]+|[\-]{0,1}[0-9]+$" style="width:100px; text-align:right;"></td> <td align="center"><input type="number" placeholder="0.00" name="card1" min="-1000" step="0.01" title="Currency" pattern="^[\-]{0,1}[0-9]+[\.][0-9]+|[\-]{0,1}[0-9]+$" style="width:100px; text-align:right;"></td> <td align="center"><input type="number" placeholder="0.00" name="web1" min="-1000" step="0.01" title="Currency" pattern="^[\-]{0,1}[0-9]+[\.][0-9]+|[\-]{0,1}[0-9]+$" style="width:100px; text-align:center;"></td> </tr> <tr> <!-- Free Form END--> <tr> <td colspan="5" align="right"><input type="submit" value="Submit DRR"></td> </tr> </table> </form> </body> </html>

    Processing Code:

    <%@LANGUAGE="VBSCRIPT"%> 
    <%Session.LCID = 2057%>
    
     <%
    Function cleanUpText(txt)
    
            If IsNull(txt) Then
            txt = 0
            End If
    	
    	if IsNumeric(txt) = false then 
    	txt = 0
    	end if
     
    cleanUpText = "0" + txt
     
    								
    End Function
    
    'Code for replacing "'" within names etc
    Function StrQuoteReplace(strValue)
    		StrQuoteReplace = Replace(strValue, "'", "''")
    End Function
    
    %>
    
    
    <%
       Dim Cash1,Card1,Web1 
    
    
    Item1 = StrQuoteReplace(Request.form("Item1"))
    ItemName1 = StrQuoteReplace(Request.form("ItemName1"))
    ItemCode1 = StrQuoteReplace(Request.form("ItemCode1"))
    VatCode1 = StrQuoteReplace(Request.form("VatCode1"))
    Vat1 =  cleanUpText(StrQuoteReplace(Request.form("Vat1")))
    
    Cash1 = cleanUpText(StrQuoteReplace(Request.form("Cash1")))
    Card1 = cleanUpText(StrQuoteReplace(Request.form("Card1")))
    Web1 = cleanUpText(StrQuoteReplace(Request.form("Web1")))
    VatAmount1 = (CSng(Cash1)+CSng(Card1)+CSng(Web1))*Vat1
    
    %>
    
    <%=VatAmount1%>
    
    

    If I was to submit the values 10 , 10 ,10 it works perfectly but if any of those were a negative value that give me the mismatch error.

    Thanks Again

  • Re: Problem Adding Negative Numbers

    Feb 10, 2020 02:49 AM|Jalpa Panchal|LINK

    Hi,

    I tried your code I am getting an error on Type mismatch: 'StrQuoteReplace'.

    if in your code you have a float number then you could use CDbl instead of CInt.

    below is the error.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.