cancel
Showing results for 
Search instead for 
Did you mean: 

Script aborting due to invalid data entry. Error checking needed.

Former Member
0 Kudos

I recorded the following script with the script recorder. I have added the inputbox to prompt for the network number from the user. I have also added the msgbox command to display the 'user status' of the network. Here is the problem... if the network entered by the user is not valid, the script aborts and shows a windows script host modal box displaying the error "control could not be found by id". Of course, the msgbox command is not executed. How can I check for a valid network and display a message to the user and loop back?

If Not IsObject(application) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

Set connection = application.Children(0)

End If

If Not IsObject(session) Then

Set session = connection.Children(0)

End If

If IsObject(WScript) Then

WScript.ConnectObject session, "on"

WScript.ConnectObject application, "on"

End If

Dim Network

Network = InputBox("Enter Network: ")

session.findById("wnd[0]/tbar[0]/okcd").text = "cn23"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/ctxtCAUFVD-AUFNR").text = Network

session.findById("wnd[0]").sendVKey 0

Msgbox session.findById("wnd[0]/usr/tabsTABSTR_2100/tabpTRMN/ssubSUBSCR_2100:SAPLCOKO:2110/txtCAUFVD-ASTTX").text

Accepted Solutions (0)

Answers (2)

Answers (2)

CountZero
Explorer
0 Kudos

Hi,

What I would do have a seperate routing for checking the network.

So


Public function CheckNetwork(Network)
 On error goto Error_Handler
  session.findById("wnd[0]/tbar[0]/okcd").text = "cn23"
  session.findById("wnd[0]").sendVKey 0

  session.findById("wnd[0]/usr/ctxtCAUFVD-AUFNR").text = Network
  session.findById("wnd[0]").sendVKey 0
  CheckNetwork = true
exit function
Error_Handler:
  CheckNetwork = false
End Function

Then you can say something like


Dim Network
Network = InputBox("Enter Network: ")
If CheckNetwork(Network) = true then
'do the rest of the code
else
' print an error message
endif.

The only issue you have is that if something else goes wrong in the CheckNetwork routine you could be reporting an incorrect error message. If you want to loop back then you could use a DO WHILE loop but don't make it infinate or else your users will get upset. This might look like the following


Dim Network
Dim NetworkCheck
Dim Counter
Counter = 1
NetworkCheck = false
Do
Network = InputBox("Enter Network: ")
NetworkCheck = CheckNetwork(Network)
Counter = Counter + 1
loop until (Counter > 10 or NetworkCheck = true)

I have not run the above code so it might not be 100%.

Hope this helps

Nath

Former Member
0 Kudos

Were you able to find a solution for this ?????

if so please could you send me the solution.