rmk
asked on
How to Calculate Character Width
In Access XP I have a continuous bound form with 2 controls:
- txtRecordID bound to RecordID
- txtRecord bound to Record
Each of these controls has FontName=CourierNew and FontSize=10 so that each character has the same width
The record is actually made up of 10 columns. So I have 10 labels in the form header. I also have a settings table that contains the names of each of these labels as well as its width in characters. In the Form_Load event I dynamically assign the the Left and Width attributes of each label so that it properly defines the start and end postion of each column. The detail section height is twice the height to txtRecord. Just above the text box I dynamically position some vertical lines to further show the field separation.
My problem is that the positioning of the form header labels and vertical lines in the detail section is never quite right across the entire width of txtRecord. I've tried the following base assumptions without total success:
dim lngUnitWidth as long
lngUnitWidth = 1440 / 12 ' the form grid is 24 x 24 and each character seems be be about 2 grid lines wide
lngUnitWidth = me.txtRecord.Width / 90 ' the text box is full at 90 characters
Any suggestions to help me with this dynamic alignement of labels and vertical bars?
- txtRecordID bound to RecordID
- txtRecord bound to Record
Each of these controls has FontName=CourierNew and FontSize=10 so that each character has the same width
The record is actually made up of 10 columns. So I have 10 labels in the form header. I also have a settings table that contains the names of each of these labels as well as its width in characters. In the Form_Load event I dynamically assign the the Left and Width attributes of each label so that it properly defines the start and end postion of each column. The detail section height is twice the height to txtRecord. Just above the text box I dynamically position some vertical lines to further show the field separation.
My problem is that the positioning of the form header labels and vertical lines in the detail section is never quite right across the entire width of txtRecord. I've tried the following base assumptions without total success:
dim lngUnitWidth as long
lngUnitWidth = 1440 / 12 ' the form grid is 24 x 24 and each character seems be be about 2 grid lines wide
lngUnitWidth = me.txtRecord.Width / 90 ' the text box is full at 90 characters
Any suggestions to help me with this dynamic alignement of labels and vertical bars?
ASKER
The vertical lines in the detail section line up correctly with the labels in the header section. However neither of these always line up nicely between characters in the txtRecord text box.
Here is an example of the txtRecord contents for 1 record:
E2003120200119000000000002 2140600024 0001005302 0107972004 0001315600 0001315609
This is my settings table that defines how wide each of the labels needs to be:
BankFieldID Name Length
1 Code 1
2 BatchDate 8
3 BatchNbr 5
4 CheckNbr 15
5 TaxMap 15
6 AssocNbr 2
7 BillNbr 6
8 TaxYear 4
9 InvoiceAmt 9
10 CheckAmt 9
11 CheckChar 1
Here is an example of the txtRecord contents for 1 record:
E2003120200119000000000002
This is my settings table that defines how wide each of the labels needs to be:
BankFieldID Name Length
1 Code 1
2 BatchDate 8
3 BatchNbr 5
4 CheckNbr 15
5 TaxMap 15
6 AssocNbr 2
7 BillNbr 6
8 TaxYear 4
9 InvoiceAmt 9
10 CheckAmt 9
11 CheckChar 1
What I would do is use Mid statements to parse out each piece of the record into separate text fields. It sure would be a lot easier and a lot easier to read. You could even format each text field appropriately. Each Mid statement can go in the text field control source property. For example:
in the txtBatchDate control source put: =Mid([txtRecord], 2, 8)
I'm assuming in the above example "E200312020011900000000000 2214060002 4000100530 2010797200 4000131560 0000131560 9" is a txtRecord
in the txtBatchDate control source put: =Mid([txtRecord], 2, 8)
I'm assuming in the above example "E200312020011900000000000
ASKER
I don't want to parse out the fields because I have to allow the users to add or delete characters in the txtRecord text box and have everything shift accordingly. This is a lock box application and unfortunately the bank does not always send properly formatted data. I also have some buttons that let the user do bulk character inserts or deletes across a range of records. It all works quite nicely. By fiddling around, I've now got the labels lining up well enough that it's not worth any more effort.
I'm glad you got it worked out.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If so try:
[vertical line].left = [header label].left
[text box in detail section].left = [header label].left
[text box in detail section].width = [header label].width