How to resize side by side controls in MS ACCESS 2007 - alignment

I have a form in which there are various fields, for ex. Two textboxes are side by side.
These 2 textbox have anchor property left,top and other right,top.
Now when I resize the form the controls are aligned to left and the other textbox to right.
But when as screen is maximized it leaves a blank space in between these two textboxes.
So then I made the anchor property of both textbox to both,both the controls overlapped.
PS: working on MS ACCESS 2007.
anchoring property above is Horizontal, Vertical
EDIT : In Normal window
_______________________Min Max Close_
| First_Name TEXTBOX Last_Name TEXTBOX |
|_______________________________|
When Maximized to whole screen it gives me
_____________________________________Min Max Close_
| First_Name TEXTBOX ............................. Last_Name TEXTBOX |
|______________________________________________|
And I need this way as below
_____________________________________Min Max Close_
| F i r s t_N a m e T E X T B O X ........ L a s t_N a m e T E X T B O X |
|______________________________________________|
I am trying to explain by doing all this as I am not allowed to upload a image, Sorry for that....

Paste the following code into your form, change the field names, and see what happens. The two fields will 'grow' as you increase the form width, yet maintain their Anchor. Note: I updated on 3/3 to handle the field labels.
Option Compare Database
Option Explicit
Dim fviInsideWidth As Integer
Dim fviSaveInsideWidth As Integer
Dim fviFormWidth As Integer
Dim fviFldWidth As Integer
Dim fviFieldGap As Integer
Dim fviRemainder As Integer
Dim fviLblWidth As Integer
Dim fviRLblToTxt As Integer
Dim fvstrLLabel As String
Dim fvstrRLabel As String
Private Sub Form_Open(Cancel As Integer)
fviSaveInsideWidth = Me.InsideWidth
fviInsideWidth = Me.InsideWidth
fviFormWidth = Me.Width
fviFldWidth = Me.fldLeft.Width + Me.fldRight.Width
fviRemainder = fviInsideWidth - fviFldWidth
fviFieldGap = Me.fldRight.Left - (Me.fldLeft.Left + Me.fldLeft.Width)
fvstrLLabel = Me.fldLeft.Controls.Item(0).Name
fvstrRLabel = Me.fldRight.Controls.Item(0).Name
fviLblWidth = Me.Controls(fvstrRLabel).Width
fviRLblToTxt = Me.fldRight.Left - Me.Controls(fvstrRLabel).Left
'Debug.Print "Open - InsideWidth = " & fviInsideWidth & " Fields: " & fviFldWidth & " Remainder: " & fviRemainder
'Debug.Print "Open - Form Width = " & Me.Width & vbTab & "Diff = " & fviInsideWidth - fviFormWidth
End Sub
Private Sub Form_Close()
Me.fldLeft.Width = fviFldWidth
Me.fldRight.Width = fviFldWidth
Me.InsideWidth = fviSaveInsideWidth
End Sub
Private Sub Form_Resize()
Dim ifldWidth As Integer
Dim ifrmWidth As Integer
fviInsideWidth = Me.InsideWidth
ifrmWidth = fviInsideWidth - 1110
Me.Width = ifrmWidth
ifldWidth = Int((fviInsideWidth - fviRemainder) / 2)
Me.fldLeft.Width = ifldWidth
Me.fldRight.Left = Me.fldLeft.Left + Me.fldLeft.Width + fviFieldGap
Me.Controls(fvstrRLabel).Left = Me.fldRight.Left - fviRLblToTxt
Me.fldRight.Width = ifldWidth
'Debug.Print "Resize - InsideWidth = " & fviInsideWidth & vbTab & "Form Width = " & Me.Width & " Flds: " & ifldWidth & " Right=" & Me.fldLeft.Left + Me.fldLeft.Width + fviFieldGap
'Debug.Print "Resize Form: " & Me.Width & " Flds: " & ifldWidth
Me.Repaint
End Sub

Related

How to populate listbox1 (without userform) with different colums from different sheets

