Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在文本文件中逐行输出字符串?_Html_Windows_Vbscript - Fatal编程技术网

Html 如何在文本文件中逐行输出字符串?

Html 如何在文本文件中逐行输出字符串?,html,windows,vbscript,Html,Windows,Vbscript,我jsut使这个htm与vbs一起工作,但我在testbox中逐行输入一些内容,它在一行中将所有内容输出到文本文件中。。。。如何使输出行与文本框中输入的字符串相同 另一个问题是,是否可以只使用一个按钮来“输出”和“运行批处理”,而不是单击两次 这是我的代码,另存为htm文件: <html> <head> <title>Release To Production Files Sync To Mexico</title> </head>

我jsut使这个htm与vbs一起工作,但我在testbox中逐行输入一些内容,它在一行中将所有内容输出到文本文件中。。。。如何使输出行与文本框中输入的字符串相同

另一个问题是,是否可以只使用一个按钮来“输出”和“运行批处理”,而不是单击两次

这是我的代码,另存为
htm
文件:

<html>
<head>
<title>Release To Production Files Sync To Mexico</title>

</head>

<script language="vbscript">

Sub WriteTxt_OnClick()
    Dim fso, txt

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set txt = fso.CreateTextFile("C:\work\test.txt")

    txt.WriteLine document.Submitted_Link_To_Mex.body.value

    MsgBox "File Submitted",64,"Selection"


End Sub

Sub SYNC_onClick()
     Set WshShell = CreateObject("WScript.Shell")
     WshShell.Run "C:\work\test.bat", 0
            ' 0 => hide cmd
     MsgBox("Success")

End Sub
</script>


<H2>Copy And Paste The Folder Path To Here </H2>
<body>


<form name="Submitted_Link_To_Mex">
<textarea name="body" cols="150" rows="20">

</textarea>
</form>

<br>
    <input type="button" value="1. SUBMIT" name="WriteTxt"> &nbsp; &nbsp; &nbsp;
    <input type="Button" value="2. SYNC" name="SYNC"> &nbsp; &nbsp; &nbsp;

</div>

</body>
</html>

发布到生产文件同步到墨西哥
子写入文本_OnClick()
Dim fso,txt
设置fso=CreateObject(“Scripting.FileSystemObject”)
Set txt=fso.CreateTextFile(“C:\work\test.txt”)
txt.WriteLine document.Submitted\u Link\u To\u Mex.body.value
MsgBox“文件已提交”,64,“选择”
端接头
子同步_onClick()
设置WshShell=CreateObject(“WScript.Shell”)
运行“C:\work\test.bat”,0
'0=>hide cmd
MsgBox(“成功”)
端接头
将文件夹路径复制并粘贴到此处


它将数据作为单行写入,因为您声明程序将数据作为单行写入。是的,当有人在文本区域中点击“回车”时,它通过换行符组件或在vbscript“vbcrlf”中分隔行

所以要解决这个问题,你可以走两条路

只需在写入块中直接写入整个内容:

Sub WriteTxt_OnClick()
     Dim fso, txt

     Set fso = CreateObject("Scripting.FileSystemObject")
     Set txt = fso.CreateTextFile("C:\work\test.txt")

     txt.Write document.Submitted_Link_To_Mex.body.value

     MsgBox "File Submitted",64,"Selection"


End Sub
这里的关键是:“.Write”而不是.WriteLine

如果需要,可以检查内容并拆分

Sub WriteTxt_OnClick()
    Dim fso, txt

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set txt = fso.CreateTextFile("C:\work\test.txt")
    dim tmp : tmp = document.Submitted_Link_To_Mex.body.value
    if instr(tmp, vbcrlf) then
    dim all_lines : all lines = split(tmp, vbcrlf)
    for each line in all_lines
    txt.WriteLine line
    next
    txt.Close
End Sub
是的,你可以从另一艘潜艇上呼叫潜艇,就像这样:

Sub Call_Sub1
    dim foo : foo = "i am horrible at deciphering bad english translations of dracula"
    Call_Sub2 foo
End Sub
Sub Call_Sub2(str)
    dim bar : bar = left(str, 40) 
End Sub