Dynamic expanding visual basic forms - forms

I have what is most likely a simple question. I have a visual basic form but when I expand it none of the fields or text expands with the window. I was wondering how to make it so the form dynamically expands when someone maximizes or expands the window on the desktop Could someone please advise thank you!

Each control has the properties VerticleAnchor and HorizontalAnchor.
These can be left right or both (top or bottom for verticle) and if it is left and top (default) they stay those distances from the top and left sides. Changing them to right and bottom keep their distances from the right and bottom. Both resizes the control to have the same spacing from both as the form resizes.
Also double chack that the CanGrow and CanShrink are true to allow for them to resize with the form.
Hope that helps!
Edit:
Here is some code from my predecessor that does it using the event:
Private Sub Form_Resize()
On Error GoTo Err_Form_Resize
If CurrentProject.AllForms("frmFMEA_PartA").IsLoaded Then
Dim DatasheetW As Double
Dim DatasheetH As Double
Dim FormW As Double
Dim FormH As Double
DatasheetW = Me.frmFMEA_PartB_Subform.width
FormW = Me.WindowWidth
DatasheetH = Me.frmFMEA_PartB_Subform.Height
FormH = Me.WindowHeight
'MsgBox FormH
'MsgBox DatasheetH
Me.frmFMEA_PartB_Subform.width = IIf(FormW - 360 > 0, FormW - 360, 1) '390
Me.frmFMEA_PartB_Subform.Height = IIf(FormH - 3405 > 0, FormH - 3405, 1) '3195
Me.text.Left = IIf(FormW - 2340 > 0, FormW - 2340, 1)
Me.text_Logo.Left = IIf(FormW - 2340 > 0, FormW - 2340, 1)
End If
Exit_Form_Resize:
Exit Sub
Err_Form_Resize:
MsgBox Err.Description
Resume Exit_Form_Resize
End Sub
as you can see its a lot of math, trial, and error so I try to do it using the form level properties but maybe this will spart some ideas.

Related

How can I disable ":w" from doing anything with the popup's buffer?

Here is a piece of code that creates the popup:
:function! PopupDemo()
let message = 'Hello World'
for i in range(10)
let message = message . ' ' . message
endfor
let s:win_buf = bufadd('popup-demo')
call bufload(s:win_buf)
call setbufline(s:win_buf, 1, message)
echo 'buf id: ' . s:win_buf
let width = 40
let height = 10
" Set the new window as the current window.
let enter = v:false
" Calculate the centering coordinates.
let win_x = &columns / 2 - width / 2
let win_y = &lines / 2 - height / 2
let s:win_id = nvim_open_win(s:win_buf, enter, {
\'relative': 'editor',
\'row': win_y,
\'col': win_x,
\'width': width,
\'height': height,
\'focusable': v:false,
\'style': 'minimal',
\'border': ['╔', '═','╗', '║', '╝', '═', '╚', '║'],
\'noautocmd': v:false,
\'bufpos': [0, 0]
\})
call nvim_win_set_option(s:win_id, 'wrap', v:true)
:endfunction
:function! PopupClose(timer)
if s:win_id != 0
call nvim_win_close(s:win_id, v:false)
endif
if s:win_buf != 0
call nvim_buf_delete(s:win_buf, {'force': v:true})
endif
:endfunction
After I create a buffer and a pop-up window through the PopupDemo() function, I do not call the PopupClose() function to close the window, but directly use the :wq command to save the file and exit neovim, the following error message will appear:
E37: No write since last change
E162: No write since last change for buffer "popup-demo"
I want file save instructions like ":w", ":wq" and ".wqall" to ignore the popup's buffer, how can I do this?
neovim version: v0.7.2
Normally buffers are related to files. Set 'buftype' option equal to nofile if not.
As it is Neovim-only code, you can replace bufadd('') with nvim_create_buf(v:false, v:true), so it sets the option while creating the buffer.

Fitting custom functions to data

