China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-26 03:20
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » If we find the maximum value of a set of temperature record values in 1 text and make a judgment View 2,406 Replies 20
Floor 16 Posted 2007-05-12 17:34 ·  中国 浙江 杭州 联通
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Originally posted by zhoushijay at 2007-5-12 04:26 PM:
set fso=createobject("scripting.filesystemobject")
set op=fso.opentextfile("1.txt",1)
set d=createobject("scripting.dictionary")
on error resume next
for i=1 to 10 ...


Using FOR, it seems that using WHILE would be better.
Loop using the op.atendofstream property.

Didn't look closely at slore's reply. Just posting water. o(∩_∩)o... Haha

[ Last edited by wudixin96 on 2007-5-12 at 05:38 PM ]
Floor 17 Posted 2007-05-13 10:56 ·  中国 新疆 乌鲁木齐 电信
高级用户
★★★
Autowalk
Credits 845
Posts 375
Joined 2007-03-03 01:58
19-year member
UID 80606
Gender Male
Status Offline
After the suggestion from floor 13, I made a little modification. But I still think the dictionary is more convenient. The main reason for the last mistake was the algorithm error in extracting the largest number from the set. Now it has been corrected and tested.

set fso=createobject("scripting.filesystemobject")
set op=fso.opentextfile("1.txt",1)
set d=createobject("scripting.dictionary")
i=1
do until op.atendofstream=true
ln=op.readline
t=mid(ln,17,3)
on error resume next
t=int(t)
if err=0 then
d.add i,t
end if
i=i+1
loop
mx=0
for each i in d
if d(i)>mx then
mx=d(i)
end if
next

if mx>45 and mx<90 then
msgbox("Temperature is OK"&chr(10)&"The hotest is "&mx&"C")
else
msgbox("Temperature is NG"&chr(10)&"The hotest is "&mx&"C")
end if

[ Last edited by zhoushijay on 2007-5-13 at 12:19 PM ]
你好,脚本专家!
<a target=blank href=tencent://message/?uin=29654761&Site=www.111.com&Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:29654761:5 alt="点击这里给我发消息"></a>
Floor 18 Posted 2007-05-13 11:19 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
t = mid(ln, 17, 2)

t = mid(ln, 17, 3)
? Then T is only one?
Floor 19 Posted 2007-05-13 11:24 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Fortunately, there are spaces after it.

XX C
XXX C

You take 3 digits... "XX " or "XXX" after INT becomes XX and XXX.
Floor 20 Posted 2007-05-13 12:18 ·  中国 新疆 乌鲁木齐 电信
高级用户
★★★
Autowalk
Credits 845
Posts 375
Joined 2007-03-03 01:58
19-year member
UID 80606
Gender Male
Status Offline
Then just take 3 digits.
你好,脚本专家!
<a target=blank href=tencent://message/?uin=29654761&Site=www.111.com&Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:29654761:5 alt="点击这里给我发消息"></a>
Floor 21 Posted 2007-05-13 18:54 ·  中国 北京 利达宽带
中级用户
★★
Credits 273
Posts 91
Joined 2007-05-07 18:12
19-year member
UID 87770
Gender Male
Status Offline
Option Explicit 'Strict syntax
Dim reg, matches, match, file, max, flag, submatch, fso, temp

Set fso = CreateObject("scripting.filesystemobject")'Create FSO object
Set reg = new regexp 'Create regular expression object

reg.global = True 'Global search
reg.ignorecase = True 'Ignore case
reg.pattern = "CT : *([0-9\-]+) +C" 'Matching pattern string (regular expression)
flag = False 'Mark whether it is the first loop
Set file = fso.opentextfile("1.txt",1)

If Not file.atendofstream Then 'File is not empty
Set matches = reg.execute(file.readall()) 'Execute search
For Each match In matches 'Iterate all matches
For Each submatch In match.submatches 'Iterate matching sub-items (content in parentheses in pattern string)
temp = Int(submatch) 'Transform into positive number
Next
If flag=False Then 'First time direct assignment
max = temp
flag = True
ElseIf max<temp Then 'Comparison assignment later
max = temp
End if
Next
End If

If max>45 And max<90 Then
MsgBox "OK"
Else
MsgBox "NG"
End If

'Release object
Set reg = Nothing
Set fso = Nothing
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
baomaboy +11 2007-05-13 19:02
Forum Jump: