Home > Software design >  How to have a text box contain a character position under each character
How to have a text box contain a character position under each character

Time:04-19

I have a text box on an MS-Access 2007 Form (its old, but its what I have) called text_record. I want to display the characters in the text box with a positional line directly underneath the text. e.g.

ABCDEF 123456

I used the following code to set the field:

 dim x as string
 x = Forms![mapped field names].Form![text_record] & vbcrlf
 For i = 1 To Len(x) - 1
     x = x & CStr(i Mod 10)
 Next
 Forms![mapped field names].Form![text_record] = x

The code works and shows the integer positions underneath, but the characters are not aligned directly above the numbers. I need the characters directly above the positional number so a user can see what is in a particular column.

I tried several different font types, all said they were monospaced, and they all fail to align directly above the number. Depending on the text in the record, the position was off as much as 5 columns.

I must be missing something simple.

Thanks in advance for any and all responses

CodePudding user response:

You might be better off splitting the text and putting it into a multi-column list box.

enter image description here

CodePudding user response:

Use a fixed font. Courier New is a fixed size.

So, on the form, I drop in a text box, and right below another text box (I set the border to transparent, and I set enabled = false (so user can't edit, or tab into).

so we have this:

enter image description here

And the font for both text boxes is this:

enter image description here

And my code (it puts numbers below as you type).

Private Sub Text0_Change()   
  Dim sResult       As String
  Dim i             As Integer
  
  For i = 1 To Len(Text0.Text)
  
     sResult = sResult & i Mod 10
     
  Next i      
  Me.Text2 = sResult      
End Sub

So, we see this (and I typed in "i" and "l", since they are small compared to numbers, and we get this:

enter image description here

so, not sure what font you used, but Courier new is a fixed font, and should work as per above.

  • Related