I have a series of data, for example:
0.767838478
0.702426493
0.733858228
0.703275979
0.651456058
0.62427187
0.742353261
0.646359026
0.695630431
0.659101665
0.598786652
0.592840135
0.59199059
which I know fits best to an equation of the form:
y=ae^(b*x)+c
How can I fit the custom function to this data?
Similar question had been already asked on LibreOffice forum without a proper answer. I would appreciate if you could help me know how to do this. Preferably answers applying to any custom function rather than workarounds to this specific case.
There are multiple possible solutions for this. But one approach would be the following:
For determining the aand b in the trend line function y = a*e^(b*x) there are solutions using native Calc functions (LINEST, EXP, LN).
So we could the y = a*e^(b*x)+c taking as y-c= a*e^(b*x) and so if we are knowing c, the solution for y = a*e^(b*x) could be taken too. How to know c? One approach is described in Exponential Curve Fitting. There approximation of b, a and then c are made.
I have the main part of the delphi code from Exponential Curve Fitting : source listing translated to StarBasic for Calc. The part of the fine tuning of c is not translated until now. To-Do for you as professional and enthusiast programmers.
Example:
Data:
x y
0 0.767838478
1 0.702426493
2 0.733858228
3 0.703275979
4 0.651456058
5 0.62427187
6 0.742353261
7 0.646359026
8 0.695630431
9 0.659101665
10 0.598786652
11 0.592840135
12 0.59199059
Formulas:
B17: =EXP(INDEX(LINEST(LN($B$2:$B$14),$A$2:$A$14),1,2))
C17: =INDEX(LINEST(LN($B$2:$B$14),$A$2:$A$14),1,1)
y = a*e^(b*x) is also the function used for the chart's trend line calculation.
B19: =INDEX(TRENDEXPPLUSC($B$2:$B$14,$A$2:$A$14),1,1)
C19: =INDEX(TRENDEXPPLUSC($B$2:$B$14,$A$2:$A$14),1,2)
D19: =INDEX(TRENDEXPPLUSC($B$2:$B$14,$A$2:$A$14),1,3)
Code:
function trendExpPlusC(rangey as variant, rangex as variant) as variant
'get values from ranges
redim x(ubound(rangex)-1) as double
redim y(ubound(rangex)-1) as double
for i = lbound(x) to ubound(x)
x(i) = rangex(i+1,1)
y(i) = rangey(i+1,1)
next
'make helper arrays
redim dx(ubound(x)-1) as double
redim dy(ubound(x)-1) as double
redim dxyx(ubound(x)-1) as double
redim dxyy(ubound(x)-1) as double
for i = lbound(x) to ubound(x)-1
dx(i) = x(i+1) - x(i)
dy(i) = y(i+1) - y(i)
dxyx(i) = (x(i+1) + x(i))/2
dxyy(i) = dy(i) / dx(i)
next
'approximate b
s = 0
errcnt = 0
for i = lbound(dxyx) to ubound(dxyx)-1
on error goto errorhandler
s = s + log(abs(dxyy(i+1) / dxyy(i))) / (dxyx(i+1) - dxyx(i))
on error goto 0
next
b = s / (ubound(dxyx) - errcnt)
'approximate a
s = 0
errcnt = 0
for i = lbound(dx) to ubound(dx)
on error goto errorhandler
s = s + dy(i) / (exp(b * x(i+1)) - exp(b * x(i)))
on error goto 0
next
a = s / (ubound(dx) + 1 - errcnt)
'approximate c
s = 0
errcnt = 0
for i = lbound(x) to ubound(x)
on error goto errorhandler
s = s + y(i) - a * exp(b * x(i))
on error goto 0
next
c = s / (ubound(x) + 1 - errcnt)
'make y for (y - c) = a*e^(b*x)
for i = lbound(x) to ubound(x)
y(i) = log(abs(y(i) - c))
next
'get a and b from LINEST for (y - c) = a*e^(b*x)
oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
args = array(array(y), array(x))
ab = oFunctionAccess.CallFunction("LINEST", args)
if a < 0 then a = -exp(ab(0)(1)) else a = exp(ab(0)(1))
b = ab(0)(0)
trendExpPlusC = array(a, b, c)
exit function
errorhandler:
errcnt = errcnt + 1
resume next
end function
The formula y = beax is the exponential regression equation for LibreOffice chart trend lines.
LibreOffice exports all settings
All the settings of LibreOffice, all in the LibreOffice folder.
C:\Users\a←When installing the operating system, the name
entered.\AppData←File Manager ~ "Hidden project" to open, the AppData
folder will be displayed.\Roaming\LibreOffice
Back up the LibreOffice folder, when reinstalling, put the LibreOffice folder in its original place.
Note:
1. If the installation is preview edition, because the name of preview edition is LibreOfficeDev, so the LibreOfficeDev folder will be
displayed.
2. Formal edition can be installed together with preview edition, if both formal edition and preview edition are installed, LibreOffice
folder and LibreOfficeDev folder will be displayed.
3. To clear all settings, just delete the LibreOffice folder, then open the program, a new LibreOffice folder will be created.
LibreOffice exports a single toolbar I made
Common path
C:\Users\a←When installing the operating system, the name
entered.\AppData←File Manager ~ "Hidden project" to open, the AppData
folder will be
displayed.\Roaming\LibreOffice\4\user\config\soffice.cfg\modules\Please
connect the branch path of the individual software below.
Branch path
\modules\StartModule\toolbar\The "Start" toolbar I made is placed here.
\modules\swriter\toolbar\The "writer" toolbar I made is placed here.
\modules\scalc\toolbar\The "calc" toolbar I made is placed here.
\modules\simpress\toolbar\The "impress" toolbar I made is placed here.
\modules\sdraw\toolbar\The "draw" toolbar I made is placed here.
\modules\smath\toolbar\The "math" toolbar I made is placed here.
\modules\dbapp\toolbar\The "base" toolbar I made is placed here.
Backup file, when reinstalling, put the file in the original place.
Note:
Because of the toolbar that I made myself, default file name, will automatically use Numbering, so to open the file, can know the name of
the toolbar.
The front file name "custom_toolbar_" cannot be changed, change will cause error, behind's file name can be changed. For example:
custom_toolbar_c01611ed.xml→custom_toolbar_AAA.xml.
Do well of toolbar, can be copied to other places to use. For example: In the "writer" Do well of toolbar, can be copied to "calc"
places to use.
LibreOffice self-made symbol toolbar
Step 1 Start "Recording Macros function" Tools\Options\Advanced\Enable macro recording(Tick), in the
"Tools\Macros", the "Record Macro" option will appear.
Step 2 Recording Macros Tools\Macros\Record Macro→Recording action (click "Ω" to enter symbol→select symbol→Insert)→Stop
Recording→The name Macros stored in "Module1" is Main→Modify Main
name→Save.
Step 3 Add item new toolbar Tools\Customize\Toolbar→Add→Enter a name (example: symbol)→OK, the new toolbar will appear in the top
left.
Step 4 Will Macros Add item new toolbar Tools\Customize\Toolbar\Category\Macros\My
Macros\Standard\Module1\Main→Click "Main"→Add item→Modify→Rename (can
be named with symbol)→OK→OK.

