I have to support an old web server developed in classic ASP and VBScript. I am running on Windows 7 with IIS 7.5.
I followed all the instructions on configuring the IIS from this article.
The web page loads, but it looks like the JS doesn't see functions in VBScript.
I have this code:
<%# Language=VBScript %>
<!-- #include file="HebrewMeta_UTF8.jv"-->
<link rel="stylesheet" type="text/css" href="../Class.css">
<html>
<head>
<%
Nm=Request("Nm")
%>
<title>my page</title>
</head>
<script LANGUAGE="javascript">
var Nm = "<%=Nm%>";
function onCheckPro() {
nm = window.navigator.appName;
if ((nm.indexOf("Explorer") == "-1") && (nm.indexOf("Netscape") == "-1")){
alert(" Compatibility שינוי הגדרות ");
window.open("http://www.comax.co.il/InstallTools/compatibility-view.reg");
//alert("ניתן להפעיל באקספלורר בלבד");
//return;
}
document.all.fr.src = "CheckLogInPro.asp?Kod=" + escape(Kod.value) + "&Pass=" + escape(Pass.value) + "&Date=" + vbDate();
}
</script>
<script LANGUAGE="vbscript">
function vbDate()
vbDate=Cstr(Day(Date()))+"/"+Cstr(Month(Date()))+"/"+Cstr(Year(Date()))+" "+Cstr(hour(Now()))+":"+Cstr(Minute(Now()))+":"+Cstr(Second(Now()))
end function
</script>
I keep on getting "'vbDate' is undefined".
The script language of the site ASP is set to VBScript.
Not an answer, but three warnings:
vbDate is a predefined data type constant; using it to name a function is asking for trouble.
The string concatenation in VBScript is &, not +.
Volatile functions like Date() or Now() shouldn't be used more than once in an expression.
Update wrt comment:
People who like to live dangerously should look at:
WScript.Echo vbDate(), checkType(Now())
Function vbDate()
vbDate = "vbDate is a predefined constant: >" & vbDate & "<"
End Function
Function checkType(x)
Select Case VarType(x)
Case vbDate
checkType = x & " is a date"
Case Else
checkType = x & " is an abomination"
End Select
End Function
output:
cscript xvbdate.vbs
vbDate is a predefined constant: >< 11/14/2014 3:48:17 PM is an abomination
output after changing the function's name:
cscript xvbdate.vbs
vbDate is a predefined constant: >7< 11/14/2014 3:56:57 PM is a date
before using any variable you should give a data type to that variable
dim or var
vbDate
vbDate=Cstr(Day(Date()))+"/"+Cstr(Month(Date()))+"/"+Cstr(Year(Date()))+" "+Cstr(hour(Now()))+":"+Cstr(Minute(Now()))+":"+Cstr(Second(Now()))
Related
I had a procedure that scraped information from a website in IE9 however after updating to IE11 the procedure breaks when trying to enter a piece of data into
an input box on the webpage. The code recognizes the field and it is listed as on object when I debug but when I try to enter a value into the box using CUSIP.value it does not enter anything on the webpage. I think it has something to do with the source being updated after the browser was updated. I could have sworn that the identifier for "txtCusipNo" in the HTML was listed as an ID instead of a Name. Any help is appreciated. Thanks.
HTML from website
<td class="tbl1">
<INPUT TYPE="TEXT" NAME="txtCusipNo" VALUE="" CLASS="input" SIZE="11" MAXLENGTH="9">
<img src="/RDPANN/pbs/images/lookup.gif" border="0" alt="Open Security Finder" align="absmiddle"> <IMG NAME="txtCusipIMG"SRC="/RDPANN/pbs/images/req.gif" ALIGN="ABSMIDDLE">
</td>
VBA code
Private Sub EnterCUSIP()
Retry:
Set CUSIP = Doc.getElementById("txtCusipNo")
Err.Clear
valA = ActiveSheet.Cells(row, 1)
On Error Resume Next
CUSIP.Value = ActiveSheet.Cells(row, 1) 'insert CUSIP
If Err.Number = 91 Then GoTo Retry
Set CurrentWindow = IE.document.parentWindow
Call CurrentWindow.execScript("javascript:processForm(document.forms.frmSearchEntry)") 'Search (hit enter)
If Err.Number = -2147352319 Then Exit Sub
On Error GoTo 0
Do While (IE.Busy Or IE.READYSTATE <> READYSTATE.READYSTATE_COMPLETE):DoEvents: Loop
End Sub
If you suspect that the HTML source has been changed and may make unannounced changes in the future, I would recommend switching to the ie.Document.All.Item property.
Doc.all.Item("txtCusipNo").Value = 123
The .Item identifier can be either an ID or a Name, there is no distinction between the two. However, I would be concerned that the identifying factor (e.g. txtCusipNo) may not be unique on that page. Yes, it is supposed to be but a growing number of HTML developers are using code like divs(0).getElementById("txtCusipNo") and divs(1).getElementById("txtCusipNo").
In classic ASP (VBScript), when I replace the string, a strange character appears.
<%
myString = "My Ttitle ®"
myString = Replace(myString,"®", "®")
Response.Write(myString)
%>
If I print this out to HTML, the final result is (Which has a strange A in it):
My Ttitle ®
add this at the top of your page <%# language="vbscript" codepage="65001"%>
open your file in a text editor, (notepad will do) select Save As from the file menu and choose utf-8 rather than ANSI encoding
add in your head section <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> (this isn't actually necessary but it doesn't do any harm)
Further information here
http://www.hanselman.com/blog/InternationalizationAndClassicASP.aspx
Change
myString = Replace(myString,"®", "®")
to
myString = Replace(myString,"®", "®")
Your website encoding is most likely wrong. Add this before your myString declaration.
response.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">')
I need a way to find the difference between two strings in a Windows application using VBScript. One of the strings is known but the second one is completely unknown during coding. I know there are functions like StrCompare, InStr etc. but these require you to know the second string also during coding.
Explanation:
There is a text box in the screen and there are several buttons in the same screen. As and when the buttons are clicked, the text in the text box changes depending on the button clicked. Is there a way to find the changes made to the text after the button is clicked ? Basically I need to get the text entered due to the button click. Is there a simple way to do this or it requires complex coding ?
Thanks in Advance.
It depends on your application and the format of the new string.
If you need to find the text appended to the original string, you could take the new text and simply replace the first occurrence of the original string with an empty string:
Dim strOld, strNew, strDiff
strOld = "Apple"
strNew = "Apple, Orange"
strDiff = Replace(strNew, strOld, "", 1, 1)
WScript.Echo strDiff
Sample output:
, Orange
Or if you need to get the appended text without the preceding comma, you could use something like this:
strDiff = Replace(strNew, strOld + ", ", "", 1, 1)
To access (read/write) the content of a HTML text input you need to get the HTML element (document.all.<Name/Id> or document.getElementById(<Name/Id>) and its .value; as in this demo:
<html>
<head>
<Title>readtext</Title>
<hta:application id="readtext" scroll = "no">
<script type="text/vbscript">
Function Change()
document.all.txtDemo.value = "Changed Value"
End Function
Function Check()
Dim txtDemo : Set txtDemo = document.getElementById("txtDemo")
Dim sDemo : sDemo = txtDemo.value
Select Case LCase(Trim(sDemo))
Case "initial value"
MsgBox "still: " & sDemo
Case "changed value"
MsgBox "now: " & sDemo
Case Else
MsgBox "surpise: " & sDemo
End Select
End Function
</script>
</head>
<body>
<input type="text" id="txtDemo" value="Initial Value" />
<hr />
<input type="button" value="Change" onclick="Change" />
<input type="button" value="Check" onclick="Check" />
</body>
</html>
I'm using Inno Setup to create a desktop shortcut that opens an HTA file saved in Program Files on Windows 7. This HTA file calls an external exe file that needs to run as administrator.
So, to do this, I want to automatically create a shortcut that runs as admin using Inno Setup. The problem here is that the shortcut points to an HTA file instead of an exe. How do I go about doing that?
check this sample:
<html>
<head>
<title>HTA Helpomatic</title>
<HTA:APPLICATION
ID="oHTA"
APPLICATIONNAME="HTAHelpomatic"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
<!-- ID="objHTAHelpomatic" -->
<!-- WINDOWSTATE="maximize" -->
</head>
<SCRIPT Language="VBScript">
If HTAElevate() = True Then
CreateObject("WScript.Shell").Run "mmc.exe compmgmt.msc", , True
Call Main()
End If
Sub Main()
MsgBox "HTA-Ende", 4096
End Sub
'*** v13.3 *** www.dieseyer.de *****************************
Function HTAElevate()
'***********************************************************
' http://dieseyer.de/scr/elevate.hta
' Unter Windows x64 laufen VBS' nach einem Doppelklick in der x64-Umgebung
' mit %WinDi%\System32\wscript.exe oder mit %WinDi%\System32\cscript.exe.
' In der x64-Umgebung laufen VBS aber nicht (richtig). Die Prozedur
' HTAElevate() erkennt dies und startet ggf. das VBS in der
Const Elev = " /elevated"
' MsgBox oHTA.commandLine, , "5016 :: "
' Trace32Log "5018 :: oHTA.commandLine: ==" & oHTA.commandLine & "==", 1
HTAElevate = True
' If InStr( LCase( oHTA.commandLine ), Elev) > 0 then MsgBox oHTA.commandLine, , "5022 :: "
If InStr( LCase( oHTA.commandLine ), Elev) > 0 then Exit Function
On Error Resume Next
window.resizeto 750, 10 ' : window.moveto screen.width / 2, screen.height / 2
On Error GoTo 0
' MsgBox oHTA.commandLine, , "5030 :: "
createobject("Shell.Application").ShellExecute "mshta.exe", oHTA.commandLine & Elev, "", "runas", 1
HTAElevate = False
self.close
End Function ' HTAElevate()
</SCRIPT>
<body>
</body>
</html>
The direct answer to the question is to create the shortcut to mshta.exe with the HTA's filename as its parameter. The shortcut to mshta.exe can be marked to run as administrator.
If your executable requires admin access, then you should add an appropriate manifest to your executable, not try and elevate the HTML application.
my application should perform some simple actions in Excel, like adding charts, list objects and so on. I'm using OLE connection. The problem is, that some Excel methods taking built-in types (enumerations) as arguments. And I have no ideas about referring to them. For example:
WorkBook.ActiveSheet.ListObjects.Add(xlSrcRange, Range("$D$5:$J$15"), , xlNo).Name = "Table1"
xlSrcRange and xlNo belong to the built-in enumeration. I tried to refer to them in a following way
ExcelApp.xlSrcRange
ExcelApp.XlListObjectSourceType.xlSrcRange
ExcelApp.XlListObjectSourceType
this code causes error "Object doesn't support property or method ExcelApp.xlSrcRange"
New XlListObjectSourceType.xlSrcRange
new xlSrcRange
this code causes an error too (unknown variable XlListObjectSourceType and xlSrcRange)
I'm working with QTP and the script language is VB-script
A .wsf script can access the xl* constants via a Excel.Sheet reference:
type xlconst.wsf
<?xml version="1.0" standalone="yes" encoding="iso-8859-1" ?>
<package>
<job id="xlconst">
<reference object="Excel.Sheet" reference="true"/>
<script language="VBScript">
<![CDATA[
' ############################################################################
For Each arg In WScript.Arguments.Unnamed
WScript.Echo "Const " & arg & " = " & Eval(arg)
Next
' ############################################################################
]]>
</script>
</job>
</package>
output:
cscript xlconst.wsf xlNo xlYes
Const xlNo = 2
Const xlYes = 1
Plain VBScript can't. If QTP is restricted to plain VBScript, you'll have to add/define the constants manually. Perhaps the above .wsf will make this task easier.
How about using fully qualified name?
dim sourceType As Excel.XlListObjectSourceType
sourceType = Excel.XlListObjectSourceType.xlSrcRange
EDIT: (in vbscript)
dim sourceType
sourceType = 1