cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Option Buttons and Event Handler

leon_laikan
Participant
0 Kudos

Hi, everybody

Please see the attached picture which summarizes my problem.

My code for the Event Handler is as foll:

Private Sub OnBeforeB_OKPressed(ByVal Source As Object, ByVal pVal As SAPbouiCOM.SBOItemEventArg, ByRef Bubble As Boolean)

 

        If O_CrRq.Selected = True And O_ToShp.Selected = True Then  

            If C_ToShip.Value <> "" Then     

            SBO_Application.MessageBox("OK! ")

            Else

                SBO_Application.MessageBox("Error! You have not selected a ship!")

            End If

        End If


------

My code is too lengthy to post here. So, I am not sure I have given you all the relevant information.

Also, I can expect only general answers, or hints to help me investigate further.

------

Any comments, or hints are most welcome

Thanks

Leon

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Leon,


I adise you to check the Linked DataSources values instead of using the Item Value.


For Exemple,

Instead of checking the Radio Button Value, check it's linked DataSource like That :


if oForm.DataSources.UserDataSources.Item("O_CrRq ").Value == 'Y' then.


You do that also for the Combobox Value :


Not String.IsNullOrEmpty(oForm.DataSources.UserDataSources.Item("C_ToShip").Value) 


Hope it helps


Regards

Mohamed BEGAA

leon_laikan
Participant
0 Kudos

Hi Mohamed and Pedro,

Thank you both for your help.

I have found the solution to my problem by using BOTH your suggestions.

The problem was in the Combo. I assumed its value was  BLANK i.e "".

I forgot that it could also be a NULL.

Also, I checked the value of the USERDATASOURCE instead of the value of the COMBO.

I don't know why UDS.VALUE works, but COMBO.VALUE does not in my project. Maybe someone can explain?

Here is the final solution- which works!

Best Regards,

Leon

Private Sub OnBeforeB_OKPressed(ByVal Source As Object, ByVal pVal AsSAPbouiCOM.SBOItemEventArg, ByRef Bubble As Boolean)

        If O_CrRq.Selected = True And O_ToShp.Selected = True Then 

            ‘// If C_ToShip.Value <> "" Then    

If Not String.IsNullOrEmpty(FormSelx.DataSources.UserDataSources.Item(“UDS_Combo”).Value Then

SBO_Application.MessageBox("OK You have selected a ship! ")

            Else

SBO_Application.MessageBox("Error! You have not selected a ship!")

            End If

        End If

Answers (1)

Answers (1)

pedro_magueija
Active Contributor
0 Kudos

Hi Leon,

Do you have any items on the combobox? I'd change the C_ToShip.Value <> "" to

Not String.IsNullOrEmpty(C_ToShip.Value)


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

leon_laikan
Participant
0 Kudos

Hi Pedro,

Thanks for your reply.

I tried your suggestion, but unfortunately the problem persists.

What appears strange is than when I select O_CrRq directly (i.e first time), the correct Message Box pops up.

But when I select O_CrRq AFTER selecting another Option Button first (in the same group), the wrong Message Box pops up. It is as if the event handler fails to see that O_CrRq has been selected finally.

Regards,

Leon

pedro_magueija
Active Contributor
0 Kudos

Hi Leon,

If a message box displays then the first condition is evaluated to true (which means the O_CrRq is evaluated correctly). Your problem (if the description is accurate) must be in the second condition.

You can set a breakpoint in the code and then just check what are the actual values. This will give you an idea of what is going on.

ps: is right about using the datasources (rather then UI), I'd recommend fixing your issue then refactoring to use the datasources.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn