Making a Console Application ask something and receive input - windows

I have Programming in Basic in High School and was tasked with a project in which I was to make a program that says hello to the teacher as well as give a paragraph describing why programming is valuable in today's time.
My initial idea was to make a program that greets and asks the teacher a question on whether they want to know why programming is valuable. When the console asks the question there will be two options: Yes or No. Each having their own text output.
REM Period 6 Class Project for (My Name)
Dim input = Console.ReadLine
Dim Yes = input
Dim No = input
Console.WriteLine("Hello, would you like to get an explanation as to why programming is valuable?")
input = Console.ReadLine
If input = Yes Then
Console.WriteLine("Well the reason why...")
End If
Where I'm having trouble is actually making the text appear on the application as well as receiving input on whether the code is correct as well.

See if .. then .. else
input=input.ToLower().Trim()
If input="yes" then
...
ElseIf input="no" then
...
Else
..' unexpected answer
End if

Related

SAS Enterprise Guide with VBScript. Looping through SAS programs get stuck

I'm facing a random problem. When executing SAS programs with VBScript and the SASEGObjectModel.Application.7.1, looping through CodeCollection get stuck sometimes, even if the program execution was succeeded (the final data bases are correctly created in our server). The script simple doesn't go to the next program of CodeCollection (the prompt executing the script still open... ad infinitum). The SAS program It happens is random, also the frequency. I'm going with something like this:
Dim oSasApp
Set oSasApp = CreateObject("SASEGObjectModel.Application.7.1")
oSasApp.SetActiveProfile("some-profile")
Dim oSasProj
Set oSasProj = oSasApp.Open("some-project.egp", "")
Dim oProgramList
Set oProgramList = oSasProj.CodeCollection
Dim programOrder
Set programOrder = ...here I assign the SAS programs order array reading from a .txt...
For Each program in programOrder
For Each sasProgram in oProgramList
If sasProgram.Name = program Then
sasProgram.Run
sasProgram.Log.SaveAs "some-folder/" & sasProgram.Name & ".txt"
End If
Next
Next
oSasProj.Close
oSasApp.Quit
The problem is not the Log saving, as the log txt file of the stucked program is also correctly created.
Any idea? Maybe problems in our SAS server? Should I declare some kind of options?
SAS Guide version: 7.15
Windows: 10
Tks
So... for people facing the same problem. As I commented above, if I press enter on prompt the script flows again. So it is waiting for my input, for reasons I can't tell. I did 2 things to get around it. Not sure if all of them are necessary or if only one solves it, but here it goes:
First, by VBScript I turned off a list of generations and I applied a delay after the SAS program runs:
For Each program in programOrder
For Each sasProgram i oProgramList
If sasProgram.Name = program Then
sasProgram.GenSasReport = False
sasProgram.GenHTML = False
sasProgram.GenListing = False
sasProgram.GenPDF = False
sasProgram.GenRTF = False
sasProgram.Run
WScript.Sleep(2000)
sasProgram.Log.SaveAs "some-folder/" & sasProgram.Name & ".txt"
End If
Next
Next
Them, in my batch file, wich I use to call the VBScript with the "cscript" command, I set it to apply "y" to every single message the VBScript could ask:
cd ./script-folder
echo y | cscript script-file-name.vbs
And that is it.

Ruby script for RPG Maker Ace VX, case sensitive ID is octal number

I have inserted a script to make a Journal Quest written by Modern Algebra. It works perfectly but when I tried to input an Item ID, 128, I get an error telling me that the number is an octal. I tried converting the number into a string "128" but the program crashes. This is part of the code:
q[:name] = "Fish for the Inn"
q[:icon_index] = 028
I'm very new to Ruby.
Can you please tell me how to solve this problem?
Thanks!

Why won't my VBS Spam Bot work?

I am working on a Spam bot in VBS. However, something is wrong with the code. Whenever I run the VBS my computer lags then crashes. I know it is a bit basic, hence why I am asking the more experienced. Please give me the right code in order for it to work.
Option Explicit
Dim x,y,obj,v,o
Set obj=CreateObject("Wscript.Shell")
x=inputbox("What would you like to spam?")
v=inputbox("How many times would you like to spam?")
o=inputbox("How many seconds do you want to select the textbox?")
wscript.sleep o & 000
do until y=v
obj.SendKeys (x & "{ENTER}")
y=y+1
loop
wscript.quit
~ Thanks
A helpful tip you probably didn't notice as you did say you were quit inexperienced with VBS -
wscript.sleep o & 000
The ampersand (&) is a character with the logical equivalent of and, similar to or and not, in that they are logic, and is used in if statements to check whether both, for example, foo and bar are equivalenet to each other; for example:
variable1 = true
variable2 = true
if(variable1 & variable2) return true
else return false
This would return true, as both variables are set to true.
I understand you were trying to get the milliseconds from the user input of seconds. It might be better achieved by making a variable:
o = o * 1000;
Then, as you got this data in the form of string, parse it into an integer form:
milSeconds = CInt(o);
Probably a good idea to check whether o had non-numeric characters beforehand to prevent errors.
Hope this can help you continue working on it. Even though spam-bots are generally frowned upon here, I like to think they're a good learning exercise.

Use of SAPI Speech Recognition in a VBS Script?

