Solved

Tab representation in Richtextbox

Posted on 2000-05-17
10
311 Views
Last Modified: 2008-02-26
Help! I have created my own editor using a Richtextbox control and have hit a snag that may put a serious dent in the whole project. The thing is, the editor is to be used for writing Cobol- and as you may know, column spacing is critical. When text is inserted into the Richtextbox by either pasting or by the loadfile method, tab characters occupy the same width as 7 spaces (with courier font) as opposed to 8 spaces with your conventional textbox. I could punt and revert back to a standard textbox, but I would then lose all of the cool "colored reserved word" tricks I have come up with. Changing fonts helps slightly, but things just don't line up. Once again, the idea is that multiple lines (some of which contain tabs, and some of which contain spaces) will visually "line up" in the Richtextbox- then after the contents are saved and reopened with a conventional editor such as notepad, things are skewed all over the place. I am suprised no one has ever talked about this issue.I have found one fix that works- it is... Richtextbox1.seltabs(0) = 8. Using this line prior to loading a file works good for me and others on NT, but the people who I have forewarded the .exe to (who are using windows 2000) have experienced this error: invalid property array index. As it sits, my new app. will not be win2k compliant. I also checked the richtextbox ocx's and they were the same version. This is my first post to this bbs, so I look foreward to any and all input.
Respectfully,
Mike North

Update1:
   In win2k I can add this line:
   text1(0).SelTabCount = 1
   'before this line
   text1(0).SelTabs(0) = 8

   and the error goes away, and the first tab gets converted
   to 8 spaces... BUT- subsequent tabs are STILL 7 spaces.
   Same for fixedsys font. Using text1(0).SelTabs(1) = 8
   before loading a file causes the same error. It looks as
   though I will have to loop through and deal with the tabs
   individually if I can't find an answer. Its really got me
   stumped. One other note- I have used the EM_SETTABSTOPS
   api with good results on a regular text box, but the
   Richtextbox doesn't want to respond to that call.  I am
   determined to figure this out!
                                   Thanks for the ideas, Mike


0
Comment
Question by:jaynorth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2818460
One solution would be to set Richtextbox1.seltext = Space$(number_of_spaces) in the KeyDown event when the KeyCode is vbKeyTab. Just remember to set the KeyCode = 0 too.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2818487
perhaps you can run through the file searching for the tab key and each instance of it, adding a space at that position
0
 
LVL 18

Expert Comment

by:mdougan
ID: 2818542
A few things, you might try setting :

Richtextbox1.seltabs(1) = 8

and see if this will run on the windows 2000 boxes.  If it runs on both, great, if it runs on win 2K but not NT, then you need two versions of your program.

Other thoughts, you might try using the Fixed Sys font, as this is supposed to guarantee that all letters take up the same width, and should line up properly if you format them with the same number of spaces etc.

The other thing you might try is to call the Windows API SendMessage with the LB_SETTABSTOPS flag.  I've done this to set tabstops in listboxes, and I think it works for text boxes too, but I'm not sure if it will work for you.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:jaynorth
ID: 2818660
Edited text of question.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2818684
the example from msdn shows you having to loop through the tabs:

"This example sets the number of tabs in a RichTextBox control to a total of five and then sets the positions of the tabs to multiples of five. To try this example, put a RichTextBox control and a CommandButton control on a form. Paste this code into the Click event of the CommandButton control. Then run the example."

Private Sub Command1_Click()
   With RichTextBox1
      .SelTabCount = 5
      For X = 0 To .SelTabCount - 1
         .SelTabs(X) = 5 * X
      Next X
   End With
End Sub


0
 

Author Comment

by:jaynorth
ID: 2818691
Edited text of question.
0
 
LVL 1

Expert Comment

by:lochiano
ID: 2819210
This is the same idea as the others have offered but it is a form that I popup to allow the users set the tabs