Panel doesn't execute )PNTS Section

I'm coding a ISPF Panel with "Point and shoot" elements. The elements say "yes" and "no" and the default cursor have to point to "yes".
1st Case:
Declaration of the fields: + TYPE(INPUT) PAS(ON)
When I use this declaration, the panel closes by pressing [enter] and generating rc = 0. However, the )PNTS section doesn't run.
2nd CASE:
Declaration of the fields: + TYPE (PS)
The )PNTS section runs by pressing [enter]. However, I cannot set the .cursor to the field "yes".
I tryed different ways with different field names (e.g. ZPS00001). I tryed to simulate Point and Shoot with Rexx, but nothing worked really fine.
Pressing enter will cause the point and shoot fields to be processed. However the cursor must be on one of the fields for the )PNTS section to set the value associated with a field. It would sound like panel may have not been coded correctly. PAS should be used for input or output fields and PS should be used for text fields. For instance if you have the following panel:
)ATTR
$ TYPE(PS)
! TYPE(OUTPUT) PAS(ON)
)BODY
+ --------------------- +
+ ===>_ZCMD +
+
$Field1 : _FLD +
$Field2 : _ABC +
$Field3 : !IN1 +
$Field4 : !IN2 +
)INIT
&INV1 = 111
&INV2 = 222
&INV3 = 333
)REINIT
REFRESH(*)
)PROC
)PNTS
FIELD(IN1) VAR(INV1) VAL(ON)
FIELD(IN2) VAR(INV2) VAL(OFF)
FIELD(ZPS00001) VAR(INV3) VAL(1)
FIELD(ZPS00002) VAR(INV3) VAL(2)
FIELD(ZPS00003) VAR(INV3) VAL(3)
FIELD(ZPS00004) VAR(INV3) VAL(4)
)END
With the following REXX exec:
/* REXX */
RCC = 0
INV1 = 0
INV2 = 1
DO WHILE RCC = 0
ADDRESS ISPEXEC 'DISPLAY PANEL(PAS)'
RCC = RC
SAY INV1 '-' INV2 '-' INV3
END
You can test the values of inv1, inv2 and inv3 based on where you put the cursor when you hit enter. You will get 1, 2, 3 or 4 if the cursor in on field1, field2, field3 or field4. If it is on IN1 or IN2 then you get ON or OFF. It all depends on where the cursor is positioned when ENTER is hit. Based on the example you can see point and shoot is not limited to Menus. Hope the example helps.
Marv Knight

