Mad Libs: Difference between revisions

Content added Content deleted
No edit summary
m (→‎{{header|VBScript}}: improved formatting)
Line 2,933: Line 2,933:


=={{header|VBScript}}==
=={{header|VBScript}}==
<lang vb>
<lang vb>Function mad_libs(s)
Do
Function mad_libs(s)
If InStr(1,s,"<") <> 0 Then
Do
If InStr(1,s,"<") <> 0 Then
start_position = InStr(1,s,"<") + 1
start_position = InStr(1,s,"<") + 1
end_position = InStr(1,s,">")
parse_string = Mid(s,start_position,end_position-start_position)
end_position = InStr(1,s,">")
WScript.StdOut.Write parse_string & "? "
parse_string = Mid(s,start_position,end_position-start_position)
input_string = WScript.StdIn.ReadLine
WScript.StdOut.Write parse_string & "? "
s = Replace(s,"<" & parse_string & ">",input_string)
input_string = WScript.StdIn.ReadLine
Else
s = Replace(s,"<" & parse_string & ">",input_string)
Exit Do
Else
End If
Exit Do
Loop
End If
mad_libs = s
Loop
mad_libs = s
End Function
End Function


WScript.StdOut.Write mad_libs("<name> went for a walk in the park. <he or she> found a <noun>. <name> decided to take it home.")
WScript.StdOut.Write mad_libs("<name> went for a walk in the park. <he or she> found a <noun>. <name> decided to take it home.")
WScript.StdOut.WriteLine
WScript.StdOut.WriteLine</lang>
</lang>


{{Out}}
{{Out}}
<pre>F:\>cscript /nologo mad_libs.vbs
<pre>
F:\>cscript /nologo mad_libs.vbs
name? babe
name? babe
he or she? she
he or she? she
noun? cat
noun? cat
babe went for a walk in the park. she found a cat. babe decided to take it home.
babe went for a walk in the park. she found a cat. babe decided to take it home.</pre>
</pre>


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==