Problem with GLOBAL var

Discuss the database features

Problem with GLOBAL var

Postby arfgh » Tue Oct 10, 2017 7:33 pm

Hey there.

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

Code: Select all   Expand viewCollapse view
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 - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 350
Joined: Tue Mar 05, 2013 6:44 pm

Re: Problem with GLOBAL var

Postby UnklDonald418 » Wed Oct 11, 2017 11:31 pm

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   Expand viewCollapse view
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 subject line
Apache OpenOffice 4.1.4 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 575
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Problem with GLOBAL var

Postby arfgh » Thu Oct 12, 2017 3:08 am

can you please be more deep ?
because i tried a lot of diferent declarations with the same result.
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 350
Joined: Tue Mar 05, 2013 6:44 pm

Re: Problem with GLOBAL var

Postby UnklDonald418 » Fri Oct 13, 2017 9:51 pm

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   Expand viewCollapse view
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 subject line
Apache OpenOffice 4.1.4 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 575
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Problem with GLOBAL var

Postby arfgh » Sat Oct 14, 2017 7:02 pm

but UnklDonald418, i always use the 'Option Explicit'. And in that example.. Global FrameSize, isnt defined its type.
OpenOffice last version - Windows 8.1 Enterprise x64 - Windows XP x64 SP2
arfgh
 
Posts: 350
Joined: Tue Mar 05, 2013 6:44 pm

Re: Problem with GLOBAL var

Postby UnklDonald418 » Sat Oct 14, 2017 11:54 pm

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 subject line
Apache OpenOffice 4.1.4 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 575
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA


Return to Base

Who is online

Users browsing this forum: No registered users and 9 guests