VERSION 5.00
Begin VB.Form frmTabSet
   Caption         =   "Set Tab Stops"
   ClientHeight    =   3450
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5835
   LinkTopic       =   "Form1"
   ScaleHeight     =   3450
   ScaleWidth      =   5835
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmd
      Caption         =   "Cancel"
      Height          =   255
      Index           =   1
      Left            =   1680
      TabIndex        =   6
      Top             =   3120
      Width           =   1215
   End
   Begin VB.CommandButton cmd
      Caption         =   "Ok"
      Height          =   255
      Index           =   0
      Left            =   360
      TabIndex        =   5
      Top             =   3120
      Width           =   1215
   End
   Begin VB.CheckBox Check1
      Caption         =   "Set All Tabs the Same Width:"
      Height          =   255
      Left            =   240
      TabIndex        =   4
      Top             =   600
      Width           =   3015
   End
   Begin VB.Frame Frame1
      Caption         =   "Absolute Tab Stops"
      Height          =   1935
      Left            =   240
      TabIndex        =   3
      Top             =   1080
      Width           =   5415
      Begin VB.TextBox txtTabStop
         Height          =   285
         Index           =   11
         Left            =   3960
         TabIndex        =   29
         Top             =   1560
         Width           =   855
      End
      Begin VB.TextBox txtTabStop
         Height          =   285
         Index           =   10
         Left            =   3960
         TabIndex        =   27
         Top             =   1200
         Width           =   855
      End
      Begin VB.TextBox txtTabStop
         Height          =   285
         Index           =   9
         Left            =   3960
         TabIndex        =   25
         Top             =   840
         Width           =   855
      End
      Begin VB.TextBox txtTabStop
         Height          =   285
         Index           =   8
         Left            =   3960
         TabIndex        =   23
         Top             =   480
         Width           =   855
      End
      Begin VB.TextBox txtTabStop
         Height          =   285
         Index           =   7
         Left            =   2160
         TabIndex        =   22
         Top             =   1560
         Width           =   855
      End
      Begin VB.TextBox txtTabStop
         Height          =   285
         Index           =   6
         Left            =   2160
         TabIndex        =   20
         Top             =   1200
         Width           =   855
      End
      Begin VB.TextBox txtTabStop
         Height          =   285
         Index           =   5
         Left            =   2160
         TabIndex        =   17
         Top             =   840
         Width           =   855
      End
      Begin VB.TextBox txtTabStop
         Height          =   285
         Index           =   4
         Left            =   2160
         TabIndex        =   16
         Top             =   480
         Width           =   855
      End
      Begin VB.TextBox txtTabStop
         Height          =   285
         Index           =   3
         Left            =   720
         TabIndex        =   10
         Top             =   1560
         Width           =   855
      End
      Begin VB.TextBox txtTabStop
         Height          =   285
         Index           =   2
         Left            =   720
         TabIndex        =   9
         Top             =   1200
         Width           =   855
      End
      Begin VB.TextBox txtTabStop
         Height          =   285
         Index           =   1
         Left            =   720
         TabIndex        =   8
         Top             =   840
         Width           =   855
      End
      Begin VB.TextBox txtTabStop
         Height          =   285
         Index           =   0
         Left            =   720
         TabIndex        =   7
         Top             =   480
         Width           =   855
      End
      Begin VB.Label lblField
         Caption         =   "#12"
         Height          =   255
         Index           =   12
         Left            =   3360
         TabIndex        =   30
         Top             =   1560
         Width           =   375
      End
      Begin VB.Label lblField
         Caption         =   "#11"
         Height          =   255
         Index           =   11
         Left            =   3360
         TabIndex        =   28
         Top             =   1200
         Width           =   375
      End
      Begin VB.Label lblField
         Caption         =   "#10"
         Height          =   255
         Index           =   10
         Left            =   3360
         TabIndex        =   26
         Top             =   840
         Width           =   375
      End
      Begin VB.Label lblField
         Caption         =   "#9"
         Height          =   255
         Index           =   9
         Left            =   3480
         TabIndex        =   24
         Top             =   480
         Width           =   255
      End
      Begin VB.Label lblField
         Caption         =   "#8"
         Height          =   255
         Index           =   8
         Left            =   1800
         TabIndex        =   21
         Top             =   1560
         Width           =   255
      End
      Begin VB.Label lblField
         Caption         =   "#7"
         Height          =   255
         Index           =   7
         Left            =   1800
         TabIndex        =   19
         Top             =   1200
         Width           =   255
      End
      Begin VB.Label lblField
         Caption         =   "#6"
         Height          =   255
         Index           =   6
         Left            =   1800
         TabIndex        =   18
         Top             =   840
         Width           =   255
      End
      Begin VB.Label lblField
         Caption         =   "#5"
         Height          =   255
         Index           =   5
         Left            =   1800
         TabIndex        =   15
         Top             =   480
         Width           =   375
      End
      Begin VB.Label lblField
         Caption         =   "#4"
         Height          =   255
         Index           =   4
         Left            =   240
         TabIndex        =   14
         Top             =   1560
         Width           =   375
      End
      Begin VB.Label lblField
         Caption         =   "#3"
         Height          =   255
         Index           =   3
         Left            =   240
         TabIndex        =   13
         Top             =   1200
         Width           =   375
      End
      Begin VB.Label lblField
         Caption         =   "#2"
         Height          =   255
         Index           =   2
         Left            =   240
         TabIndex        =   12
         Top             =   840
         Width           =   375
      End
      Begin VB.Label lblField
         Caption         =   "#1"
         Height          =   255
         Index           =   1
         Left            =   240
         TabIndex        =   11
         Top             =   480
         Width           =   375
      End
   End
   Begin VB.TextBox txtTabs
      Height          =   285
      Index           =   1
      Left            =   3360
      TabIndex        =   2
      Top             =   600
      Width           =   855
   End
   Begin VB.TextBox txtTabs
      Height          =   285
      Index           =   0
      Left            =   3360
      TabIndex        =   0
      Top             =   240
      Width           =   855
   End
   Begin VB.Label lblField
      Caption         =   "Number of Tabs to Use:"
      Height          =   255
      Index           =   0
      Left            =   240
      TabIndex        =   1
      Top             =   240
      Width           =   2415
   End
