Undefined function 'Replace' in expression. Run-time error 3085 - vb6

I'm working with a vb 6.0 application. There I'm using a replace function in my query. The query works fine in access but when it runs in vb it gives me the error:
"Undefined function 'Replace' in expression. Run-time error 3085".
I think that I'm missing references. I currently added following references.
The 'Replace' is located in the where clause:
...WHERE ((DateValue(Replace(Invoice.InvoiceDate, ': ', ' '))
Between...
The following full query is giving me the error.
Set DrsInv = db.OpenRecordset("SELECT Invoice.InvoiceDate, InvoicedProduct.InvoiceType, Invoice.InvoiceStatus, Invoice.RetailerID, Invoice.DailySalesID, Invoice.RepID, InvoicedProduct.Quantity, InvoicedProduct.UnitRate, InvoicedProduct.TotalItemValue From Invoice INNER JOIN InvoicedProduct ON (Invoice.DailySalesID = InvoicedProduct.DailySalesID) AND (Invoice.RepID = InvoicedProduct.RepID) AND (Invoice.InvoiceID = InvoicedProduct.InvoiceID)" _
& " WHERE ((DateValue(Replace(Invoice.InvoiceDate, ': ', ' ')) Between #" & Format(dtpFrom.value, "yyyy/mm/dd") & "# And #" & Format(dtpTo.value, "yyyy/mm/dd") & "#) AND (InvoicedProduct.ProductID = '" & Srs("ProductID") & "'))" _
& " GROUP BY Invoice.InvoiceDate, InvoicedProduct.InvoiceType, Invoice.InvoiceStatus, Invoice.RetailerID, Invoice.DailySalesID, Invoice.RepID, InvoicedProduct.Quantity, InvoicedProduct.UnitRate, InvoicedProduct.TotalItemValue HAVING ((InvoicedProduct.InvoiceType)='Invoice' AND (Invoice.InvoiceStatus)='VALID') Order By Invoice.InvoiceDate DESC")
I use the replace function because InvoiceDate is a text feild. So it is giving me the error "Data type mismatch", when I try to convert it to a date field in query. The colon inside the date is the reason for this error. That's why I need to replace the colon. I could not be able to change the database field. So this is the solution as the way I see it.
The data of the field InvoiceDate looks like following

This function doesn't make much sense to me. As the commenters have asked can you explain why you need to remove the ":" from InvoiceDate? As #LukeG says - adding data examples would help us.
By removing the ":" from the time AM/PM part of the date, your function will fail even if the Replace worked, because you'd be asking DateValue to convert as string that is now not formatted as a proper date
There's a couple things you can do:
EDITED:
Since we now know InvoiceDate is NOT a Date Field you can just remove the time part of the field by taking the first 10 characters and converting to date:
(CDate(Left(Invoice.InvoiceDate,10)) Between #" & Format(dtpFrom.value, "yyyy/mm/dd") & "# And #" & Format(dtpTo.value, "yyyy/mm/dd") & "#)

Related

ASP.Classic Getting value from input to POST parameter

Please excuse me if this question is dumb.
I need to get an input value and pass it in a POST parameter like follow:
SQL = "[proc_Happy]" & Request.Cookies("UserID")& "," & Request.Form("MYINPUTFIELD")
I have tried hardcoding MYINPUTFIELD with (it worked!):
SQL = "[proc_Happy]" & Request.Cookies("UserID")& "," & 54555152
My input in the asp page looks as follow:
<input type="number" name="MYINPUTFIELD " id="MYINPUTFIELD" value="<%=MYINPUTFIELD%>">
Things I have tried:
Getting the value with JS - failed.
Notes:
MYINPUTFIELD is an int
Is your input field in a form, i.e. is it between <form...> and </form> tags? If no, that's your problem right there. If yes, what does the <form...> tag have in it? Does it say method='get'? If yes, then your inputs are being put in the querystring, not the form object. For Request.Form(...) to work, your form needs to say method='post'.
If you need this code to work with both form methods, you can do something like
dim MyInputField
MyInputField = Request.Querystring("MyInputField")
If MyInputField = "" Then MyInputField = Request.Form("MyInputField")
'make the "OMGSQLINJECTION!!1!" people just go away already
'(note to such people: he's using a frigging stored procedure.)
If Not Isnumeric(MyInputField) Then
MyInputField = 0
End If
SQL = "[proc_Happy]" & Request.Cookies("UserID")& "," & MyInputField

get value from selection in dropdown menu with variable name

I have created a HTA page to get the status of workstations filtered from Active Directory.
Currently I added buttons to perform specific actions for the workstation that has the button next to is.
Since I'm adding more and more functions, I would like to use a dropdown box.
The size of the list with workstations is variable depending on the input made by the user, so I've given the name of the worstation to the dropdown box.
The problem I have now is that I cannot retreive the selected value in my VBScript code.
If I put listbox1.value I get the correct value in return.
If I use place the name of the listbox in a variable like this, it doesn't work.
strlistbox = "listbox1
listbox1.value
I get an error.
This is part of the code I'm using. In total I have 760 lines, so I won't paste everything here.
VBScript code:
Sub RunOption(strCPU)
dim lstname
dim intNumber
lstname = "list"&strCPU 'Value of lstname = listWPBED3702885
msgbox listWPBED3702885.value 'If I try this messagebox, I get the value of the selected option form the dropdown list names "listWPBED3702885"
intNumber = lstname.value 'This doesn't seem to work
Select Case list 'intNumber
Case 1 Do something
Case 2 Do something
Case 3 Do something
Case 4 Do something
End Select
End Sub
HTML code:
strHTML = strHTML & "<td width='1'><select class='select' size='1' title='list" & _
objRecordSet.Fields("Name") & "' name='list' onChange=""RunOption('" & _
objRecordSet.Fields("Name") & "')"">"& _
"<option value='0' selected>Options...</option>" & _
"<option value='1'>C:\ Drive</option>" & _
"<option value='2'>Computer Management</option>" & _
"<option value='3'>Event Viewer</option>" & _
"<option value='4'>MAC Address</option>" & _
"</select></td>"
You can't set a variable to a string and expect that string to behave like an element of your HTML code. You need to fetch the element referenced by the name or ID. The usual way is to define the element you want to use with a unique ID like this:
<select id='uniquevalue' ...>
...
</select>
and then get that element via getElementById():
Set listbox = document.getElementById("uniquevalue")
MsgBox listbox.value

VBScript Object Required When Trying to set DateTime

I am new to VBScript and can't figure out why I'm getting an Object Required error with my code. It's very simple right now, I've just begun it:
<%
set fs=Server.CreateObject("Scripting.FileSystemObject")
Dim dateandtime
On Error Resume Next
set dateandtime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
If Err <> 0 Then
' File operation(s) failed, handle the error
response.write(Err.Description)
End If
%>
Why am I not able to set the DateTime? I've set the FileSystemObject for use later in the code FYI. I'm just putting it all in here so you see exactly what I have. I figure it's a simple syntax thing but I can't seem to find the answer anywhere. Thanks for your help!
The first mistake is to use Set when assigning a non-object to a variable. The last entry in the 'Related' list “Object required” when using Set in an assignment deals with it.
>> Set dt = "a string"
>>
Error Number: 424
Error Description: Object required [because Set wants an object to assign]
No Set, no problem:
>> dt = "a string"
>> WScript.Echo dt
>>
a string
Removing the Set will reveal the next problem: Unless you defined a suitable class and an instance named 'DateTime' of your own, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") will fail with the same error 424.
>> dt = Nix.Now.ToString("")
>>
Error Number: 424
Error Description: Object required [to use its .Now member]
Do a search here for ways to format a date in VBScript. (First hit for "[vbscript] format date": date format in VBS)
The () in the .Write call should be removed; they are not parameter list (), but 'pass me per value' (). See this answer and follow the link to Eric Lippert's article.
What about crear your code and just do this?
<%
dateandtime = now()
response.write dateandtime
%>
To use setyou need a Object.

Classic ASP Type Mismatch with If Then Statement

Can someone please tell me why this is tossing a Type Mismatch using Classic ASP error?
If (strPaidByPO = True) OR (arrResult(0) = "1") Then
'Do Stuff
Else
'Do Other stuff
End if
arrResults is an Array and strPaidByPO is a variable.
Thanks,
Before the If statement type the following (I think you may be making assumptions about the Types).
Call Response.Write(TypeName(strPaidByPO) & "<br />")
Call Response.Write(TypeName(arrResult) & "<br />")
Call Response.Flush()
If your variables are of the type you expected you should get the following output
Boolean
Variant()
Also you might receive this if your Array is multidimensional in which case you need to specify all the dimensions.
The other possibility is arrResult(0) contains something other than a String. In which case use TypeName(arrResult(0)) to check what that is.
Try this and see result based on which you can correct your script:
response.write(cStr(strPaidByPO) & "- My strPaidByPO value<br>")
response.write(arrResult(0) & "- My Array value")
If (strPaidByPO = True) OR (cStr(arrResult(0)) = "1") Then
'Do Stuff
Else
'Do Other stuff
End if
but if your strPaidByPO contain values other then true - false (Boolean) you need to review your approach to this completely. For example if strPaidByPO is NULL or empty your script will trough you an error like you described.

VB6 / Crystal Report 8.5 error: A string is required here

I recently inherited an old visual basic 6/ crystal reports project which connects to a sql server database. The error message I get (Error# -2147191803 A String is required here) when I attempt to run the project seems to be narrowed down to the .Printout command in the following code:
'Login to database
Set Tables = Report.Database.Tables
Set Table = Tables.Item(1)
Table.SetLogOnInfo ConnName, DBName, user, pass
DomainName = CStr(selected)
'Set parameter Fields
'Declare parameter holders
Set ParamDefs = Report.ParameterFields
'Store parameter objects
For Each ParamDef In ParamDefs
With ParamDef
MsgBox("DomainName : " + DomainName)
Select Case .ParameterFieldName
Case "Company Name"
.SetCurrentValue DomainName
End Select
Select Case .Name
Case "{?Company Name}"
.SetCurrentValue DomainName
End Select
'Flag to see what is assigned to Current value
MsgBox("paramdef: " + ParamDef.Value)
End With
Next
Report.EnableParameterPrompting = False
Screen.MousePointer = vbHourglass
'CRViewer1.ReportSource = Report
'CRViewer1.ViewReport
test = 1
**Report.PrintOut**
test = test + 3
currenttime = Str(Now)
currenttime = Replace(currenttime, "/", "-")
currenttime = Replace(currenttime, ":", "-")
DomainName = Replace(DomainName, ".", "")
startName = mPath + "\crysta~1.pdf"
endName = mPath + "\" + DomainName + "\" + DomainName + " " + currenttime + ".pdf"
rc = MsgBox("Wait for PDF job to finish", vbInformation, "H/W Report")
Name startName As endName
Screen.MousePointer = vbDefault
End If
During the run, the form shows up, the ParamDef variable sets the "company name" and when it gets to the Report.PrintOut line which prompts to print, it throws the error. I'm guessing the crystal report isn't receiving the "Company Name" to properly run the crystal report. Does any one know how to diagnose this...either on the vb6 or crystal reports side to determine what I'm missing here?
UPDATE:
inserted CStr(selected) to force DomainName to be a string
inserted msgboxes into the for loop above and below the .setcurrentvalue line
inserted Case "{?Company Name}" statement to see if that helps setting the value
tried .AddCurrentValue and .SetCurrentValue functions as suggested by other forum websites
ruled out that it was my development environement..loaded it on another machine with the exact same vb6 crystal reports 8.5 running on winxp prof sp2 and the same errors come up.
and when I run the MsgBox(ParamDef.Value) and it also turns up blank with the same missing string error. I also can't find any documentation on the craxdrt.ParameterFieldDefinition class to see what other hidden functions are available. When I see the list of methods and property variables, it doesn't list SetCurrentValue as one of the functions.
Any ideas on this?
What is the value of your selected variable?
Table.SetLogOnInfo ConnName, DBName, user, pass
DomainName = selected
'Set parameter Fields
If it is not a string, then that might be the problem. Crystal expects a string variable and when it doesn't receive what it expects, it throws errors.
selected is a string variable input taken from a form with a drop down select box. I previously put a message box there to ensure there the variable is passing through right before the Report.Printout and it does come up. DomainName variable is also declared as a string type.
Here's how I set my parameters in Crystal (that came with .NET -- don't know if it helps you).
Dim dv As New ParameterDiscreteValue
dv.Value = showphone
rpt.ParameterFields("showphone").CurrentValues.Add(dv)
This can happen in crystal reports 8.5 if you changed the length of a string column you use in your report so that it exceeds 255 bytes. This can also happen if you change the column type from varchar to nvarchar (double byte string!)
The reason for this is that crystal reports 8.5 treats all strings longer than 255 bytes as memo fields.
I would suggest youe upgrade to crystal reports XI - the API has not changed that much.
From my point of view you should get the same error message if you open the report in the Crystal Reports Designer and switch to preview mode. The Designer should also show you a message with the exact location of the problem, e.g. the field which can not be treated as a string.
The problem is not that a field longer than 255 bytes cannot be printed. The problem is that a field longer than 255 bytes cannot be used in a formula, as a sort criteria ...
Here is a live example of setting the parameters that we use:
For Each CRXParamDef In CrystalReport.ParameterFields
Select Case CRXParamDef.ParameterFieldName
Case "#start"
CRXParamDef.AddCurrentValue CDate("1/18/2002 12:00:00AM")
Case "#end"
CRXParamDef.AddCurrentValue Now
End Select
Next
This is actually a sample written in VBScript for printing Crystal 8.5 reports, but the syntax is the same for VB6

Resources