Solved

VBS Input box to display warning/error if empty

Posted on 2010-11-18
8
1,808 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 350 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

Independent Software Vendors: 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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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