A routine to insert tables in Richtextbox

Submitted on: 2/14/2015 5:15:00 AM
By: Mario Villanueva (from psc cd)  
Level: Intermediate
User Rating: By 2 Users
Compatibility: VB 6.0
Views: 7498
     This is a routine that add a table to the current selection in a RichTextBox. I didn't find how can I do this on the web, so I made it by looking on the rtf Specification. I expect that this would be helpfull for those who are using RTB. If you find how to fix the problems i found please send me your work. (Sorry for my english ;) )

				Public Sub InsertTable(Rtb as RichTextBox, vRows as integer,vCols as integer)
Dim A As String, i As Integer, j As Integer
A = "{\rtf1\ansi\ansicpg1252\deff0" & _
"{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}" & _
"\viewkind4\uc1\trowd\trqc\trgaph108\trleft-8" & _
"\trbrdrt\brdrs\brdrw10" & _
"\trbrdrl\brdrs\brdrw10" & _
"\trbrdrb\brdrs\brdrw10" & _
For i = 1 To vCols
A = A & "\clbrdrt\brdrw15\brdrs" & _
"\clbrdrl\brdrw15\brdrs" & _
"\clbrdrb\brdrw15\brdrs" & _
"\clbrdrr\brdrw15\brdrs" & _
"\cellx" & _
CStr((ScaleX(Rtb.Width, Rtb.Parent.ScaleMode, vbTwips) \ vCols * 2) * i) & _
A = A & "\pard\intbl\lang3082\f0\fs24"
For i = 1 To vRows
A = A & "\intbl\clmrg"
For j = 1 To vCols
A = A & "\cell"
A = A & "\row"
A = A & "}"
Rtb.SelText = A
End Sub

Other 3 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.