Help with: Wrong number of arguments or invalid propety assignment here

2

I just started with the VBS language and I'm doing things, here I am doing a vbs generator that has msgbox with 2 answers, but I get the error that appears in the title with the SendKeys on line 17.

result=inputbox("Titulo")
Mensaje=inputbox("Pregunta del Msgbox")
rsp1=inputbox("Respuesta afirmativa")
rsp2=inputbox("Respuesta negativa")
vel=200
titulo=inputbox("Titulo del msgbox")

O = Chr(34)
C = Chr(40)
D = Chr(41)

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad.exe", 9

WScript.Sleep 500

WshShell.SendKeys "x=msgbox"" & O & "" & Mensaje & "" & O & ",4+64," & O & "" & titulo & "" & O & "

WScript.Sleep vel

WshShell.SendKeys "if x=7 then MsgBox"" & O & "" & rsp2 & "" & O & ",0+64," & O & "" & titulo & "" & O & "

WScript.Sleep vel

WshShell.SendKeys "if x=6 then MsgBox"" & O & "" & rsp1 & "" & O & ",0+64," & O & "" & titulo & "" & O & "

WScript.Sleep vel

WshShell.SendKeys "%{f4}"
WScript.Sleep vel

WshShell.SendKeys "{ENTER}"
WScript.Sleep vel

WshShell.SendKeys "" & result & ".vbs"

WScript.Sleep vel

WshShell.SendKeys "{ENTER}"

So you can see it better: link

    
asked by Celestial 03.08.2017 в 20:15
source

1 answer

2

Good, your main error is in the concatenation, it is normal to get confused between what you want to write and what you write. I went to correct the sentences and in turn I want to clarify some points: For example:

WshShell.SendKeys "x=msgbox{(}" & O & Mensaje & O & ",4 {+} 64," & O & titulo & O & "{)}"

You will notice the differences in the use of quotes (") and concatenators (&), but in the syntax there was an error, the assignment to a variable from a sub routine or function (in this case the MsgBox) uses the parentheses as you used correctly in the ImputBox in the first lines, in this case I had to put in brackets the special characters (the parentheses "(", ")" and "+") so that the SendKeys would send it.

The rest would remain like this:

WScript.Sleep vel
WshShell.SendKeys "{ENTER}"
WScript.Sleep vel
WshShell.SendKeys "if x=7 then MsgBox" & O & rsp2 & O & ",0 {+} 64," & O & titulo & O
WScript.Sleep vel
WshShell.SendKeys "{ENTER}"
WScript.Sleep vel
WshShell.SendKeys "if x=6 then MsgBox" & O & rsp1 & O & ",0 {+} 64," & O & titulo & O

PS: It would be better to use a text editor such as Notepad ++ or VbsEdit to help you with the syntax and color what is string or it is variable so as not to get dizzy when concatenating.

    
answered by 31.01.2018 в 20:18