My listbox is populated with 1 column of a specific sheet.
How can I get a second and third column in my listbox?
I mean... Column B from sheet1, column C from sheet2 and column B from sheet3, each with a second column from the sheets.
In this case I have a textbox where you can type your search.
This already works for me for just 1 specific column of 1 sheet:
Private Sub textbox1_change() 'zoekt via zoekterm boxpositie de mogelijke boxposities op
Dim i As Long
Dim x As Integer
Dim Sheet1 As Worksheet
TextBox1 = Format(StrConv(TextBox1, vbUpperCase))
Set Sheet1 = Worksheets("Cytolab")
a = TextBox1.TextLength
ListBox1.Clear
ListBox1.Height = 101
ListBox1.Top = 290
ListBox1.Width = 512
For i = 5 To Sheet1.Range("B238").End(xlUp).row
For x = 1 To Len(Sheet1.Cells(i, 2))
If UCase(Mid(Sheet1.Cells(i, 2), x, a)) = TextBox1 And TextBox1 <> "" Then
ListBox1.AddItem CStr(Sheet1.Cells(i, 2)) 'CStr() toegevoegd
ListBox1.List(ListBox1.ListCount - 1, 1) = "" & Sheet1.Cells(i, 3) & " · " & Sheet1.Cells(i, 7) & " · " & Sheet1.Cells(i, 5) & " · " & Sheet1.Cells(i, 4)
ListBox1.List(ListBox1.ListCount - 1, 2) = "" & Sheet1.Cells(i, 9)
End If
Next x
Next i
End Sub
Thank you.

How to transpose a 2D list with repeating objects

I have been trying to write some VBA in Excel to transpose a 2D list, based on searching for the first character "{".
Before:
After:
My code:
With Sheets("Results").Range(Cell1:="A1", Cell2:="A39")
Set a = .Find("{", After:=Range("A" & lRow))
Set b = a
c = a.Address
Do While Not .FindNext(b) Is Nothing And a.Address <> .FindNext(b).Address
c = c & "," & .FindNext(b).Address
rangeToMoveCell1 = a.Address
rangeToMoveCell2 = .FindNext(b).Address
MsgBox ("rangeToMoveCell1: " & rangeToMoveCell1 & vbNewLine & "rangeToMoveCell2: " & rangeToMoveCell2)
Sheets("Results").Range(Cell1:=rangeToMoveCell1, Cell2:=rangeToMoveCell2).Copy
Sheets("Results").Range(Cell1:=rangeToMoveCell1, Cell2:=rangeToMoveCell2).Offset(-3, 1).PasteSpecial Transpose:=True
Sheets("Results").Range(Cell1:=rangeToMoveCell1, Cell2:=rangeToMoveCell2).Clear
Set b = .FindNext(b)
Loop
End With
I've come up with this and it works, except it does not process the last find:
With Sheets("Results").Range(Cell1:="A1", Cell2:="A" & lRow)
Set a = .Find("{", After:=Range("B" & lRow))
Set b = a
c = a.Offset(3).Address
Do While Not .FindNext(b) Is Nothing And a.Address <> .FindNext(b).Address
Set nextFind = .FindNext(b)
Set d = nextFind
'MsgBox ("d: " & d)
e = nextFind.Offset(-1, 1).Address
Sheets("Results").Range(Cell1:=c, Cell2:=e).Copy
Sheets("Results").Range(Cell1:=c, Cell2:=e).Offset(-3, 2).PasteSpecial Transpose:=True
Sheets("Results").Range(Cell1:=c, Cell2:=e).EntireRow.Delete
Sheets("Results").Range(c).EntireRow.Insert
Sheets("Results").Range(c).EntireRow.Insert
c = nextFind.Offset(3).Address
Set b = .FindNext(b)
Loop
End With

MapKit JS how to assign mapkit.Coordinates() from variable as digit

