2015-08-07 3 views
0

В приведенном ниже VBScript представлены два файла с использованием ввода из диалогового окна ввода. Ниже я хотел бы добавить имя файла (fileName) в document.write('Confirm file"&filename&" completed'); в файл JavaScript, созданный в сценариях ниже.Добавить имя переменной в HTML-разметки

Но когда я это делаю, оно возвращается как имя переменной в кавычки так же, как написано выше, а не сама переменная. Я знаю, что это связано с кавычками, но я потерял то, что нужно делать. Любая помощь будет оценена по достоинству.

fileName=InputBox("Enter a Name for the new SubRoutine: ","Enter Value","NewRoutine") 

CreateFolder 
CreateHTML 
CreateJS 

Sub CreateHTML 
    Set objFS = CreateObject("Scripting.FileSystemObject") 
    Set objNewFile = objFS.CreateTextFile(fileName&"\"&fileName&".html") 
    objNewFile.WriteLine "<html>" 
    objNewFile.WriteLine "<head>" 
    objNewFile.WriteLine "<title>Created by Robot--MM</title>" 
    objNewFile.WriteLine "</head><body>" 
    objNewFile.WriteLine "<script type='text/javascript'  src='"&fileName&".js'></script>" 
    objNewFile.WriteLine "<script>"&fileName&"()</script>" 
    objNewFile.WriteLine "</body>" 
    objNewFile.WriteLine "</html>" 
    objNewFile.Close 
End Sub 

Sub CreateJS 
    Set objFS = CreateObject("Scripting.FileSystemObject") 
    fileName2 = fileName & ".js" 
    Set objNewFilejs = objFS.CreateTextFile(fileName&"\"&fileName&".js") 
    objNewFilejs.WriteLine "var "&fileName&" = function() { window.alert('Hi,This is an alert from the file : "&fileName2&"');" 
    objNewFilejs.WriteLine "document.write('Confirmed file loaded.'); }" 
    objNewFilejs.Close 
End Sub 

Sub CreateFolder 
    Set objShell = CreateObject("Wscript.Shell") 
    strPath = Wscript.ScriptFullName 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objFile = objFSO.GetFile(strPath) 
    strFolder = objFSO.GetParentFolderName(objFile) 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objFolder = objFSO.CreateFolder(strFolder & "/"&fileName) 
    objShell.Run objFolder 
    Set Sh = Nothing 
End Sub 
+0

Линия вы имеете в виду ('document.write («Confirm файл „и имя файла и“ завершено»);') даже не появляется в коде, который размещен. – Bond

+0

Да, потому что он не работает. «Подтвердить загрузку файла» в 5-й строке Sub CreateJS - это местоположение, в котором я бы хотел, чтобы линия прошла. Благодарю . – JSJunkie

+1

Вы должны отредактировать свой вопрос, чтобы показать свой код точно, как он работает, когда он не работает. – Bond

ответ

0

Я сделал это упрощенным ответом. Я понял, что у меня есть котировки в неправильном месте. Вот решение с несколькими обновлениями.

fileName = InputBox("Please enter a name for your new files:", _"Create File") 
    US =    CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%") 

    Sub CreateHTML 
    Set objFS = CreateObject("Scripting.FileSystemObject") 
    Set objNewFile = objFS.CreateTextFile(US &"\Desktop\"& fileName&".html") 
    objNewFile.WriteLine "<html>" 
    objNewFile.WriteLine"<link rel = 'stylesheet' href='"&fileName&".css'>" 
    objNewFile.WriteLine "<head>" 
    objNewFile.WriteLine "<title>Created by Robot--MM</title>" 
    objNewFile.WriteLine "</head><body>" 
    objNewFile.WriteLine "<script type='text/javascript'  src='"&fileName&".js'></script>" 
    objNewFile.WriteLine "<script> "&fileName&"()""</script>" 
    objNewFile.WriteLine "</body>" 
    objNewFile.WriteLine "</html>" 
    objNewFile.Close 
    End Sub 



    CreateHTML 


    Sub CreateJS 
    Set objFS = CreateObject("Scripting.FileSystemObject") 
    Set objNewFilejs = objFS.CreateTextFile(US &"\Desktop\"& fileName&".js") 
    objNewFilejs.WriteLine "window.alert('Hi,This is an alert from the file ');" 
    objNewFilejs.WriteLine "document.write('Document loaded')" 
    objNewFilejs.Close 
    End Sub 


    CreateJS 


    Sub CreateCSS 
    Set objFS = CreateObject("Scripting.FileSystemObject") 
    Set objNewFileCSS = objFS.CreateTextFile(US &"\Desktop\"& fileName&".css") 
    objNewFilecss.WriteLine "body {text-align:center;font-family:'Zapfino',serif;}" 
    objNewFilecss.Close 
    End Sub 

    CreateCSS 
Смежные вопросы