I found this one-line example that allows to use the Windows SAPI Text-to-Speech feature in VBScript:
CreateObject("SAPI.SpVoice").Speak("This is a test")
I wonder if the SAPI Speech Recognition could be used in a VBScript program in the same easy way. When I seek for such information the tons of SAPI information that appear are related to C++, like the Microsoft SAPI site, or to Text-to-Speech in VBS. I tried to find documentation about the SAPI COM object Speech Recognition part that could be used in a VBScript, but found none.
Do you know if such a documentation exists? TIA
EDIT: Additional request added after the first answer was recevied
Although the first answer below provide a link to the SAPI COM object documentation, I want to attract your attention to a point in my question: "I wonder if the SAPI Speech Recognition could be used in a VBScript program IN THE SAME EASY WAY". The SAPI documentation is huge! I read several pages of it and I am completely lost... My goal is to recognize just a few single words, say 8 or 10, and show a different message in the screen each time that one of they was recognized; that is it! (The program should be a console application started via cscript). Is there a simple example of VBS code that achieve such thing? If the required code to program this solution needs to have several pages, then it is not the answer I am looking for...
Here is a working example of vbscript listening a wav file:
scriptRunning = true
Sub rc_Recognition(StreamNumber, StreamPosition, RecognitionType, Result)
Wscript.Echo "Reco: ", Result.PhraseInfo.GetText, ".", RecognitionType
End Sub
Sub rc_StartStream(StreamNumber, StreamPosition)
Wscript.Echo "Start: ", StreamNumber, StreamPosition
End Sub
Sub rc_EndStream(StreamNumber, StreamPosition, StreamReleased)
Wscript.Echo "End: ", StreamNumber, StreamPosition, StreamReleased
scriptRunning = false
End Sub
outwav = "C:\SOFT\projects\af2t\t.wav"
Const SAFT22kHz16BitMono = 22
Const SSFMOpenForRead = 0
set sapiFStream = CreateObject("SAPI.SpFileStream")
sapiFStream.Format.Type = SAFT16kHz16BitMono
sapiFStream.Open outwav, SSFMOpenForRead
MsgBox "A SpeechLib::ISpRecoContext object will be created"
Const SGDSActive = 1
Set rct = WScript.CreateObject("SAPI.SpInProcRecoContext", "rc_")
Set rgnz = rct.Recognizer
Set rgnz.AudioInputStream = sapiFStream
Set rcGrammar = rct.CreateGrammar
'rcGrammar.DictationLoad
rcGrammar.DictationSetState SGDSActive
i = 0
while scriptRunning and i < 100
WScript.Sleep(50)
i = i + 1
wend
MsgBox "A SpeechLib::ISpRecoContext object has been created"
The magical part of the code is this line (the "rc_" prefix param allows events to be caught by the subs):
Set rct = WScript.CreateObject("SAPI.SpInProcRecoContext", "rc_")
The recorded text in the t.wav file I used for testing has been generated with SAPI.SpVoice::Speak and MS-David voice ;-)
I spent 10 days figuring out how to write this script. Microsoft is removing documentation about automation, COM, old style scripts, etc. A shame.
So, this works in dictation mode reading a wav file. But I couldn't correct it to make it work in live dictation mode (i.e. using the microphone as direct input). Any help appreciated for this. Thanks.
EDIT: direct/live dictation mode solved. If interested I share the vbscript code.
EDIT2: text sample spoken in the wav: Hello world. This is a talk about gear tooth profile using a circle involute.
Console output from the vbscript
C:\SOFT\projects\af2t>cscript r.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. Tous droits réservés.
Start: 1 0
Reco: Hello world . 0
Reco: this is a talk about gear to the profile using a circle invalid . 0
End: 1 195040 -1
C:\SOFT\projects\af2t>
Yes. Look at the SAPI Automation Overview; it will tell you all about the late-bound COM interfaces and objects available to VBScript.

Can anyone see what is wrong with my code?

My code is as follows:
a=msgbox("Do you like waffles",4+16,"Waffles")
Do While a=vbno
a
Loop
if a=vbyes then
b=msgbox("Do you like pancakes",4+16,"Pancakes")
Do While b=vbno
b
loop
if b=vbye then
c=msgbox("Do you like French toast",4+16,"French toast")
Do While c=vbno
c
Loop
else
d-msgbox("good",0+16,"YAY!")
end if
I know it is basic, but it comes up with the error message: "Error: Expected 'End'"
But as you can see 'end' is at the start of line 17, if it is something I haven't seen some where else in the code that might be causing this. I'm kind of new to this language and was putting things I knew how to do into a semi-useful paten.
I saved it as a .bat file and ran it using cmd.
Here is the original code posted in the question (as I'm writing this):
a=msgbox("Do you like waffles",4+16,"Waffles")
Do While a=vbno
a
Loop
if a=vbyes then
b=msgbox("Do you like pancakes",4+16,"Pancakes")
Do While b=vbno
b
loop
if b=vbye then
c=msgbox("Do you like French toast",4+16,"French toast")
Do While c=vbno
c
Loop
else
d-msgbox("good",0+16,"YAY!")
end if
A main error cause seems to be a notion that one can assign a definition to a variable. Well one can, but not in that way. Here is corrected code:
option explicit
dim answer
do
answer = msgbox("Do you like waffles",4+16,"Waffles")
if answer = vbYes then exit do
answer = msgbox("Do you like pancakes",4+16,"Pancakes")
if answer = vbYes then exit do
answer = msgbox("Do you like French toast",4+16,"French toast")
if answer = vbYes then exit do
loop
call msgbox( "good",0+16,"YAY!" )
There are however umpteen zillion ways to prepare food, and so also with code, plus, it's not clear if the above is the intention, but I guess it's pretty close.
At any rate, it's code that works and that you can build further on
Note that VBScript documentation is now only available as a CHM compiled help file, called "script56.chm".
The VBScript documentation is both available as a handy CHM compiled help file, called "script56.chm", as well as online in the MSDN library.
Note: you need to save the source code as a .vbs file.

Resources