?
Solved

VBS Input box to display warning/error if empty

Posted on 2010-11-18
8
Medium Priority
?
1,919 Views
Last Modified: 2012-05-10
Hi I am working on a simple script below to ask a user a few questions.

On the input boxes I would like it to come with an error if the users does not input anything into the boxes and not go to the new step until the user has entered data.

if inbox is empty then error

Thanks!
Dim kNameFirst
Dim kNameLast
Dim EmailAdd
MsgBox "welcome"
kNameFirst = InputBox("first name")
kNameLast = InputBox("last name")
EmailAdd = InputBox("email?")
MultiUsrPC = InputBox("shared pc?")

Dim objNetwork, objDrives, intIndex, objFSO, objFile, objUser, strUsername
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
strUsername = objUser.samAccountName

Set objFSO = CreateObject("Scripting.FileSystemobject")
Set objFile = objFSO.OpenTextFile("\\shared\results.csv", 8, True)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 
Set colComputer = objWMIService.ExecQuery("Select Name from Win32_ComputerSystem")
Set colComputerIP = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration")

For Each objComputer In colComputer
    strHostName = objComputer.Name
Next
For Each IPConfig In colComputerIP
	If Not IsNull(IPConfig.IPAddress) Then 
        For intIPCount = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
			If strIPAddress = "" Then
				strIPAddress = IPConfig.IPAddress(intIPCount)
			Else
				strIPAddress = strIPAddress & " | " & IPConfig.IPAddress(intIPCount)
			End If
		Next
	End If
Next

Set objNetwork = CreateObject("WScript.Network")
Set objDrives = objNetwork.EnumNetworkDrives
For intIndex = 0 To objDrives.Length - 1 Step 2
        objFile.WriteLine  """" & strUsername & """,""" & kNameFirst & """,""" & kNameLast & """,""" & EmailAdd & """,""" & strHostName & """,""" & strIPAddress & """,""" & MultiUsrPC & """,""" & objDrives(intIndex) & """,""" & objDrives(intIndex + 1) & """"
Next
objFile.Close
Set objFile = Nothing
Set objUser = Nothing
Set objFSO = Nothing
Set objDrives = Nothing
Set objNetwork = Nothing

MsgBox "Complete",0,"Complete"

Open in new window

0
Comment
Question by:Eirejp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 10

Accepted Solution

by:
hosneylk earned 1400 total points
ID: 34170881
Try something like this
Do
   kNameFirst = InputBox("first name")
   If Len(kNameFirst) = 0 Then MsgBox "Error"
Loop While Len(kNameFirst) = 0

Open in new window

0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34170890
or add a function
Function getInput(msg)
   Do
      inputVal = InputBox(msg)
      If Len(inputVal) = 0 Then MsgBox "Error"
   Loop While Len(inputVal) = 0
   myfunction = inputVal 
End Function

and call it like this

kNameFirst = getInput("first name")

Open in new window

0
 
LVL 1

Author Closing Comment

by:Eirejp
ID: 34170900
Thanks!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Eirejp
ID: 34170905
Actually one last thing. Sorry I know I already close the question.

Now that the look works how about if a user press the cancel button to exit? Is that possible.

if blank then error
if cancel then exit
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34170931
try this..
Do
   kNameFirst = InputBox("first name")
   If Len(kNameFirst) = 0 Then MsgBox "Error"
   If VarType(kNameFirst ) = vbEmpty Then End
Loop While Len(kNameFirst) = 0

Open in new window

0
 
LVL 1

Author Comment

by:Eirejp
ID: 34170970
I get a expected statement error

Do
      kNameFirst = InputBox(firstname)
      if Len (kNameFirst) = 0 Then MsgBox "Error please enter something"
      if VarType (kNameFirst) = vbEmpty Then End
Loop While Len(kNameFirst) = 0
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34171038
that was kinda pseudo code.

replace End with WScript.Quit (1)
0
 
LVL 1

Author Comment

by:Eirejp
ID: 34171067
Fantastic! Thank you
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question