对于一个寻宝者,我想给我的侄子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
用法:
答案 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
用法: