Int32 parse not finding object in asp - asp-classic

I have the follow asp file:
<H3>test file</H3>
<%
s = "1"
a = Int32.Parse(s)
%>
and I get the following error:
test file
Microsoft VBScript runtime error '800a01a8'
Object required: ''
/ignore/testInt32.asp, line 4
I suspect I am missing an include, but I can not find any example that has an include.

Are you sure you are using classic asp. I looked this up because I though
Int32.Parse()
was a bit strange. As far as I can tell that is a ASP.NET only function. for classic asp you should use
CInt()
Edit: Just wanted to update my answer a bit. While the above line would give you no issue in your example, in order to make sure the code exactly matches what your original code would do, you should instead use
CLng()
CLng will overflow after ~2 million the same as Int32. CInt on the other hand CInt will overflow after ~30k. Either way for classic asp you should use one of those two.

Why did you get an Object Required Error?
The issue is your mixing asp.net objects with asp-classic which out of the box Classic ASP (by default vbscript) doesn't know about.
The fact a line number is included should lead to the cause of the problem fairly quickly.
Microsoft VBScript runtime error '800a01a8'
Object required: ''
/ignore/testInt32.asp, line 4
on line 4 which will be;
a = Int32.Parse(s)
An Object is required error occurs because Int32 is not a valid "Object Reference" as far as VBScript is concerned. There is no built-in Objects called Int32 and there is no instantiation of an Int32 Object Reference using code like;
Set Int32 = Server.CreateObject("TheObjectsProgID")
Solution
If you want to parse an Long data type in VBScript as #KHeaney has suggested you should be using
a = CLng(s)
VBScript is Typeless so Check Your Variables
Be aware that if the value of s is not a valid numeric value you conversion will fail and you will receive a
Microsoft VBScript runtime error '0x800a000d'
Type mismatch: 'CLng'
There are various ways to get around this including using Val() which will return non numeric conversions as 0 (this can be dangerous). Another approach is to check the value beforehand using something like;
If IsNumeric(s) Then a = CLng(s) Else a = 0
You don't have to set a = 0 this can be any assignment a = "" is also possible, the fact is checking the variable like this gives you greater control over the outcome.
Useful Links
CLng() Function
VBScript Data Types

Related

What causes "ASP 0248" error?

I get this really bizarre error:
0x80004005 - Object ObjectContext: 006~ASP 0248~Script isn't transacted. This ASP file must be transacted in order to use the ObjectContext object.
In some cases. I have old ASP pages that call several libraries, one of which does this:
IF blnHasError THEN
ObjectContext.SetAbort
ELSE
ObjectContext.SetComplete
END IF
Which is where the error occurs. But given the obscure error message, I can't figure out what ASP wants or expects.
The calling page must be transacted, meaning that in its header it must declare this:
<%# Transaction=Required %>
More documentation here.

Using Comparison operators with DateTime datatype

I am new C# and don't know how can I compare the DateTime datatype. If I am using equality operator it works fine:
RM(FILE.FileCreationTime) == System.DateTime.Parse("11:30:00")
But I shows me error when I use:
RM(FILE.FileCreationTime) <= System.DateTime.Parse("11:30:00")
Error is like:
operator <= cannot be applied to the Operands of type System.DateTime and System.DateTime
Important here that the syntax you are using is actually NOT c#!!
When working in BizTalk orchestrations you are using X#, a variation of C# based on XLANG.
More information you can find here: http://masteringbiztalkserver.wordpress.com/2011/02/21/debugging-
orchestrations-in-biztalk-server-2009-using-c-cs-file/
An Orchestration *.odx file contains an XML file and code written in a
language specific to BizTalk called X#.
You can easily find these, when you right click an orchestration and
open it with XML Editor or Notepad.
XML Representation of the Orchestration is used by the Graphical
Designer to show the shapes on the screen.
X# code is in turn converted to C# at runtime using XSharp.exe file
and this C# assembly will be executed.
This C# file can be found inside
\obj\Debug\BizTalk\Xlang\File0.cs once the project is
built.
So, the c# tag actually is incorrect here and I would seriously consider removing it from your question.
Nevertheless, you have the issue in your BizTalk orchestration.
My advice: add a variable of type System.DateTime to your orchestration.
Next, assign your variable to this value: RM(FILE.FileCreationTime).
This will allow you to use the if command properly in your shape.
Late - but I stumbled upon this while looking for the same answer. The way to compare two System.DateTime objects in a BizTalk expression shape, is to use:
System.DateTime.Compare(DateTime1, DateTime2)
With > 0, = 0 or < 0...
And in the specified case
!(System.DateTime.Compare(RM(FILE.FileCreationTime), System.DateTime.Parse("11:30:00")) > 0)
Try:
if (StartDate < EndDate)
// code
if you want to compare dates, and not the time
if (StartDate.Date < EndDate.Date)
// code

ASP.Net - Function output shown before function called

I have the following line of code in ASP.Net (VB)
Response.Write("<td class=""tblRow""><strong>" & ITServiceRow.NAME & " </strong><br>" & funcRAGColour(ITServiceRow.RAGSTATUS) & Environment.NewLine)
This should output the Name from ITServiceRow.NAME followed by the result of the function funcRAGColour.
However this is not the case. ASP.Net is outputting the value of the function funcRAGColour. first followed by the value of ITServiceRow.NAME.
Just trying to understand why this might be happening? If I replace the function with static text it executes fine, but when I put the function in it outputs the function result immediately before the name.
The image here, in yellow shows the full output that comes from the function, it is shown before everything else?
Am I missing something obvious here?
Try using String.Format instead to guarantee placement.
Response.Write(string.Format("<td class=""tblRow""><strong>{0}</strong><br />{1}{2}</td>",funcRAGColour(ITServiceRow.RAGSTATUS),Environment.NewLine))
Always do whatever you can to avoid string concatenation. String concatenation is tough on a system and uses much more memory and resources to be garbage collected than you think because it's actually far more complicated. String.Format and StringBuilder help get around this.
I am very suspect of the function funcRAGColour() itself though and think that is the problem. My guess is the function is not returning the output as a string, but instead is using Response.Write() to output it's result. That would cause it's value to appear first since it is called while the string is being assembled.
Keep in mind, Response.Write is NOT the way to do things in ASP.Net. It was need in classic ASP, but ASP.Net has HtmlTextWriters that can be used during the rendering process, controls for result placement, etc.. It's the old school, non object-oriented way of doing things that can get into trouble.

SqlDataSource erroring when retrieving NVARCHAR(max) column

I'm writing a small ASP .Net application in order to retrieve data from a SQL database. The application uses drop downs in order to select what the next drop down should contain and when a page is selected, it should retrieve the HTML from the database. Everything is working until it gets to the retrival of the HTML data. When I try to retrieve the data, I get:
Microsoft JScript runtime error:
Sys.WebForms.PageRequestManagerServerErrorException:
An unknown error occurred while
processing the request on the server.
The status code returned from the
server was: 500
The HTML column is a defined as NVARCHAR(MAX), but I can't see this causing a problem. The application works if I set the DataValueField to another column. Has one else come across a problem like this? Maybe someone could shine some light on this?
One thing I noted when dealing with varchar(max) columns is that the framework still commonly expects to have a size associated with it. What I ended up having to do was specify the length as -1 to get it to accept a varchar(max) field. Your error message doesn't indicate that this is the problem, but you might try experimenting with it rather than turning off the validation, which could possibly have other repercussions.
Figured it out. Just needed to set ValidateRequest to false at the Page level.

No clue.. Overflow, Microsoft VBScript runtime error '800a0006'

I'm receiving suddenly this error on a Win2003 Server Web Application:
Microsoft VBScript runtime error '800a0006'
Overflow: 'Appname'
A bunch of updates where performed on this server but I have rolled them back all.
The page is old ASP code and if i run file monitor utility it will show the BUFFER OVERFLOW when it hits a GIF.
Any ideas?
Microsoft VBScript runtime error '800a0006' almost always indicates a divide by zero error.
You can reproduce the Overflow error like this :
Dim testVar
testVar = 99999
testVar = CInt(testVar)
So, maybe this indicates there are some problems with the data types where you are setting some variables on that file?
Can you figure out where in the file the error is happening? You can use
Response.Write "here"
Response.End
And then load the page to see what point it gets to. Then you can post the code that is crashing and we may be able to help you more.
You may have a function with Out of Range variable
If you used integer variable and the variable posses greater than
integer range then its shows error.
Explanation:
Dim IntVar AS Integer
IntVar = 50000
Then it must show overflow error
So you can use following code instead of given code
Dim LongVar As Long
longVar = 50000

Resources