VBScript calculations - VBscript error - when a data field is NULL or 0 - vbscript

This is the piece of code im having an issue with.
<%=total+((rs("fee_overall")/100)*rs("fee_wip")-rs("fee_rendered"))%>
If any of the data fields are either 0 or NULL then i get a mismatch error
"Microsoft VBScript runtime error '800a000d' Type mismatch: '[string: ""]' "
Any help is apreciated.
Thanks

in this case Zero seems to be ok because you have no division by zero. for null variables the standard solution would be that you check if variables are not null , then do calculations:
if not(isnull(rs("feeoveral")) or isnull( rs("fee_wip")) or isnull(rs("fee_rendered")) ) then
response.write total+((rs("fee_overall")/100)*rs("fee_wip")-rs("fee_rendered"))
else
response.write "bolb"
end if

Try it like this.
Dim fee_over
If (IsNull(rs("fee_overall"))) Then
fee_over = "0"
Else
fee_over = (rs("fee_overall"))
End If
response.write total+((Cint(fee_over))/100)
Also please check that your database record is INT and default 0

Related

CT_FETCH error in PowerBuilder Program

I'm still learning PowerBuilder and trying to get familiar with it. I'm receiving the following error when I try to run a program against a specific document in my database:
ct_fetch(): user api layer: internal common library error: The bind of result set item 4 resulted in an overflow. ErrCode: 2.
What does this error mean? What is item 4? This is only when I run this program against a specific document in my database, any other document works fine. Please see code below:
string s_doc_nmbr, s_doc_type, s_pvds_doc_status, s_sql
long l_rtn, l_current_fl, l_apld_fl, l_obj_id
integer l_pvds_obj_id, i_count
IF cbx_1.checked = True THEN
SELECT dsk_obj.obj_usr_num,
dsk_obj.obj_type,
preaward_validation_doc_status.doc_status,
preaward_validation_doc_status.obj_id
INTO :s_doc_nmbr, :s_doc_type, :s_pvds_doc_status, :l_pvds_obj_id
FROM dbo.dsk_obj dsk_obj,
preaward_validation_doc_status
WHERE dsk_obj.obj_id = :gx_l_doc_obj_id
AND preaward_validation_doc_status.obj_id = dsk_obj.obj_id
using SQLCA;
l_rtn = sqlca.uf_sqlerrcheck("w_pdutl095_main", "ue_run_script", TRUE)
IF l_rtn = -1 THEN
RETURN -1
END IF
//check to see if document (via obj_id) exists in the preaward_validation_doc_status table.
SELECT count(*)
into :i_count
FROM preaward_validation_doc_status
where obj_id = :l_pvds_obj_id
USING SQLCA;
IF i_count = 0 THEN
//document doesn't exist
// messagebox("Update Preaward Validation Doc Status", + gx_s_doc_nmbr + ' does not exist in the Preaward Validation Document Status table.', Stopsign!)
//MC - 070815-0030-MC Updating code to insert row into preaward_validation_doc_status if row doesn't already exist
// s_sql = "insert into preaward_validation_doc_status(obj_id, doc_status) values (:gx_l_doc_obj_id, 'SUCCESS') "
INSERT INTO preaward_validation_doc_status(obj_id, doc_status)
VALUES (:gx_l_doc_obj_id, 'SUCCESS')
USING SQLCA;
IF sqlca.sqldbcode <> 0 then
messagebox('SQL ERROR Message',string(sqlca.sqldbcode)+'-'+sqlca.sqlerrtext)
return -1
end if
MessageBox("PreAward Validation ", 'Document number ' + gx_s_doc_nmbr + ' has been inserted and marked as SUCCESS for PreAward Validation.')
return 1
Else
//Update document status in the preaward_validation_doc_status table to SUCCESS
Update preaward_validation_doc_status
Set doc_status = 'SUCCESS'
where obj_id = :l_pvds_obj_id
USING SQLCA;
IF sqlca.sqldbcode <> 0 then
messagebox('SQL ERROR Message',string(sqlca.sqldbcode)+'-'+sqlca.sqlerrtext)
return -1
end if
MessageBox("PreAward Validation ", 'Document number '+ gx_s_doc_nmbr + ' has been marked as SUCCESS for PreAward Validation.')
End IF
update crt_script
set alt_1 = 'Acknowledged' where
ticket_nmbr = :gx_s_ticket_nmbr and
alt_2 = 'Running' and
doc_nmbr = :gx_s_doc_nmbr
USING SQLCA;
Return 1
ElseIF cbx_1.checked = False THEN
messagebox("Update Preaward Validation Doc Status", 'The acknowledgment checkbox must be selected for the script to run successfully. The script will now exit. Please relaunch the script and try again . ', Stopsign!)
Return -1
End IF
Save yourself a ton of headaches and use datawindows... You'd reduce that entire script to about 10 lines of code.
Paul Horan gave you good advice. This would be simple using DataWindows or DataStores. Terry Voth is on the right track for your problem.
In your code, Variable l_pvds_obj_id needs to be the same type as gx_l_doc_obj_id because if you get a result, it will always be equal to it. From the apparent naming scheme it was intended to be long. This is the kind of stuff we look for in peer reviews.
A few other things:
Most of the time you want SQLCode not SQLDbCode but you didn't say what database you're using.
After you UPDATE crt_script you need to check the result.
I don't see COMMIT or ROLLBACK. Autocommit isn't suitable when you need to update multiple tables.
You aren't using most of the values from the first SELECT. Perhaps you've simplified your code for posting or troubleshooting.

Valid response causes "Subcript out of range"

I've got a classic ASP application that contacts a database and receives a valid response but then crashes with
Error Number 9: Subscript out of range
after exiting the IF block the db call is made in. What's odd is that the same code is currently working in production. As far as I can tell they're configured identically (but I suspect there's a subtle difference that's causing this issue) and have identical code bases.
What I want to know is:
Where is this array that I'm supposedly attempting to reach a non-existent index of? I don't see it and the error gives no line number. Is there a chance something is not working correctly in the adodb library?
Perhaps this is a common problem having to do with a certain patch and my particular db connection library? Have you had a similar experience?
How do I troubleshoot a problem that doesn't immediately present itself? Should I just start putting troubleshooting statements in the library?
Explanation of what's happening in the code: When the cookie "click" is received err.number is 0. When the cookie "bang" is received the err.number is 9. It then crashes with that error at the end of the IF block.
<%#Language="VBSCRIPT"%>
<% Server.ScriptTimeout = 150 %>
<%
On Error resume Next
%>
<!--#include file="adovbs.inc"-->
<!--#INCLUDE FILE="DBConn.asp"-->
<!--#INCLUDE FILE="ErrorHandler.asp"-->
<%
'Application Timeout Warning
sessionTimeout = 20
advanceWarning = 5
jsTimeout = (sessionTimeout - advanceWarning) * 60000
'If the users session has expired
If Session("USERNAME") = "" or Session("USERNAME") = NULL Then
Response.Redirect("default.asp")
End If
'If the user has just changed their password. Prompt them that it was successfully changed
If Request("changePasswd") = "true" Then
Response.Write("<script language='Javascript'>alert('Your Password Has been Successfully Changed!');</script>")
End If
Dim connection, cmd, objRS, latestDate, lastDateJPMC, firstDateJPMC, lastDateWACH, firstDateWACH, lastDateWFB, firstDateWFB, accountCount
Function calConvertDate(theDate)
Dim yr, mn, dy, dtSplit
dtSplit = Split(theDate,"/")
yr = dtSplit(2)
mn = dtSplit(0)
dy = dtSplit(1)
if Len(mn) = 1 then mn = "0" & mn
if Len(dy) = 1 then dy = "0" & dy
calConvertDate = "[" & yr & "," & mn & "]"
End Function
set connection = Server.CreateObject("adodb.connection")
connection.Open DBConn
connection.CommandTimeout = 60
set connection = Server.CreateObject("adodb.connection")
connection.Open DBConn
connection.CommandTimeout = 60
'Get Earliest & Latest Date in Database
If Err.Number = 0 Then
Response.Cookies("CLICK")=Err.number
Set cmd = Server.CreateObject("ADODB.Command")
With cmd
Set .ActiveConnection = connection
.CommandText = "CIRS_Admin.spGetLatestDate"
.CommandType = adCmdStoredProc
set objRS = .Execute
End With
latestDate = calConvertDate(objRS("latestDate"))
Response.Cookies("latestdate")=objRS("latestDate")
objRS.Close
Set objRS = Nothing
Response.Cookies("BANG")=Err.number
End If
To debug, please add a statement like
Response.Write (objRS("latestDate"))
before the line
latestDate = calConvertDate(objRS("latestDate"))
so you can see if (for example) the date returned from the server has "-" as separator instead of "/" or if an empty value is returned.
After understanding what is causing the problem you can solve it
1.Where is this array that I'm supposedly attempting to reach a non-existent index of? I don't see it and the error gives no line number. Is there a chance something is not working correctly in the adodb library?
This is your array:
yr = dtSplit(2)
mn = dtSplit(0)
dy = dtSplit(1)
What's odd is that the same code is currently working in production. As far as I can tell they're configured identically (but I suspect there's a subtle difference that's causing this issue) and have identical code bases.
May be you have different regional settings?
I strongly suggest to you use better error handling.
Internal Server Error 500 w/ IIS Log

MS Access Reference to Recordset.Recordcount

