How check if exists the field? SAP GUI Scripting - sap-gui

How check if exists the field?
I tried it:
If session.findById("wnd[1]").setFocus Then

you can try e.g. the following:
on error resume next
session.findById("wnd[1]").setfocus
if err.number = 0 then
msgbox "The SAP GUI element exists."
else
msgbox "The SAP GUI element does not exist."
end if
on error goto 0
Regards,
ScriptMan

To avoid using error handling you can use:
If Not session.findById("wnd[1]", False) Is Nothing Then
session.findById("wnd[1]").setFocus
End If
The key here is the second parameter in FindById which determines if it raises an error or not if the field or any object in SAP exists. If it is set to False there is no error raised and the object is set to Nothing which you can check as in my code.

If the question is how to see if there's a second window: wnd[1]
This should work:
Sub test()
If session.Children.Count = 2 then
'your code goes here
End If
End Sub
It also has the advantage that it doesn't need to use error handling to work,
so another type of error could occur and still be handled.

Related

Controls and null reference exception

I'm aware that the NullReferenceException is pretty much the equivalent to the check engine light on a car but with this particular case I can't seem to pinpoint why its not working properly, I've never really messed with controls so I'm a bit unfamiliar in with the technicalities of it. What I have works, but I keep getting the exception when I run a trycatch around it. Here is what I have.
Dim TypeControl As Control
TypeControl = MaterialHeader_Edit1.FindControl("cboType")
DBTable = MaterialStuff.GetMaterial(ID)
Using DBTable
If DBTable.Rows.Count > 0 Then
Try
CType(TypeControl, DropDownList).SelectedItem.Text = (DBTable.Rows(0).Item("MaterialTypeDescription").ToString)
Catch ex As NullReferenceException
trace.runAllErrorLogging(ex.ToString)
End Try
End If
A NullReferenceException doesn't have anything to do with "controls" specifically. It's just an indication that your code assumes an object exists when at runtime it doesn't exist. For example, if you do this:
TypeControl = MaterialHeader_Edit1.FindControl("cboType")
CType(TypeControl, DropDownList).SelectedItem.Text = ...
Then your code assumes that TypeControl has a value on the second line. If it doesn't, trying to use .SelectedItem will fail because TypeControl is null. So you're assuming that .FindControl() actually found something. It doesn't make that guarantee implicitly.
Instead of making this assumption, you should verify:
TypeControl = MaterialHeader_Edit1.FindControl("cboType")
If TypeControl Is Not Nothing Then
CType(TypeControl, DropDownList).SelectedItem.Text = ...
End If
That way the code only executes if there's a value that it can use. You can add an Else to handle the condition where no value is found. (Display an error? Log the error? Silently continue? It's up to you how the condition should be handled.)
There are two possible problems here:
1 - Does FindControl actually find the control you seek? Add a check in to make sure you are actually finding it:
Dim TypeControl As Control
TypeControl = MaterialHeader_Edit1.FindControl("cboType")
If TypeControl Is Nothing Then Debug.Writeline("Could not find control")
2 - The SelectedItem of the control could also be Nothing so you may need to add a check here:
Dim ddl = CType(TypeControl, DropDownList)
If ddl.SelectedItem Is Nothing Then Debug.Writeline("Could not find selectedItem")

ReportViewer is not displaying data .

