Problem with GLOBAL var

Discuss the database features
Post Reply
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Problem with GLOBAL var

Post by arfgh »

Hey there.

i defined this global variable to be used in my Base forms:

Code: Select all

Global FrameSize as new com.sun.star.awt.Size
For some reason that i dont know, the values in 'FrameSize.width' and 'FrameSize.height' are erased and the value change to 0 each time i navigate to the next record. And i defined it as GLOBAL, so then i dont understand which is the problem. I have tried also to define it in other module, with the same bad result.

please help.

thx in advance
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
UnklDonald418
Volunteer
Posts: 1546
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Problem with GLOBAL var

Post by UnklDonald418 »

I believe each time the macro runs anything already stored in FrameSize gets wiped out the next time the macro runs because you are assigning it “ as new com.sun.star.awt.Size “
Try simply declaring it with

Code: Select all

Global FrameSize
and then assigning it a value inside the sub/function.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Problem with GLOBAL var

Post by arfgh »

can you please be more deep ?
because i tried a lot of diferent declarations with the same result.
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
UnklDonald418
Volunteer
Posts: 1546
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Problem with GLOBAL var

Post by UnklDonald418 »

Here is an example based on Listing 253 from Andrew Pitonyak's book "OpenOffice.org Macros Explained". with added lines
"Global FrameSize" and
"if i = 0 then
FrameSize = vFrames(i).getComponentWindow().getSize()
endif"

Code: Select all

REM  *****  BASIC  *****

Global FrameSize

Sub QueryFrames
Dim vFrames As Variant 'All of the frames
Dim vFrame As Variant 'A single frame
Dim i As Integer 'Index to enumerate the frames
Dim s As String 'Contains the string to print

REM Call the queryFrames() method on the XFrames interface.
REM This takes one argument, a FrameSearchFlag.
REM This searches the children of the desktop.
vFrames = StarDesktop.getFrames().queryFrames(com.sun.star.frame.FrameSearchFlag.CHILDREN)

For i = LBound(vFrames) To UBound(vFrames) ' The return value is an array.
s = s & vFrames(i).Title & CHR$(10) ' Append the title and a new line.
  if i = 0 then
    FrameSize = vFrames(i).getComponentWindow().getSize()
  endif
Next
 
MsgBox s, 0, "Frame Titles" ' Display the titles.
End Sub
Using the IDE set a Watch on FrameSize and run the macro once. It will store the size of the first frame it finds in Global FrameSize.
Again in the IDE single step into the beginning of the macro and in the Watch window you can expand FrameSize where you can see that the stored values persist from the previous run of the macro.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Problem with GLOBAL var

Post by arfgh »

but UnklDonald418, i always use the 'Option Explicit'. And in that example.. Global FrameSize, isnt defined its type.
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
UnklDonald418
Volunteer
Posts: 1546
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Problem with GLOBAL var

Post by UnklDonald418 »

Define it as Variant, which is the default type assigned by Star Basic.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Post Reply