VBScript to detect Facebook IE window, press Like and close the window

I tryed to make a script to detect the IE window that is opened on Facebook and hit the Like button.
Let's say I have 10 IE opened. Only one of them is on a page on Facebook.
I want my script to detect that IE window, click this button:
IE.Document.getElementById("pagesHeaderLikeButton")
(The above button is the Like button)
and close that IE window.
I tryed to get that IE window by:
For Each wnd In CreateObject("Shell.Application").Windows
If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
Set IE = wnd
Exit For
End If
Next
But this will only set my VBscript to the first opened IE and it will not find the Facebook window.
I tryed this:
Dim objInstances, item
Set objInstances = CreateObject("Shell.Application").windows
For Each item In objInstances
If Item.Name Like "*Internet*" And Item.document.URL Like "*facebook.com*" Then
IE.Document.getElementById("pagesHeaderLikeButton").Click
End If
Next
But I get "Sub or function not defined"
Next code snippet could help:
Set shApp = CreateObject( "shell.application")
With shApp
For Each wnd In .Windows
If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
If InStr(1, wnd.document.URL, "facebook.com", vbTextCompare) > 0 Then
Wscript.Echo "THIS:"
End If
Wscript.Echo Left( wnd.document.URL, 70)
End If
Next
End With
Output example (with more facebook.com matches):
==>cscript D:\VB_scripts\SO\30717779a.vbs
http://www.msn.com/?ocid=iehp
THIS:
https://www.facebook.com/login.php?api_key=127760087237610&skip_api_lo
THIS:
https://www.facebook.com/literarnifestival1
THIS:
https://cs-cz.facebook.com/mgvsetin
http://www.bing.com/search?q=Xmaster+Official&qs=n&form=QBRE&pq=xmaste
http://www.bing.com/search?q=%22Xmaster+Official%22&qs=n&form=QBRE&pq=
==>
The following code will search for open IE windows that have "facebook.com" in its URL and save them in a collection:
Dim getIE As New Collection
For Each Item In CreateObject("Shell.Application").Windows
If Item.Name Like "*Internet*" And Item.document.URL Like "*facebook.com*" Then
getIE.Add Item
End If
Next
Then you can loop through the collection and do what you want with the IE items:
For Each itemIE In getIE
itemIE.Document.getElementById("pagesHeaderLikeButton").Click ' For example
Next itemIE
Hope this does what you wanted! ;)
For Each wnd In CreateObject("Shell.Application").Windows
If InStr(wnd.Name,"Internet") Then
if InStr(wnd.Document.URL,"facebook.com") Then
Set IE2 = wnd
Exit For
End If
End If
Next
So to press the button will be like this:
Set Butlike = IE2.Document.getElementsByTagName("button")
For Each btn In Butlike
If btn.type = "submit" Then btn.Click()
Next

Resize Picture and Keep Aspect Ratio in Autohotkey GUI

Is it possible to have an image be 100% of the window width and keep it's aspect ratio while resizing an AutoHotKey GUI?
I have a simple GUI as follows:
Gui +Resize
Gui, Add, Picture, w440 h-1 vProductImage, default.png
Gui, Show, , MyApp
The closest thing I have been able to come to is Anchor.ahk http://www.autohotkey.com/board/topic/4105-control-anchoring-v4-for-resizing-windows/
Using it, I can have the image resized when the window is resized but it doesn't keep it's aspect ratio and gets deformed
Does anyone know how I can do this?
Closest thing I could come up with:
Assuming the picture is 440x350, is 85 pixels from the top of the app window (left:0)
GuiSize:
if(A_GuiWidth < A_GuiHeight)
{
GuiControl, MoveDraw, ProductImage, % "w" . (A_GuiWidth - 20) . " h" . (350/440) * (A_GuiWidth - 20)
}
else
{
GuiControl, MoveDraw, ProductImage, % "w" . (440/350) * (A_GuiHeight - 85) . " h" . (A_GuiHeight - 85)
}
return
(the 20 is for window padding)