on 05-19-2015 8:46 AM
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:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Maik,
Thanks a lot for your reply.
You have hit upon the correct answer!
I thought SBO_Application.Desktop.Width gave the screen resolution. I was only partially right. If SAP B1 is maximised, it will give the same answer as the screen resolution, but if it is minimised, it returns 160!
What happened is that while I was testing my program, I inadvertently minimised the SAP screen, and it returns 160! This was driving me crazy!
Here are my tests:
MAXIMISED ---> 1600
RESTORE DOWN ---> 960
MINIMISED ---> 160
So, mystery solved completely! Great!
But before closing this thread, may I ask you 2 other related questions:
(a) Is there an SDK formula that gives the actual resolution width?
(Desktop --> Mouse right-click --->Screen Resolution)
Alternatively
(b) Can I add a code in my application, so that when I run it, it ensures that the SAP B1 screen is MAXIMISED?
Best Regards,
Leon Lai
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
95 | |
11 | |
11 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.