我可以在我的数据库工具中运行此查询没有问题:
UPDATE table1
SET NAME = 'John'
WHERE userid IN (SELECT Max(userid)
FROM table1
WHERE userid = NULL)
Run Code Online (Sandbox Code Playgroud)
这成功运行.当我尝试从VBScript运行这个完全相同的语句时,我没有得到任何错误,并且不会发生更新.谁能告诉我我做错了什么?
Public Function GetAvailableRow()
Dim conn, command
On Error Resume Next
Set conn = CreateObject("adodb.connection")
Set command = CreateObject("adodb.command")
conn.IsolationLevel = 1048576
conn.Open "Driver={Adaptive Server Enterprise}; Server=myserver;port=myport; db=mydatabase;uid=userid;pwd=password;"
command.ActiveConnection = conn
command.CommandText = "UPDATE table1 SET name = 'John' WHERE userid in (SELECT MAX(userid) from table1 where userid = NULL)"
conn.BeginTrans
command.Execute
conn.CommitTrans
conn.Close
Set command = Nothing
Set conn = Nothing …Run Code Online (Sandbox Code Playgroud) vbscript中以下的值是什么?
1)x=1+"1"
2)x="1"+"1"
3)x=1+"mulla"
注意:在以上三种情况中,我使用第一个变量作为字符串或整数,第二个作为字符串使用.
情况1:在操作期间作为数字和自动转换为数字
enter code here
y=inputbox("Enter a numeric value","") Rem I am using 1 as input
x=1
msgbox x+y Rem value is 2
msgbox x*y Rem value is 1
Run Code Online (Sandbox Code Playgroud)
情况2:作为一个字符串,在操作期间没有转换为数字,它失败了
enter code here
y=inputbox("Enter a numeric value","") Rem I am using 1 as input
x=1
if y= x then
msgbox "pass"
else
msgbox "fail"
end if
Run Code Online (Sandbox Code Playgroud)
情况3:在操作过程中作为字符串和显式转换为数字
enter code here
y=inputbox("Enter a numeric value","") Rem I am using 1 as input
x=1
if Cint(y) = x …Run Code Online (Sandbox Code Playgroud) 当我运行我的代码时,我在第15行收到错误"对象变量未设置".我不是每次都得到它.这似乎是随机的.我已经搜索过,但找不到任何理由.我遇到的问题是变量没有一直被清除,所以我刚添加第42行设置strText = Nothing.我没有正确设置变量的问题消失了,但现在我有了这个.任何帮助将不胜感激.代码如下.
Option Explicit
Dim i, objFSO, objFile, strText, Fields, TimeStamp, Location, MachNum, Amount, Theme, objSMFile, SMLine, p, CSVLine, objReportFile, FileName
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Do while i<>1
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\Print\output.txt") Then
'*** Clean up CR/LF and Make CSV Variable ***
Set objFile = objFSO.OpenTextFile("C:\Print\output.txt", ForReading)
If Not objFile.AtEndOfStream Then strText = objFile.ReadAll
objFile.Close
' WScript.Sleep 1000
objFSO.CopyFile "C:\Print\output.txt", "C:\Print\outputCopy.txt"
objFSO.DeleteFile("C:\Print\output.txt")
' WScript.Sleep 3000
strText = Replace(strText, vbCrlf, "")
strText …Run Code Online (Sandbox Code Playgroud) 我写了一个小程序来帮助我学习如何使用VBScript中的对象数组,并且我得到的结果并没有多大意义.我不明白为什么当我打印出来时整个数组都填满了最后一个对象条目.
Class TestObj
Public id
End Class
Dim arr()
Set tObj = new TestObj
Public Function fillArray()
ReDim arr(10)
For i = 0 To 9 Step 1
Call createObj()
Set arr(i) = tObj
Next
'Print the array in this function
Print ("Printing from fillArray function")
For i = 0 To 9 Step 1
Print ("arr("&i&"):"& arr(i).id)
Next
Call printArray()
End Function
Public Function createObj()
max = 100
min = 1
Randomize
randInt = (int((max-min+1)*Rnd+min))
Print ("Random Integer is: " &randInt) …Run Code Online (Sandbox Code Playgroud) 我一直在关注有关将VBA转换为VBScript的文章和问题,但我现在卡住了.以下代码仍然适用于VBA(如果我删除Sub例程调用)但它不会作为脚本运行.
该代码打开与SQL Server的连接以检查表以查看该进程是否已在今天运行并将结果加载到Recordset中.如果该字段设置为No然后它打开Excel工作簿并运行宏.它适用于VBA,但是当我运行与脚本相同的代码时,没有任何事情发生(也没有错误).
你能看出问题所在吗?非常感谢.
NB.有两行cmd.CommandText.注释掉的行旨在始终返回No以仅用于测试目的.
' Author Steve Wolstencroft
' Inititates the Automated Excel Refresh Procedure
Option Explicit
Pivot_Refresh
Public Function ConnectToSQLDwarfP()
On Error Resume Next
ConnectToSQLDwarfP = "Driver={SQL Server Native Client 10.0};Server=DwarfP;Database=DwarfPortable;Trusted_Connection=yes;"
End Function
Public Sub Pivot_Refresh()
On Error Resume Next
Dim cnx
Dim Rst
Set cnx = New ADODB.Connection
cnx.ConnectionString = ConnectToSQLDwarfP
cnx.Open
Dim cmd
Set cmd = New ADODB.Command
cmd.ActiveConnection = cnx
cmd.CommandType = adCmdText
cmd.CommandText = "Select Case When max(DwarfPortable.dbo.fn_GetJustDate(pl.StartDateTime)) …Run Code Online (Sandbox Code Playgroud) 我需要获取子匹配字符串的索引位置值。根据文档,我已经阅读了此正则表达式并了解了FirstIndex属性以获取匹配字符串的位置。
但这仅适用于一维匹配的字符串。我无法申请子FirstIndex比赛。请参考样本匹配
我尝试过这种格式,
Dim myRegExp As Object, match As MatchCollection
Dim matched As String
Set myRegExp = CreateObject("VBScript.RegExp")
myRegExp.pattern = find
If myRegExp.test(text) = True Then
Set match = myRegExp.Execute(text)
Debug.Print match(0).submatches(0) '' this is matched string
Run Code Online (Sandbox Code Playgroud)
我应该在哪里打电话FirstIndex以获得匹配的字符串的位置
输出:
match(0)=>Berry, Brent. (2006). What accounts for race and ethnic differences in Berry,
Brent. parental financial transfers to adult children in the United States? Journal of Family
Issues 37:1583-1604.
submatches(0)=>Berry, Brent.
submatches(6)=>2006
Run Code Online (Sandbox Code Playgroud)
预期的输出: …
我对以下内容感到困惑,希望我能学到一些东西.当我运行以下代码时:
<%
Response.Write "ss = ""1""<br/>"
ss = "1"
Response.Write "ii = 50<br/>"
ii = 50
Response.Write "ss >= ii "
If ss >= ii Then Response.Write "True?" Else Response.Write "False"
Response.Write "<br/>""1"" >= 50 "
If "1" >= 50 Then Response.Write "True" Else Response.Write "False"
%>
Run Code Online (Sandbox Code Playgroud)
它写道:
ss = "1"
ii = 50
ss >= ii True?
"1" >= 50 False
Run Code Online (Sandbox Code Playgroud)
MSDN说 如果操作数是一个数字和一个字符串比较是字符串被转换为双精度并执行数字比较.如果无法将String转换为Double,则抛出InvalidCastException.
我正在使用ASP版本5.8,内部版本号18525.
我不需要一个解决方法,因为我有一个,但我想知道是否有一个原因,因为它是一个容易犯的错误.
编辑:选择正确的答案有一个注释,其中包含2个比较之间差异细节的进一步链接.
我不确定以下代码有什么问题.
Set obj=description.Create()
obj("micClass").Value="Link"
obj("name").Value="Advertising Programs"
Set totalnobuttons=Browser("title:=.*").Page("title:=.*").ChildObjects(obj)
totalnobuttons.highlight
print totalnobuttons.count
For i=0 to totalnobuttons.count-1
print totalnobuttons(i).GetRoProperty("name")
Next
Run Code Online (Sandbox Code Playgroud)
这会在执行期间出现错误"对象不支持此属性或方法错误".我需要使用上面的代码突出显示"广告计划"程序链接.
我一直在努力使手动过程更像是一次点击过程,而且我遇到了来自vbs脚本的这些msgbox弹出窗口的问题.基本上我使用的是powershell并做了类似的事情:
foreach ($loc in $locs):
& cscript $loc
Run Code Online (Sandbox Code Playgroud)
$ locs中的$ loc是一个变量,其中包含需要运行的.vbs文件的路径.
问题是我们的一个开发人员在每个.vbs文件中包含两个msgbox语句,弹出这些语句并要求您单击确定.编辑vbs脚本并删除它们是微不足道的,但我不想改变我们的开发人员的脚本 - 所以问题是:是否有可能使PowerShell对从cscript行生成的msgbox做出反应?我不确定如何将盒子带入上下文或通过PowerShell对它做出反应.
我想搜索从.txt文件中选取的字符串,用双引号括起来的数字.我正在用Excel宏做这一切.示例数据:
"08134789316498"
"022"
Run Code Online (Sandbox Code Playgroud)
我的代码:
Set oRegex1 = CreateObject("VBScript.RegExp")
oRegex1.Pattern = "(\"[0-9]+\"])"
Run Code Online (Sandbox Code Playgroud)
但上面这行是错误的:
"编译错误:预期结束语句"
注意:我已经添加了对"Microsoft VBScript Regular Expressions 5.5"和"Microsoft VBScript Regular Expressions 1.0"的引用