VBScript通过将文档拆分为多个无法单独读取的文档来创建谜题

时间:2015-11-20 21:08:39

标签: vbscript char

对于一个寻宝者,我想给我的侄子4个相同的字母,他们必须结合阅读。我在网上找不到任何可以快速使用的东西,所以我写了一篇。如果你有一些想法,我会用更好的代码更新。

'******************  Change things here ****************

'Change the number in perenthesis to set the number of files
Dim Letters(4)

'Set the original filename here:
originalFile = "Letter.txt"

'Set a letter to use as a syncronizer in addition to punctuation and line breaks
charSync = asc("o")

'*********************************************************

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(originalFile , 1)

Do Until objFile.AtEndOfStream
strCharacters = objFile.Read(1)

Randomize
selLetter = Int((Ubound(Letters))*Rnd+1)

If (asc(strCharacters) < 46) or (asc(strCharacters) = charSync) then
    for i = 1 to Ubound(Letters)
         Letters(i) = Letters(i) & strCharacters
    next 
else
    for i = 1 to Ubound(Letters)
        if i = selLetter then
            Letters(i) = Letters(i) & strCharacters
        else
            Letters(i) = Letters(i) & " "
        end if
    next 
end if
Loop

For n = 1 to Ubound(Letters)
outFileName = replace(originalFile ,".",n & ".")
Set objFile = objFSO.CreateTextFile(outFileName,True)
    objFile.Write Letters(n)
    objFile.Close
next

Set objFSO=Nothing

用法:

  1. 创建要随机拆分的文本文件
  2. 编辑以下内容的脚本:
  3. 设置要将其拆分为
  4. 的文档数
  5. 设置要更新的文件的文件名
  6. 如果您想
  7. ,请选择同步字符
  8. 运行脚本,它将创建编号文件
  9. 使用相同的字符间距字体,如系统,通过持有光来阅读

1 个答案:

答案 0 :(得分:0)

'******************  Change things here ****************

'Change the number in perenthesis to set the number of files
Dim Letters(4)

'Set the original filename here:
originalFile = "Letter.txt"

'Set a letter to use as a syncronizer in addition to punctuation and line breaks
charSync = asc("o")

'*********************************************************

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(originalFile , 1)

Do Until objFile.AtEndOfStream
strCharacters = objFile.Read(1)
'uncomment next 2 comments to simplify and change only once per word:
'If strCharacters = " " then
    Randomize
    selLetter = Int((Ubound(Letters))*Rnd+1)
'end if

If (asc(strCharacters) < 46) or (asc(strCharacters) = charSync) then
    for i = 1 to Ubound(Letters)
         Letters(i) = Letters(i) & strCharacters
    next 
else
    for i = 1 to Ubound(Letters)
        if i = selLetter then
            Letters(i) = Letters(i) & strCharacters
        else
            Letters(i) = Letters(i) & " "
        end if
    next 
end if
Loop

For n = 1 to Ubound(Letters)
outFileName = replace(originalFile ,".",n & ".")
Set objFile = objFSO.CreateTextFile(outFileName,True)
    objFile.Write Letters(n)
    objFile.Close
next

Set objFSO=Nothing

用法:

  1. 创建要随机拆分的文本文件
  2. 编辑以下内容的脚本:
  3. 设置要将其拆分为
  4. 的文档数
  5. 设置要更新的文件的文件名
  6. 如果您想
  7. ,请选择同步字符
  8. 运行脚本,它将创建编号文件
  9. 使用相同的字符间距字体,如系统,通过持有光来阅读