Trying to call a function again if a value for ValidData is not entered. When I press Enter without entering any data, the function simply quits. Any ideas? Thanks.
strNewProfPath = ValidData Function ValidData WScript.StdOut.WriteLine "Enter new profile server and share: " ValidData = WScript.StdIn.ReadLine If ValidData = "" Then WScript.Echo "User profile cannot be set to nothing." WScript.Echo strNewProfPath = ValidData End If WScript.Echo End Function
Posts: 54
Score: 0
Joined: 5/4/2005
From: USA
Status: offline
Try this out. I think your problem was that you have to give a value of some type to the string or you get a value of null which vbscript can't handle. So you just give it a value of one space and it works. Also, you just had to call the function again, you didn't have to reset the value of strnewProfPath because you had not finished running ValidData yet. Hope this helps.
strNewProfPath = ValidData Function ValidData WScript.StdOut.WriteLine "Enter new profile server and share: " ValidData = WScript.StdIn.ReadLine & " " If ValidData = " " Then WScript.Echo "User profile cannot be set to nothing." WScript.Echo ValidData End If WScript.Echo End Function
In function ValidData() the Name "ValidData" means the variable used to specify the return value of the function. If you just press enter after the prompt, this variable is set to "".
means
To call the Function, use
but consider, that ValidData is still "" after the second call of ValidData(). I would start from something like this:
Setting the quotes as you mentioned, produced the same effect.
Within the function, I then tried removing strNewProfPath = and left ValidData. That seemed to help but... Say I hit the enter key ten times and then enter a server name and path. The recursion works, but when I finally enter valid data, all the previous blank entries are echoed to the screen and the valid data doesn't appear to get assigned to strNewProfPath.