[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2171
  • Last Modified:

VBS Input box to display warning/error if empty

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
Eirejp
Asked:
Eirejp
  • 4
  • 4
1 Solution
 
hosneylkCommented:
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
 
hosneylkCommented:
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
 
EirejpAuthor Commented:
Thanks!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
EirejpAuthor Commented:
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
 
hosneylkCommented:
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
 
EirejpAuthor Commented:
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
 
hosneylkCommented:
that was kinda pseudo code.

replace End with WScript.Quit (1)
0
 
EirejpAuthor Commented:
Fantastic! Thank you
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now