End
Attribute VB_Name = "frmTabSet"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Sub MakeVisible()

If Check1.Value = 1 Then
    For i = 0 To 11
        txtTabStop(i).Visible = (i < Val(txtTabs(0)))
    Next
End If
       


End Sub


Private Sub Check1_Click()

If Not IsNumeric(txtTabs(0)) Then Exit Sub



Frame1.Enabled = (Check1.Value = 0)
txtTabs(1).Enabled = (Check1.Value = 1)

If Check1.Value = 1 Then MakeVisible
       


End Sub

Private Sub cmd_Click(Index As Integer)
Select Case Index
    Case 0
        If Not IsNumeric(txtTabs(0)) Then Exit Sub
        If Not IsNumeric(txtTabs(1)) Then Exit Sub
   
        frmMainMenu.ScaleMode = 4
        frmMainMenu.rtb1.SelTabCount = Val(txtTabs(0))      'InputBox("Tabs", "TAB STOP", 0)
        If Check1.Value = 1 Then
            i = Val(txtTabs(1))
            For x = 0 To frmMainMenu.rtb1.SelTabCount - 1
                frmMainMenu.rtb1.SelTabs(x) = i * x
            Next x
        Else
            For x = 0 To frmMainMenu.rtb1.SelTabCount - 1
                frmMainMenu.rtb1.SelTabs(x) = Val(txtTabStop(i))
            Next x
        End If
        frmMainMenu.ScaleMode = 1
        Me.Hide
   
    Case 1
        Me.Hide

End Select
End Sub

Private Sub Form_GotFocus()
If Me.WindowState = 1 Then Me.WindowState = 0
End Sub

Private Sub Form_Load()
Check1.Value = 1
Frame1.Enabled = False
txtTabs(0) = 10
txtTabs(1) = 10
txtTabs(1).Enabled = True


 MakeVisible
End Sub


Private Sub txtTabs_Change(Index As Integer)
If Index = 0 Then
    If Not IsNumeric(txtTabs(0)) Then txtTabs(0) = 10
    If Val(txtTabs(0)) < 1 Then txtTabs(0) = 1
    If Val(txtTabs(0)) > 12 Then txtTabs(0) = 12
End If
End Sub


Private Sub txtTabs_LostFocus(Index As Integer)
If Index = 0 Then MakeVisible
End Sub

0
 
LVL 18

Accepted Solution

by:
mdougan earned 166 total points
ID: 2819557
OK, this last idea is probably too heinous to consider, but what if you used a VideoSoft Flex Grid instead of your Richtext box?  It has all of the cool abilities to color code things, and you could definately make the columns line up properly.  You could repress the grid lines so they wouldn't show. The only thing I'd be afraid of is how the keyboard would respond.  You'd probably have to programatically make the grid change cells after each cell had a single character in it.

Now, with Cobol, since particular columns have particular purposes, maybe you could make the first 7 characters into one column, the 8th character into it's own column, then the next column streatches out to 70 something characters etc.  

As I said, it's a heinous thought, but I thought I'd throw it out there.
0
 

Author Comment

by:jaynorth
ID: 2827956
Although this may not have been what I was looking for, the off-beat alternative that you suggested tells me that you are probably a kick-ass programmer.  I think I'll experiment with this other control just for the learning experience. The richtextbox has so many quirks that quite frankly, I'm just sick of the dang thing! If I run into any future grief, I'll be sure to let you know.  Thanks, Mike
0
 
LVL 18

Expert Comment

by:mdougan
ID: 2860491
Thanks!  And by all means, feel free to pass any future grief by me directly:

mdougan@earthlink.net

I have been programming for a while, and I've found that sometimes, when the obvious things aren't working you have to steal a line from Monty Python:

And now for something completely different....

Do check out the Videosoft Flexgrid, I'm very impressed by all of it's functionality (though it's a bit pricy)

Mike
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question