VB scripting I'm in need of help

Status
Not open for further replies.

mikesx4911

In Runtime
Messages
356
Location
chicago, IL
Well I just started a new class COMP230 and I hate it, I do not understand really anything of the whole concept of programming I have read the book, and followed the excersies given to me. Currently I'm trying to work on a script here it is.

' VBScript:
' Written by: Michael Ikezoe
' Date: 5/9/2012
' Class: COMP230
' Professor:
' ==================================================================================

' Create name and age variables
name = "John Doe"
ageStr = 50


'Calculate Age+10 and assign to ageStr10
ageStr10 = CStr( CInt(ageStr)+10 )

' Build output as a signle string msgStr
msgStr = "Your name is " & vbTab & vbTab & name & _
vbCrLf & "Your age is " & vbTab & vbTab & ageStr & _
vbCrLf & vbCrLf & "Your Age in 10 years will be ...... " & _
ageStr10 & vbCrLf & vbCrLf & "End of Program"

WScript.Echo(vbCrLf & "Your Age in 10 years is ........... " & _
ageStr10 & vbCrLf)
WScript.Echo("End of Program")
' Pause Routine
WScript.Sleep(6000)


Here is what I am trying to accomplish. When I run my script it only shows, "Your age in 10 years is ...." I need it to say your name is John Doe, your age is 60, your age in 10 years will be 60. Where did I go wrong at? I put the name as John Doe, I put the age in at 60.


• Delete the “WScript.StdOut.WriteLine(“ portion of the remaining lines and replace it “WScript.Echo “. Also remove the closing parentheses from each of these lines. For example the line: WScript.StdOut.Writeline(“Your name is “ & vbTab & vbTab & name) would be replaced with WScript.Echo “Your name is “ & vbTab & vbTab & name. Make the same changes for the remaining lines.

• Also change the lines” name = “” to name = “John Doe” and AgeStr = “” to AgeStr = 50.


• Lastly remove WScript.StdIn.Read(1) line that we used for a pause replace it the statement WScript.Sleep(6000) which will give us a 6 second (6000 millisecs) delay before the console window closes.

• Save the program (<Ctrl>S) and press <F5>. Change “The Program to Run” to cscript C:\Scripts\PopUpWindow.vbs. Click Run. You should get the console output shown below.

I'm
 
After looking it over, I noticed I have the msgStr all correct but it is not writing because I do not have a command to output. So I need to put ECHO somewhere in there, this is where I'm stuck I have tried

WScript.Echo
msgStr = "Your name is " & vbTab & vbTab & name & _
vbCrLf & "Your age is " & vbTab & vbTab & ageStr & _
vbCrLf & vbCrLf & "Your Age in 10 years will be ...... " & _
ageStr10 & vbCrLf & vbCrLf & "End of Program"

and

WScript.Echo msgStr = "Your name is " & vbTab & vbTab & name & _
vbCrLf & "Your age is " & vbTab & vbTab & ageStr & _
vbCrLf & vbCrLf & "Your Age in 10 years will be ...... " & _
ageStr10 & vbCrLf & vbCrLf & "End of Program"

none of those worked for me.
 
If you're assembling the msgStr correctly but you're outputting the wrong text then the logical thing to do would be to make sure that the argument to echo is msgStr. You don't need to add another echo, all you need to do is change the one you already have.
 
Code:
WScript.Echo(vbCrLf & "Your Age in 10 years is ........... " & _
ageStr10 & vbCrLf)
WScript.Echo("End of Program")
' Pause Routine
WScript.Sleep(6000)

Change the argument of the echo to just your msgStr variable.
 
Code:
WScript.Echo(vbCrLf & "Your Age in 10 years is ........... " & _
ageStr10 & vbCrLf)
WScript.Echo("End of Program")
' Pause Routine
WScript.Sleep(6000)

Change the argument of the echo to just your msgStr variable.

So it should be

WScript.Echo (msgStr)

I'm not 100% sure on what you mean by this, keep in mind I have only been in this class 1 week lol.
 
I haven't done VB for a long time, but I believe so. Try it and see if it works; good thing about code, is if something doesn't work, you can always change it back ;).
 
I haven't done VB for a long time, but I believe so. Try it and see if it works; good thing about code, is if something doesn't work, you can always change it back ;).

yup I do like being able to screw it up as much as I want, but you can spend a whole week guessing lol. Which I dont have all the time in the world unfortunately lol.
 
Status
Not open for further replies.
Back
Top Bottom