I want to use Report Viewer in my project.
i have
1. CustomerDetails - Stored Procedure
2. CustomerDataset.xsd - in which i dragged n dropped the stored procedure.
3. CustomerReport.rdlc - in which i have crated a table which and data set is
CustomerDetails
4. CustomerReportViewer.aspx - in which the CustomerReoprt.rdlc is being binded.
now, i want to pass 2 values "chkeckInDate" and "checkOutDate" from 2 text box which are to be filled by use from "main.aspx" also i 'm calling my stored procedure from this file .
the report viewer is getting displayed but, the contents are not getting displayed (i have executed my stored procedure and it is running perfectly.)
How can i fix it? please help.
I didn't clearly understand where is the mistake, but I think you have the code under page_load event. Copy the code into button_click.
This is what I've used..
You must inport this:
Imports Microsoft.Reporting.WinForms
You should pass the textbox value as parameter.
Dim yr As New ReportParameter("param1", TextBox1.Text)
Try
Me.your_TableAdapter.Fill(Me.DataSet_name.table_name)
ReportViewer1.LocalReport.SetParameters(New ReportParameter() {yr})
Me.ReportViewer1.RefreshReport()
Catch ex As Exception
MsgBox("try again")
End Try
copy these two lines from page_load event into button_click.
Me.your_TableAdapter.Fill(Me.DataSet_name.table_name)
Me.ReportViewer1.RefreshReport()
Further, watch this

ASP.Net Dropdown List is not throwing an error

I am having problems with dropdown lists NOT throwing an error with the following code in ASP.Net 4.0
the dropdown list is empty to start. The page in question is a simple test page containing no code besides the lines below in Page_Load.
ddlTest.Items.Add(new ListItem("test","test"));
ddlTest.SelectedValue = "Fail";
When I load the page, the DDL displays "test" as the only item (as expected) and no error is thrown. I thought an error would be thrown with something like "item 'Fail' does not exist"
I have tested the code both, inside an if (!IsPostBack) block and outside of it. The results are the same.
Does this make sense? I don't understand why this is not throwing an error. Any explanation would be greatly appreciated.
Thanks.
It will only throw an exception if there are no items in ddlTest, otherwise it just doesn't find the value.
You can always do this first if you are trying to find out if the item exists in the list:
if (ddlTest.Items.FindByValue("Fail") != null)
ddlTest.SelectedValue = "Fail";
else
//item doesn't exist, do something meaningful here

"Missing Parameter Values" error on moving to next page of report

I am writing a web application using ASP.NET 2.0 [Visual Studio 2005 Professional Edition].
I have a Crystal Report that is connected to a stored procedure residing in SQL Server. This stored procedure accepts a parameter and therefore I have a formula in my report's hyperlink section to pass the parameter via Query String.
Everything works fine except when I click the navigation buttons to move to the next page of the report, I either get an error or Crystal Reports shows an input box to enter the parameter values.
The error shown is: "Missing Parameter Values". Only this error is shown and nothing else. If I try to export the report by selecting Export option on the Crystal toolbar, it opens a page and asks for the parameter values.
I am not following why parameter values disappear when either I move from the first page to the other or try to export the report?
Most likely you are setting the parameters in the report viewer instead of the report object. If the parameters are set in the report object they should persist on navigation. If you still have issues create an event handler for the report viewer's 'Navigate' event and reset them.
Aditionally, if you call report.Refresh() or report.VerifyDatabase() after you set parameters it clears the values so be aware of that,
MD
When we click on report navigatin button, print button page is refeshed and we facing with 'missing parameter values error '
My probem is solved by using below line of code.
If Not Page.IsPostBack Then
CrystalReportViewer1.ParameterFieldInfo = paramFields
CrystalReportViewer1.ReportSource = myReportDocument
CrystalReportViewer1.DataBind()
Else
CrystalReportViewer1.ReportSource = myReportDocument
CrystalReportViewer1.DataBind()
End If
where paramFields are runtime created ParmeterFields
Best Regards,
Vinay Shukla

On error Resume next in ASP

HI,
I want to catch SQL error in my Page.If I use "On error Resume next" ,If page having some other error it wont thrown .Can u plese give solution for handling error
You can revert the standard exception raising by using
ON ERROR GOTO 0
http://www.powerasp.com/content/new/on-error-resume-next.asp
Also, don't forget that if you put On Error Resume Next in a Sub or a Function it will only apply to that Sub/Function.

Resources