I am using MapKit JS in Filemaker and can get the coordinates from an input in Filemaker Web View like this.
"const punkt = '" & Substitute ( MYMAP::longlat ; ¶ ; ", " ) & "';" & ¶ &
The input is e.g.: 59.436549, 10.629371 but I can not get this into mapkit definition. I get the latitude ang longtitude value and make sure it is a digit. But then I need the comma (,).
var punkt // this is 59.658985, 10.790869
var punktxy = punkt.split(",");
var x = parseFloat(punktxy[0]);
var x = parseFloat(punktxy[1);
When I hardcode it works:
new mapkit.Coordinate(59.658985, 10.790869)
But I can not get this right. Probably because it is type text when I concatenate it like this:
new mapkit.Coordinate(x + ',' + y)
This does not work either:
new mapkit.Coordinate(x,y)
It is probably a string? How do I get the value correct? This is probably a javascript basic question but I am lost here.
Here is my webviewer code that includes the javascript from the text fields. Notice I am putting the x and y values into the javascript. That is why I need 3 js files since I can't seem to get this right: mapkit.Coordinate(59.658985, 10.790869)
webviewer:
// Load your specific implementation of MapKit JS ""; "const
punkt = '" & Substitute ( ARTSFUNN::Lokalitet ; ¶ ; ", " ) & "';" & ¶
& GetLayoutObjectAttribute ( "map1.js" ; "content" ) & ARTSFUNN::Lat
& " , " & ARTSFUNN::Long & GetLayoutObjectAttribute ( "map2.js" ;
"content" ) & ARTSFUNN::Lat & " , " & ARTSFUNN::Long &
GetLayoutObjectAttribute ( "map3.js" ; "content" ); "";
map1.js:
mapkit.init({
authorizationCallback: done => {
done(
"<<$$JWT.TOKEN>>"
);
}
});
var punktxy = punkt.split(",");
var x = parseFloat(punktxy[0]);
var x = parseFloat(punktxy[1);
var xy = (x + ','+ y); // doesn't work
var MarkerAnnotation = mapkit.MarkerAnnotation,
clickAnnotation;
var borch = new mapkit.CoordinateRegion(
new mapkit.Coordinate(
map2.js:
),
new mapkit.CoordinateSpan(0.005, 0.005)
);
var map = new mapkit.Map('map');
map.region = borch;
map.mapType = "hybrid";
map.setCenterAnimated(new mapkit.Coordinate(
map3.js:
), true);
console.log(map);
update## - just testing and now this seems to work!
Define the Lat and Long in WebViewer:
"var x = '" & Substitute ( ARTSFUNN::Lat ; ¶ ; ", " ) & "';" & ¶ &
"var y = '" & Substitute ( ARTSFUNN::Long ; ¶ ; ", " ) & "';" & ¶ &
Use the values in the include map.js:
var x = parseFloat(x);
var y = parseFloat(y);
// does not work if I don't convert to digit before use!
var bor = new mapkit.CoordinateRegion(
new mapkit.Coordinate(x,y),
new mapkit.CoordinateSpan(0.005, 0.005)
);
var map = new mapkit.Map('map');
map.region = bor;
map.mapType = "hybrid";
map.setCenterAnimated(new mapkit.Coordinate(x,y), true);
This is not really an answer (unless your question is purely about the "as digit" part), but I can't post this much code in a comment.
At the beginning of your question, you used a field named MYMAP::longlat which apparently held both coordinates separated by a carriage return. And you used Substitute() to replace the return with a comma.
Now you are using two separate fields, ARTSFUNN::Lat and ARTSFUNN::Lon - yet you're still applying the same Substitute operation to both. This does not seem necessary.
More importantly, you're doing:
"var x = '" & Substitute ( ARTSFUNN::Lat ; ¶ ; ", " ) & "';" & ¶ &
"var y = '" & Substitute ( ARTSFUNN::Long ; ¶ ; ", " ) & "';" & ¶ &
which would produce a result like:
var x = '59.436549';
var y = '10.629371';
where both variables are clearly strings which you then have to convert to numbers.
I believe you should be doing:
"var x = " & ARTSFUNN::Lat & ";¶var y = " & ARTSFUNN::Long & ";¶"
to produce:
var x = 59.436549;
var y = 10.629371;
which can then be used directly by:
new mapkit.Coordinate(x,y)
The same result can be obtained using your original field in:
"var x = " & GetValue ( MYMAP::longlat ; 2 ) & ";¶var y = " & GetValue ( MYMAP::longlat ; 1 ) & ";¶"
(assuming longitude is the first value listed in the field).

Masking textbox to accept only 1 digit after decimal

I am using VB6 and I want to allow user to enter only one digit after decimal,
please help.
Put the code below in change event of textbox. I think "." point is used for decimal seperator. if "," coma is used, then change the point in the code with coma.
Private Sub TextBox1_Change()
Dim strA As String
Dim intP As Integer
strA = TextBox1.Text
intP = InStr(1, strA, ".", vbTextCompare)
If intP > 0 Then TextBox1.Text = Left(strA, intP + 1)
End Sub

How to use a loop through multiple similar textboxes?

So I know this is pretty sloppy, but I have a lot going on for a simple triangulation program (2d) and I'm very new.
The user inputs value in textboxes- "aft1.text,ain1.text,aft2.text,ain2.text,bft1.text,bin1.text,bft2.text,bin1.text." This goes on for as many points that need triangulated. I want to be able to run a loop through these similar textboxes, and run a function on them.
So for each textbox that starts with abft + i and ain + i run the inches function to create a1.
Do the same to create b1.
Then another loop to plot a + i and b + i on the chart per the xcoord/ycoord functions created.
Dim a1 As Double = inches(aft1.Text, ain1.Text)
Dim b1 As Double = inches(bft1.Text, bin1.Text)
If a1 <> 0 And b1 <> 0 Then
Dim targetpoint As Int32
targetpoint = Chart1.Series("Drawing").Points.AddXY((xcoord(a1, b1)), ((ycoord(a1, b1))))
Chart1.Series("Drawing").Points.Item(targetpoint).Label = "1"
End If
Dim a2 As Double = inches(aft2.Text, ain2.Text)
Dim b2 As Double = inches(bft2.Text, bin2.Text)
If a2 <> 0 And b2 <> 0 Then
Dim targetpoint As Int32
targetpoint = Chart1.Series("Drawing").Points.AddXY((xcoord(a2, b2)), ((ycoord(a2, b2))))
Chart1.Series("Drawing").Points.Item(targetpoint).Label = "2"
End If
Dim a3 As Double = inches(aft3.Text, ain3.Text)
Dim b3 As Double = inches(bft3.Text, bin3.Text)
If a3 <> 0 And b3 <> 0 Then
Dim targetpoint As Int32
targetpoint = Chart1.Series("Drawing").Points.AddXY((xcoord(a3, b3)), ((ycoord(a3, b3))))
Chart1.Series("Drawing").Points.Item(targetpoint).Label = "3"
End If
If I understand you correctly, this code can be easily generalized by creating a Sub and calling it with your inches calculation and Label text,:oord are reachable (in scope) Functions:
Triangulate(inches(aft1.Text, ain1.Text), inches(bft1.Text, bin1.Text), 1)
Triangulate(inches(aft2.Text, ain2.Text), inches(bft2.Text, bin2.Text), 2)
Triangulate(inches(aft3.Text, ain3.Text), inches(bft3.Text, bin3.Text), 3)
EDIT-2
Although I have tested the following up to a point, since I do not have your chart properties nor the inches, xcoord and ycoord functions I could not test it completely, so try it out and let me know how it goes.
Sub TriangulateAll()
Try
Dim aft As New SortedList(Of String, TextBox)
Dim ain As New SortedList(Of String, TextBox)
Dim bft As New SortedList(Of String, TextBox)
Dim bin As New SortedList(Of String, TextBox)
For Each ctl As Control In Controls
If TypeOf (ctl) Is TextBox Then
Select Case ctl.Name.Substring(0, 3)
Case "aft"
aft.Add(ctl.Name, ctl)
Case "ain"
ain.Add(ctl.Name, ctl)
Case "bft"
bft.Add(ctl.Name, ctl)
Case "bin"
bin.Add(ctl.Name, ctl)
End Select
End If
Next
Dim a As New List(Of Double)
Dim b As New List(Of Double)
For Each kvp_aft As KeyValuePair(Of String, TextBox) In aft
For Each kvp_ain As KeyValuePair(Of String, TextBox) In ain
a.Add(inches(kvp_aft.Value.Text, kvp_ain.Value.Text))
Next
Next
For Each kvp_bft As KeyValuePair(Of String, TextBox) In bft
For Each kvp_bin As KeyValuePair(Of String, TextBox) In bin
b.Add(inches(kvp_bft.Value.Text, kvp_bin.Value.Text))
Next
Next
For i As Int16 = 0 To aft.Count - 1
Triangulate(a(i), b(i), i.ToString())
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
EDIT
Replace the 3 calls to Triangulate with the following code to completely generalize the Triangulation routine. Note that this routine expects there to be an equal number of each of the TextBox controls: aft, ain, bft, bin. I haven't tested this but it should work.
Dim aft As List(Of TextBox) = Nothing
Dim ain As List(Of TextBox) = Nothing
Dim bft As List(Of TextBox) = Nothing
Dim bin As List(Of TextBox) = Nothing
For Each ctl As Control In Controls
If TypeOf (ctl) Is TextBox Then
Select Case ctl.Name.Substring(0, 2)
Case "aft"
aft.Add(ctl)
Case "ain"
ain.Add(ctl)
Case "bft"
bft.Add(ctl)
Case "bin"
bin.Add(ctl)
End Select
End If
Next
aft.Sort()
ain.Sort()
bft.Sort()
bin.Sort()
For i As Int16 = 0 To aft.Count - 1
Dim a As Double = inches(aft.Item(i).Text, ain.Item(i).Text)
Dim b As Double = inches(bft.Item(i).Text, bin.Item(i).Text)
Triangulate(a, b, i.ToString())
Next
Sub Triangulate(a As Double, b As Double, LabelValue As String)
If a <> 0 And b <> 0 Then
Dim targetpoint As Int32
targetpoint = Chart1.Series("Drawing").Points.AddXY((xcoord(a, b)), ((ycoord(a, b))))
Chart1.Series("Drawing").Points.Item(targetpoint).Label = LabelValue
End If
End Sub

Resources