Skip to Content

Why does "SBO_Application.Desktop.Width" behave erratically?

Hi,

I use the foll. code in my application to calculate my desktop width. This figure varies according to the resolution of the user's monitor.

oFormWidth = SBO_Application.Desktop.Width

Unfortunately, this code does not seem to return the same value each time the program is run. Very strange indeed!

I use a MsgBox to find the value returned.

On my computer, it returns 1440 on many runs. Then suddenly changes to 160 on the next run.

I wonder how it got the 160 ( 1/9 th of the correct value)

On another computer, it returns 1920 on many runs. Then suddenly changes to 160 on the next run.

Here, it is 1/12 of the correct value

Once the bad value (160) is returned, further runs return the same value (160).

The only way to make the code work properly is to close SAP B1 and reopen it.

But then the problem recurs after a number of runs (at random intervals)

My application contains only 2 relevant lines of code:

oFormWidth = SBO_Application.Desktop.Width

MsgBox("Desktop Width = " & oFormWidth)

All the rest are just connection details.

Could anybody tell me what's wrong with my code?

I really can't understand why the code is returning values that vary randomly.

----------------------

'// SubMain

Option Strict Off

Option Explicit On

Module SubMain

Public Sub Main()

Dim oWnH As WnH

oWnH = New WnH

End Sub

End Module

-------------------------

'// Code for the application called WnH (i.e Width & Height)

Option Strict Off

Option Explicit On

Public Class WnH

Private WithEvents SBO_Application As SAPbouiCOM.Application

Public oCompany As SAPbobsCOM.Company

Dim oFormWidth As Double

Dim oFormHeight As Double

Public Sub New()

MyBase.New()

SetApplication()

DesktopWidth()

SetConnectionContext()

ConnectToCompany()

End Sub

Public Sub DesktopWidth()

oFormWidth = SBO_Application.Desktop.Width

MsgBox("Desktop Width = " & oFormWidth)

End Sub

Private Sub SetApplication()

Dim SboGuiApi As SAPbouiCOM.SboGuiApi

Dim sConnectionString As String

SboGuiApi = New SAPbouiCOM.SboGuiApi

Try

If Environment.GetCommandLineArgs.Length > 1 Then

sConnectionString = Environment.GetCommandLineArgs.GetValue(1)

Else

sConnectionString = Environment.GetCommandLineArgs.GetValue(0)

End If

Catch ex As Exception

End Try

SboGuiApi.Connect(sConnectionString)

SBO_Application = SboGuiApi.GetApplication()

oCompany = New SAPbobsCOM.Company

oCompany = SBO_Application.Company.GetDICompany()

End Sub

Private Function SetConnectionContext() As Integer

Dim sCookie As String

Dim sConnectionContext As String

oCompany = New SAPbobsCOM.Company

sCookie = oCompany.GetContextCookie

sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie)

If oCompany.Connected = True Then

oCompany.Disconnect()

End If

SetConnectionContext = oCompany.SetSboLoginContext(sConnectionContext)

End Function

Private Function ConnectToCompany() As Integer

ConnectToCompany = oCompany.Connect

End Function

End Class

------------------------------------------------------------------

And here are screenshots:

Capture1.JPG (73.9 kB)
Capture2.JPG (77.3 kB)
Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on May 19, 2015 at 11:49 AM

    Hi Leon,

    I didn't test, but SBO_Application.Desktop.Width is not giving the width of Windows Desktop. It is per SDK definition :


    Represents the SAP Business One desktop (main window). Use this object to change window properties

    And 160 sounds like a value possible if SBO is minimized ( task bar windows size ).

    regards,

    Maik

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Maik,

      Fantastic!

      Your 1st formula is exactly what I wanted.

      Now, I don't need to bother whether SAP is maximised or minimised.

      Your formula gives the correct screen resolution.

      Now, I can design my add-on screens so that all dimensions and positions are parametrized as a % of the resolution.

      Great! All users will see EXACTLY the same screen, even if they use different monitors!

      Best Regards,

      Leon

  • Posted on May 19, 2015 at 08:23 AM

    Hi Leon,

    From your description seems like a bug in B1. If you can reproduce it consistently I'd suggest opening a ticket with SAP Support to have it fixed.


    Best regards,

    Pedro Magueija


    View Pedro Magueija's profile on LinkedIn

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Pedro,

      Thanks for your reply.

      Before I open a ticket with SAP Support, would it be possible for you to test my program on your computer?

      I want to make sure other users are getting the same anomalies and that the error is not due to wrong coding on my part.

      As I have made 100% of my code available on this thread, I invite other people to copy / paste my code on their Visual Studio (VB.NET) and let me know whether the code generates correct results.

      Notes:

      (a) Do not loop the Desktop.Width command. It's no use. I looped it 10,000 times and it's not generating an error if the 1st result is good. If the 1st result is bad, all the 10,000 will be bad.

      We have to RUN the program several times, say 100 times, because sometimes the error happens on the 1st run, sometimes on the 50th run... quite unpredictable.

      (b) I also notice that an error is more likely to happen after you change the resolution on the desktop (Right click mouse > Screen Resolution). So try to change the resolution manually, and see if the program returns the correck desktop width.

      Best Regards.

      Leon Lai

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.