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-08-06 23:54
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] How to use VBS code to implement finding and writing strings? View 2,169 Replies 17
Original Poster Posted 2007-12-12 19:51 ·  中国 北京 鹏博士BGP
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
How to use VBS code to find a certain string in a text file and write it to another file? (Output the lines containing the string)

[ Last edited by s11ss on 2007-12-14 at 04:24 PM ]
Floor 2 Posted 2007-12-12 20:47 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
open file
str = read file
colse flie
str=~
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
s11ss +4 2007-12-12 21:06
Floor 3 Posted 2007-12-12 21:10 ·  中国 北京 鹏博士BGP
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Does Brother vkill know if there is a clear screen command similar to cls when executing VBS with cscript?
Floor 4 Posted 2007-12-13 20:30 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Originally posted by s11ss at 2007-12-12 21:10:
Does brother vkill know if there is a screen-clearing command similar to cls when executing vbs with cscript?

Unknown, it seems that except for cmd, there is no screen-clearing function.
Floor 5 Posted 2007-12-13 20:48 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by vkill at 2007-12-13 20:30:

Unknown, it seems that except for cmd, there is no function to clear the screen.

hta can have
Floor 6 Posted 2007-12-13 21:37 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
How to clear the screen in HTA?
Floor 7 Posted 2007-12-14 00:29 ·  中国 福建 三明 电信
高级用户
★★
论坛上抢劫的
Credits 551
Posts 246
Joined 2006-09-21 12:35
19-year member
UID 63270
Status Offline
Can you explain the code in more detail?
Floor 8 Posted 2007-12-14 02:09 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
It's not really clearing the screen, but replacing it with empty or hiding

The running mode of HTA itself is different from batch processing


<html>
<title>cls</title>
<HTA:APPLICATION
ID="MyhyliApp"
APPLICATIONNAME="cls"
BORDER="thin"
BORDERSTYLE="normal"
VERSION="1.0"
SCROLL="no"
INNERBORDER="yes"
CONTEXTMENU="yes"
CAPTION="yes"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
NAVIGABLE="yes"
/>

<script language="VBScript">

windowswidth = 640
windowsheight = 480
window.resizeTo windowswidth, windowsheight
ileft=(window.screen.width-windowswidth)/2
itop=(window.screen.height-windowsheight)/2
window.moveTo ileft,itop

</script>

<body bgcolor=#e0e0e0>

<table align="center">
<tr>
<td align="center">Clear and then refresh with F5</td>
</tr>
<tr>
<td id="Menu" align="center"></td>
</tr>
</table>


<table width="100%" style="position:absolute; bottom:20px;"><td>
<table align="center" style="font:bold 15px 宋体;">
<tr align="center">
<td><button onclick="CLS1" style="width:100;">Clear Content</button></td>
</tr>
<tr align="center">
<td><button onclick="CLS2" style="width:100;">Hide Content</button></td>
</tr>
</table>
</td></table>

</body>

<script language="VBScript">

Menu.innerHTML = "Test<br>Test<br>Test<br>Test<br>Test<br>"

Sub CLS1
Menu.innerHTML = ""
End Sub

Sub CLS2
Menu.style.display = "none"
End Sub

</script>

<html>
Floor 9 Posted 2007-12-14 15:00 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Specify 1 character
file=Wscript.ScriptFullName
'file=WScript.Arguments(0)
Dim str
set str = CreateObject("Adodb.Stream")
str.Type = 1
str.Mode = 3
str.Open
str.Loadfromfile file
Bin=str.read(6)
Usage = MidB(Bin,6,1)
str.Close
set str = Nothing
WScript.echo "The character at the 6th byte of this script is “",Usage,"”"
第一高手 第二高手

Floor 10 Posted 2007-12-14 15:39 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
The question is: Do you want to output the line that contains the character, or output that character if it exists?
Floor 11 Posted 2007-12-14 16:23 ·  中国 北京 鹏博士BGP
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Please provide the specific content from the China DOS Union (中国DOS联盟) forum so that I can accurately output the line containing characters.
Floor 12 Posted 2007-12-14 16:42 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
```vb
Set fso = CreateObject("Scripting.FileSystemObject")

source = "a.txt"
strFind = "b"

Set f = fso.OpenTextFile(source, 1)
While Not f.AtEndOfStream
strRead = f.ReadLine
If InStr(strRead, strFind) > 0 Then
MsgBox strRead
End If
Wend
f.Close
```
Floor 13 Posted 2007-12-14 17:03 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Which byte in the text, newline + 2
第一高手 第二高手

Floor 14 Posted 2007-12-14 20:16 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Dig out an old post and post it up

set fso=createobject("scripting.filesystemobject")
If fso.FileExists("text.txt")=0 then 'Check if the text.txt file exists
fso.createtextfile("text.txt")
end if
set file=fso.opentextfile("text.txt",8) 'Open the file in append mode
set opfile=fso.opentextfile("a.txt") 'Open the file
do while opfile.atendofstream=false
line=opfile.readline 'Read a line of content
if instr(line,"Search character")>0 then 'Judge if it contains the search character
str=str&line&vbcrlf 'Add to buffer
end if
loop
file.writeline (str) 'Write the line with the search character to the text.txt file
简单!简单!再简单!
Floor 15 Posted 2007-12-16 10:48 ·  中国 福建 三明 电信
高级用户
★★
论坛上抢劫的
Credits 551
Posts 246
Joined 2006-09-21 12:35
19-year member
UID 63270
Status Offline
Originally posted by zh159 at 2007-12-14 16:42:
Set fso = CreateObject("Scripting.FileSystemObject")

source = "a.txt"
strFind = "b"

Set f = fso.OpenTextFile(source,1)
While not f.AtEndOfStream
strRe ...

What if there are multiple characters!! I have a text file list.txt, which has abc, will, www, etc. (all one word per line). Can I find them all at once instead of having to reassign strFind every time I run the VBS?
Forum Jump: