我的vbscript文件存在此问题。它实际上从第一个文件读取数据并使用它与第二个文件中的值进行比较。如果有匹配必要的事情。此代码适用于第一个文件的第一个值。但是对于第二个输入错误显示为此阵列是固定的或临时锁定的。我在互联网上搜索,发现问题是固定大小的数组,可以通过redim函数解决。我不知道这是正确的解决方案。这是完整的代码。提前谢谢。
set fs = CreateObject("Scripting.FileSystemObject")
set shell = CreateObject("Wscript.Shell")
set file =fs.OpenTextFile("C:\wamp\www\order.csv",1,false)'Read from orders.csv (Current Orders)
set output =fs.OpenTextFile("C:\wamp\www\completed-orders.csv",8)'Output file. All Completed Order's Number are placed here
Set tempfile = fs.CreateTextFile("C:\wamp\www\temp-order.csv",true) 'Create temporary text files to store the line numbers to be deleted
set p=fs.OpenTextFile("C:\wamp\www\current.csv",1,false)'Read the path to the current Stock Data File
path=p.ReadLine
p.close()
path = Trim(path)
set n=fs.OpenTextFile(path,1,false)'Read the data from it and check for name match and then whether current price is >= order price.
line=0
'format of line in order.csv written from php 'fwrite($file,$company."||".$price."||".$oid."||".$type."||".$email
do while file.AtEndOfStream<>true
lin=file.ReadLine
Wscript.Echo line
Wscript.Echo lin
if lin="" Then
noerr=false
else
noerr=true
end if
Wscript.Echo noerr & " error variable"
if noerr Then
temp=Split(lin,"||") 'Read the first order (id,price)
i=0
for each data in temp
If i=0 Then
namestock=data
ElseIf i=1 Then
target=CDbl(data)
ElseIf i=2 Then
orderid=data
ElseIf i=3 Then
buysell=data
ElseIf i=4 Then
transtype=data
ElseIf i=5 Then
emailto=data
ElseIf i=6 Then 'Bharti Airtel ||300.90||100000004||BUY||INTR||email@hotmail.com||5||1506.45585 format of lin
nos=CInt(data)
Else
totalprice=CDbl(data)
End If
i=i+1
next
do while n.AtEndOfStream <>true 'Compare against current data
stock=Split(n.ReadLIne,"||")
j=0
for each name in stock
If j=0 Then
If StrComp(namestock,name,1)=0 Then
Wscript.Echo namestock & " name matched"
check = true
j=j+1
Else
Exit For
End If
Else If j=1 Then
If buysell="BUY" Then
If CDbl(name) <=target Then
tempfile.WriteLine(line) 'Add the line to temporary file if condition is satisfied.
output.WriteLine(orderid) 'Write orderno to complete-orders
shell.run "send.vbs 1 "& emailto &" "& target &" "& buysell &" "& transtype &" "& nos &" "&totalprice &" "& namestock & " Order Completed"
Wscript.Echo "sended"
End If
ElseIf buysell="SELL" Then
If CDbl(name) >=target Then
tempfile.WriteLine(line) 'Add the line to temporary file if condition is satisfied.
output.WriteLine(orderid) 'Write orderno to complete-orders
shell.run "send.vbs 1 "& emailto &" "& target &" "& buysell &" "& transtype &" "& nos &" "&totalprice &" "& namestock & " Order Completed"
End If
End If
Exit Do
End If
End If
next
loop
end if
line=line+1
loop
n.close()
tempfile.close()
file.close()
output.close()
这是我的微型项目的一部分。一个简单的股票市场系统。这段代码用于订单是否被系统接受。它对第一行的预期工作正常,但对于order.csv的第二行,但由于stock变量发生错误,它不起作用。
答案 0 :(得分:0)
你的整个方法都存在缺陷。您尝试阅读来自all
的{{1}}行n
的{{1}}行。如果没有每次打开(和关闭)each
,这都行不通。
您应该编辑您的问题,以便通过一些示例数据披露您的真实世界问题/您想要实现的目标。然后就可以给你有用的建议。