![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-10-24 03:18 |
47,815 topics / 349,928 posts / today 1 new / 48,287 members |
| DOS批处理 & 脚本技术(批处理室) » If we find the maximum value of a set of temperature record values in 1 text and make a judgment |
| Printable Version 3,177 / 20 |
| Floor16 wudixin96 | Posted 2007-05-12 17:34 |
| 银牌会员 Posts 931 Credits 1,928 | |
Originally posted by zhoushijay at 2007-5-12 04:26 PM: 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 ] |
|
| Floor17 zhoushijay | Posted 2007-05-13 10:56 |
| 高级用户 Posts 375 Credits 845 | |
|
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 ] |
|
| Floor18 slore | Posted 2007-05-13 11:19 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
t = mid(ln, 17, 2)
t = mid(ln, 17, 3) ? Then T is only one? |
|
| Floor19 slore | Posted 2007-05-13 11:24 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
Fortunately, there are spaces after it.
XX C XXX C You take 3 digits... "XX " or "XXX" after INT becomes XX and XXX. |
|
| Floor20 zhoushijay | Posted 2007-05-13 12:18 |
| 高级用户 Posts 375 Credits 845 | |
|
Then just take 3 digits.
|
|
| Floor21 sonicandy | Posted 2007-05-13 18:54 |
| 中级用户 Posts 91 Credits 273 | |
|
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 |
|
| Prev 1 2 |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |