I have crystal reports and in formula editor, based on date.
If {?PDATERANGE1} <> "" AND {?PDATERANGE2} <> "" Then
ToText(DateValue({?PDATERANGE1}), "MMM d, yyyy") & " - " & ToText(DateValue({?PDATERANGE2}), "MMM d, yyyy")
I am calling this from ASP and PDATERANGE1 and PDATERANGE2 are "10/10/2001" and "10/12/2001".
I am getting the following error.
Bad date format string. Details: errorKind Error in File {B6624BE5-D6DA-469B-A635-9FE86B125492}.rpt: Error in formula dt_range: 'If {?PDATERANGE1} <> "" AND {?PDATERANGE2} <> "" Then ' Bad date format string. Details: errorKind
Could someone please tell me what is wrong? I am not a crystal reports developer.
If the values of {?PDATERANGE1} and {?PDATERANGE2} include double quotes - so that they are "10/10/2001" and "10/12/2001" respectively - then these double quotes need to be removed (so that they become 10/10/2001 and 10/12/2001 respectively).
I think it's because "" is not a valid date. Are the paramaters optional and you're checking whether they have values?
In crystal you have to use function hasvalue({?parameter}) though optional parameters tend to cause real issue so i avoid them like the plague!
Related
I am trying to add some session values and if any of the value have a decimal value ie 12.50 I get an error that Input string was not in a correct format.?
Dim Res As Integer = Convert.ToInt32(Session("ConsultingFeeAmount")) + Convert.ToInt32(Session("FoodAndBeverageAmount"))
TotalAmount = Environment.NewLine + "Total Amount: " + Session("ConsultingFeeAmount") + Session("FoodAndBeverageAmount")
TotalAmount = "Total Amount " + Res.ToString
Use a TryParse method from the Decimal class
Dim consultAmt As Decimal
Dim foodAmt As Decimal
Decimal.TryParse(Session("ConsultingFeeAmount"), consultAmt))
Decimal.TryParse(Session("FoodAndBeverageAmount"), foodAmt))
Dim Res As Decimal = consultAmt + foodAmt
TotalAmount = Environment.NewLine & "Total Amount: " & _
consultAmt.ToString() & " " & foodAmt.ToString()
TotalAmount = "Total Amount " & Res.ToString
The Decimal.TryParse analize the input string and set the second parameter with the converted value if it is possible to convert the string to a decimal. If not the method doesn't rises any exceptions and the second parameter is let alone to its default value.
EDIT
The OP says that after the change initially suggested now it has an error message that says:
Conversion from string " Total Amount: 12.50 13.00" to type 'Double'
is not valid
The problem was the + operator used to concatenate strings when Option Strict is OFF. In that case the VB compiler confuses the meaning of the operator and tries to sum two numeric values. I really suggest to use Option Strict On and Option Explicit On because this will force your code to be more precise (no implicit conversion of types). Of course if you make this change you need an extensive retest of your application
You can read about this problem in this question/answer link
I think your problem lies in the code Convert.ToInt32. You can't pass in a decimal number there. It's expecting an integer. That occurs more than once in your code.
I am guessing the value you passed to Convert.ToInt32 are not a valid numeric ones. Make sure you check the session values are empty or not before using that.
if Session("ConsultingFeeAmount") IsNot Nothing Then
' Now use this session variable
End If
I don't know if vb.net is different than C#, but Session returns an object not a typed value. You will need to cast Session("ConsultingFeeAmount") to a decimal.
CType(Session("ConsultingFeeAmount"), Decimal)
or
CType(Session("ConsultingFeeAmount"), Integer)
I am having the following issue:
I am using an application that allows users to concatenate text to build a URL that passes parameters to an ASP page via GET method, i.e. something like:
http://myhostname/process.asp?param1=value1¶m2=value2
Problem is value1 and value2 can contain the ampersand symbol, which is not interpreted as a text character.
The most popular solution to this issue is to encode the URL, which is not an option for me because I cannot modify the program that builds the URL. I can modify the process.asp page, but not the program that concatenates the text fields and builds the URL.
Things I've tried to search for are:
How to encode a URL using javascript directly in the browser
How to change IIS default behaviour when reading an &
Alternative ways to pass parameters, i.e. something like passing them as a single string of characters separated with pipes
Hope you can give me some guidance.
You can read the entire query string and parse it yourself, like this:
q = Request.QueryString
a = Split(q, "=")
i = 1
For Each s In a
If i mod 2 = 0 Then
If InStr(s, "&") <> InStrRev(s, "&") Then
Response.Write "Value: " & Left(s, InStrRev(s, "&") - 1) & "<br/>"
hidingParam = Right(s, Len(s) - InStrRev(s, "&"))
Response.Write "PAramName: " & hidingParam & "<br/>"
i = i + 1
Else
Response.Write "Value: " & s & "<br/>"
End If
Else
Response.Write "PAramName: " & s & "<br/>"
End If
i = i + 1
Next
Result:
URL: ...?Q=abc&def&P=123 produces
PAramName: Q Value: abc&def PAramName: P Value: 123
Note that this is less than robust. I am only illustrating my idea. I didn't test with no &.
It also doens't handle multiple "=" characters (if that's a possiblity as well).
If there are 2 (or more) ampersands in-between the equals, then only the last one is a parameter separator. So, using your URL above, and assuming that value1 = "abc&def", and value2 = "123", then the URL will look like:
http://myhostname/process.asp?param1=abc&def¶m2=123
Notice there's 2 ampersands in-between the 2 equals. The last one will be your parameter separator, the rest are part of the value. And any ampersands after the last equals are also part of the value.
You'll have to dissect the incoming URL and apply the appropriate logic.
I want to convert the below string into classic asp code can any one help
email has some value but it is not going inside the Loop
Can any one help me.
If (IsEmpty(email) And IsNull(email)) Then
EndIf
The code looks like its VBScript already so there is no "conversion" needed, however the code is faulty. Should be:
If IsEmpty(email) Or IsNull(email) Then
End If
a variable cannot both be empty and contain a Null at the same time hence the orginal conditional expression was always false.
You could always try:
If IsEmpty(email) = True Then
'uninitialized
ElseIf IsNull(email) = True Then
'contains null value
ElseIf email = ""
'contains zero length string
Else
'Response.Write email
'MsgBox email
End If
In most cases I try to code so that the variable is guaranteed to be initialized so you don't need to run the IsEmpty check.
Option Explicit
Dim email
email = ""
Why don't you just check the length of the email variable:
If Len(Trim(email)) > 0 Then
Else
YOUR CODE HERE
End If
I have a server side operation manually generating some json response. Within the json is a property that contains a string value.
What is the easiest way to escape the string value contained within this json result?
So this
string result = "{ \"propName\" : '" + (" *** \\\"Hello World!\\\" ***") + "' }";
would turn into
string result = "{ \"propName\" : '" + SomeJsonConverter.EscapeString(" *** \\\"Hello World!\\\" ***") + "' }";
and result in the following json
{ \"propName\" : '*** \"Hello World!\" ***' }
First of all I find the idea to implement serialization manually not good. You should to do this mostla only for studying purpose or of you have other very important reason why you can not use standard .NET classes (for example use have to use .NET 1.0-3.0 and not higher).
Now back to your code. The results which you produce currently are not in JSON format. You should place the property name and property value in double quotas:
{ "propName" : "*** \"Hello World!\" ***" }
How you can read on http://www.json.org/ the double quota in not only character which must be escaped. The backslash character also must be escaped. You cen verify you JSON results on http://www.jsonlint.com/.
If you implement deserialization also manually you should know that there are more characters which can be escaped abbitionally to \" and \\: \/, \b, \f, \n, \r, \t and \u which follows to 4 hexadecimal digits.
How I wrote at the beginning of my answer, it is better to use standard .NET classes like DataContractJsonSerializer or JavaScriptSerializer. If you have to use .NET 2.0 and not higher you can use Json.NET.
You may try something like:
string.replace(/(\\|")/g, "\\$1").replace("\n", "\\n").replace("\r", "\\r");
Having an issue with type conversion in ASP classic.
heres my code:
Set trainingCost = Server.CreateObject("ADODB.Recordset")
strSQL3 = "SELECT cost1 FROM tblMain WHERE (Booked = 'Booked') AND (Paid IS NULL) AND (PaidDate BETWEEN '01/04/" & startyear & "' AND '31/03/" & endyear & "')"
trainingCost.Open strSQL3, Connection
trainingCost.movefirst
totalTrainCost = 0
do while not trainingCost.eof
trainCost = trainingCost("cost1")
If NOT isNull(trainCost) then
trainCostStr = CStr(trainCost)
trainCostStr = Replace(trainCostStr, "£", "")
trainCostStr = Replace(trainCostStr, ",", "")
totalTrainCost = totalTrainCost + CInt(trainCostStr)
end if
trainingCost.movenext
loop
trainingCost.close
when I run this I get the following error:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'CInt'
/systems/RFT/v1.2/Extract.asp, line 43
which is "totalTrainCost = totalTrainCost + CInt(trainCostStr)"
Im guessing that the problem is to do with the String value being uncastable to Int in which case is there any way to catch this error? I havent worked with asp classic much so any help would be usefull
cheers
-EDIT-
the type of column cost1 is String as it may contain a number or a sequence of chars eg £10.00 or TBC
You have a couple of choices. You can be proactive by checking ahead of time whether the value is numeric using the IsNumeric function:
If IsNumeric(trainCostStr) Then
totalTrainCost = totalTrainCost + CInt(trainCostStr)
Else
' Do something appropriate
End If
...or you can be reactive by using error catching; in Classic ASP probably easiest to define a function and use On Error Resume Next:
Function ConvertToInt(val)
On Error Resume Next
ConvertToInt = CInt(val)
If Err.Number <> 0 Then
ConvertToInt = Empty
Err.Clear
End If
End Function
Or return 0 or Null or whatever suits you, then use it in your trainCost code.
Note that CInt expects an integer and will stop at the first non-digit, so "123.45" comes back as 123. Look at the other conversions, CDouble, CCur, etc.
Rather than casting to a string, why not use CCur (Cast as Currency) so that your commas and any currency symbols (I think) are effectively ignored while doing arithmetic operations?
Potentially solving the wrong problem, depends on the type of Cost1 within the database but the code is looping through the records to generate a total.
strSQL3 = "SELECT sum(cost1) FROM tblMain WHERE (Booked = 'Booked') AND (Paid IS NULL) AND (PaidDate BETWEEN '01/04/" & startyear & "' AND '31/03/" & endyear & "')"
trainingCost.Open strSQL3, Connection
etc and just read off the value as a total.
I don't see why the RS is being looped to generate a sum when the database can do that work for you. All the conversion work it has generated just looks artifical.
Heh heh. Classic ASP. You have my pity :) Anyway,
On error resume next
And then on the next line, check that it worked.
Though maybe you want CDouble. Is that a function? I can't remember.