I need to find out if there is a record in my
Main forms [frmShiftDay]
Subform [frmShiftMachinesSubform]
SubSubform [frmMachineOutputSubform]
and I can’t get it to reference at all. Thanks!
ElseIf Me!frmMachineOutputSubform.Form!frmMachineOutputSubform.Recordset.RecordCount = 0 Then
MsgBox "Product Name is missing", vbCritical + vbOKOnly, "Required Data!"
Me.frmShiftMachinesSubform.Form.frmMachineOutputSubform.SetFocus
Exit Sub
Try this ..
ElseIf Me.frmMachineOutputSubform.frmMachineOutputSubform.Recordset.RecordCount = 0 Then
I think that you are missing one last "form"
ElseIf Me.frmMachineOutputSubform.Form.frmMachineOutputSubform.Form.Recordset.RecordCount = 0 Then

Why does this VBS code fail with a "Type mismatch: 'CInt'" error?

I am experiencing difficulty with the following VBS code. It works only sometimes, and even then it fails quickly. Why?
Dim Butt
Set Butt = CreateObject("InternetExplorer.application")
Butt.visible = True
Butt2 = InputBox("Put the link to one hat you would like to snipe.", "Hat Selection")
Butt3 = InputBox("Enter the maximum amount of Robux you will spend on this hat.", "Maximum Payment")
Dim Proace
Set Proace = CreateObject("Microsoft.XMLHTTP")
Proace.Open "GET", "http://www.roblox.com", False
Proace.Send
Do
Do While Butt.Busy
WScript.sleep 200
Loop
St00f = CInt(Replace(Mid(St00f, (InStr(St00f, ">R$")+3), 8), "</b>", ""))
If St00f <= CInt(Butt3) Then
Butt.Navigate "javascript:WebForm_DoPostBackWithOptions(new%20WebForm_PostBackOptions(""ctl00$cphRoblox$TabbedInfo$UserSalesTab$lstItemsForResale$ctrl0$lnkBuyNow"",%20"""",%20true,%20"""",%20"""",%20false,%20true))"
Exit Do
End If
Loop
Do While Butt.Busy
WScript.sleep 200
Loop
MsgBox("Congratulations! Your snipe was successful! You sniped "&Butt2&" for "&Butt3&" Robux!")
Butt.Quit
Set Butt = Nothing
Set Proace = Nothing
WScript.Quit
Error:
Script: C:\Users\John\Downloads\SingleHatSniper.vbs
Line: 14
Char: 1
Error: Type mismatch: 'CInt'
Code: 800A000D
Source: Microsoft VBScript runtime error
Please help me, I'm not that great with VBS. That much is clear, my friend helped me write this.
As you might have known by now, this is where the error occurs
St00f = CInt(Replace(Mid(St00f, (InStr(St00f, ">R$")+3), 8), "</b>", ""))
And that line does these things
InStr that returns the numeric position of the first occurrence of ">R$"
Its then added with 3 to get the index after the string"R$"
Now Mid splits the string St00f with start index after "R$" to a length of 8
Then Replace takes the split string and replaces an occurrence of "</b>" with ""
At last CInt converts the string to an integer or more correctly * converts any number to the variant of subtype Integer*
And you are getting the error at the CInt conversion.
If I were at your place, I will split this line by line by keeping only one function per line and then try something like MsgBox for the output after each line and find what's wrong with that.
The key is the variable St00f and what that variable holds.
Happy Coding :)
The "Type mismatch" error indicates that your Replace(...) did not return a valid numerical string:
>> i = CInt("4711")
>>
>> i = CInt("999999999999")
>>
Error Number: 6
Error Description: Overflow
>> i = CInt("no number")
>>
Error Number: 13
Error Description: Type mismatch
>> i = CInt("")
>>
Error Number: 13
Error Description: Type mismatch
Consider using IsNumeric() before you apply CInt().
CInt can handle betweeen -32,768 and 32,767
Use CLng instead of CInt
Copied from Cint overflow error when value exceeds 100,000+

end of line error with classic asp

I have a do a project for school with classic asp which I ave never used before.
I keep getting this syntax error:
Expected end of statement
set Y=server.CreateObject("ADODB.Connection");
---------------------------------------------^
The asp code i'm trying to execute is:
<%
set Y=server.CreateObject("ADODB.Connection")
X = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ= " & Server.MapPath(".\account.mdb")Y.open X
user=request.Form("username")
set useraccount=Y.Execute("select * from logintable where username='" & user & "'")
if useraccount.eof then
Response.Redirect("41697hw1noaccount.htm");
else if useraccount.fields[0].passwd == request.Form("pwd") then
Response.Redirect("41697hw1wrongpasswd.htm")
else
Response.Write("<h1>Welcome, " & useraccount.fields[0].fullname & "</h1>")
end if
%>
Thanks so much for your help!
I am not familiar with VBScript, but I think you should not put a ';' at the end of your statement. I think removing the semi-colon will help.
In vbscript the explicit "end-of-line " character is a colon ":"
It is not required in vbscript unless you want to put more than one statement on a physical line.
for example--
Dim myVariable : myVariable = "some string"

Resources