-
Jun 22nd, 2021, 09:04 AM
#1
Thread Starter
Fanatic Member
Template for RichTextBox
Can I set up template styles for a RichTextBox such as one finds in the Normal template of MS Word, where the fonts and paragraph styles are defined.
Thanks
PK
-
Jun 22nd, 2021, 10:21 AM
#2
Re: Template for RichTextBox
Set all the properties that you want in a blank RTB and use the SaveFile to save the template file.
Then use LoadFile to load the template.
-
Jun 22nd, 2021, 11:01 AM
#3
Thread Starter
Fanatic Member
Re: Template for RichTextBox
Excellent thanks, Eduardo.
PK
-
Jun 22nd, 2021, 05:46 PM
#4
Re: Template for RichTextBox
Doesn't sound very useful. If you only need something that basic I'm not sure why this was a question.
Properly implementing textstyles and templates is far more involved than this.
-
Jun 22nd, 2021, 05:49 PM
#5
Thread Starter
Fanatic Member
Re: Template for RichTextBox
dilettante,
At least it's a large step for me. I do not know how far I should push this envelope. It is one thing to swat flies here, but the acid test comes years later if I do not have enough foresight.
PK
-
Jun 23rd, 2021, 02:11 AM
#6
Thread Starter
Fanatic Member
Re: Template for RichTextBox
I wish to use templates for the RTB and one external file for every template seems to be a good idea.
I also do not want to use OLE for controls and other objects, as I will then get embroiled in a myriad of files.
My first template will be a To Do List with tick boxes, similar to the Checked Listbox of VB6. Is there a way to have tick boxes embedded in the rtfText that is saved to the database?
Thanks
PK
-
Jun 23rd, 2021, 02:33 AM
#7
Re: Template for RichTextBox
Early RTF was progressing toward something HTML-like with "protected" and unprotected text markup. The unprotected areas could be edited by the user. This was all but abandoned early on. Vestiges remain, but they are rarely used today.
Saving 100 To Do Lists as 100 RTF documents in a database is... odd. As well as very bulky.
Why reinvent the Form we already have in VB?
It almost sounds like you want to reinvent Microsoft OneNote, or at least an early version of it. Or maybe InfoPath?
-
Jun 23rd, 2021, 04:07 AM
#8
Thread Starter
Fanatic Member
Re: Template for RichTextBox
dilettante,
The application I have is to have a checklist which a user (inspector) must complete when he inspects a building project and it has about sixty checkboxes.
It also has the history of the building process as text.
I was trying to combine the two otherwise I will have a text field and about sixty different boolean fields.
Is that what I should do?
Thanks
PK
-
Jun 23rd, 2021, 06:03 AM
#9
Re: Template for RichTextBox
Code:
Private Sub Form_Load()
rtb1.Text = ""
AddOptionText rtb1, "Option 1"
AddOptionText rtb1, "Option 2"
AddOptionText rtb1, "Option 3"
End Sub
Private Sub AddOptionText(rtb As RichTextBox, OptionText As String)
Dim FS As Single
Dim FN As String
With rtb
FS = .SelFontSize
FN = .SelFontName
.SelFontName = "Wingdings"
.SelFontSize = FS * 1.5
.SelText = "q" ' "o"
.SelFontName = FN
.SelFontSize = FS
.SelText = " " & OptionText & vbCrLf
End With
End Sub
Check what you like better for the checkbox, "q" or "o".
The only problem is if Wingdings font is not installed, in that case it would be good to provide some alternative code, using Wingdings 2, Webdings or other font.
Last edited by Eduardo-; Jun 23rd, 2021 at 06:15 AM.
-
Jun 23rd, 2021, 08:46 PM
#10
Re: Template for RichTextBox
Originally Posted by Peekay
I was trying to combine the two otherwise I will have a text field and about sixty different boolean fields.
Is that what I should do?
Doesn't that depend on what you will do with the data after collecting it?
If it is just a blob that maybe gets reviewed/corrected, maybe printed... perhaps it doesn't matter. But if the collected data needs to be searched, reported, summarized, etc. then you might want to consider alternatives.
-
Jun 23rd, 2021, 09:19 PM
#11
Re: Template for RichTextBox
Originally Posted by dilettante
Doesn't that depend on what you will do with the data after collecting it?
If it is just a blob that maybe gets reviewed/corrected, maybe printed... perhaps it doesn't matter. But if the collected data needs to be searched, reported, summarized, etc. then you might want to consider alternatives.
I think he wants to print on paper a check list with items to be manually checked with a pen (at least regarding this step, this current question).
And you are instead thinking on a program UI.
-
Jun 23rd, 2021, 09:21 PM
#12
Re: Template for RichTextBox
If so, then why not just break out Publisher, or even WordPad or Word?
-
Jun 23rd, 2021, 10:19 PM
#13
Re: Template for RichTextBox
Well if the goal is to create check lists that will be printed out my first thought would be to use a report engine to handle the job. Perhaps the items that should appear on the checklists would be stored in a db and then appear on the report based on the query you send so there could be multiple versions and only need a single file for the data and a single report in the program.
If the goal is to do it through UI then my first thought would be a flex grid
-
Jun 23rd, 2021, 11:12 PM
#14
Re: Template for RichTextBox
Originally Posted by DataMiser
Well if the goal is to create check lists that will be printed out my first thought would be to use a report engine to handle the job. Perhaps the items that should appear on the checklists would be stored in a db and then appear on the report based on the query you send so there could be multiple versions and only need a single file for the data and a single report in the program.
Yes, there are probably a lot of ways of doing it, but the RTB approach I think is also a valid one.
-
Jun 24th, 2021, 12:31 AM
#15
Thread Starter
Fanatic Member
Re: Template for RichTextBox
Thanks for your helpful comments guys, and I can see that you are fired up, so I need to elaborate.
I am developing a client service centre for a municipality. Residents phone in with a complaint and that complaint should be in plain text in the complaints table. I am using varchar(max) for that. Updates on that complaint forms the history of it in plain text.
These complaints are referred to users in the relevant department which each gets a record in the response table. These responses have an rtf field where reports are generator in a nvarchar(max) field.
Then tasks are generated from these responses and these tasks have taskspecs in a table Tasks with an nvarchar(max) field for the taskspecs.
Then the inspectors have a checklist to mark whether the tasks comply with the spec.
It is all paperless and stays on record.
On the side I run an app where resources get a tablet with access to the tasks table to quote for it.
PK
-
Jun 26th, 2021, 03:46 AM
#16
Thread Starter
Fanatic Member
Re: Template for RichTextBox
I think the most important thing I need to know is whether an added OLE object can be stored together with the rtf text in the RTB in the database as rtfText, or whether it will always remain an independent file disconnected from the database.
Thanks
PK
-
Jun 26th, 2021, 04:09 AM
#17
Re: Template for RichTextBox
Objects can be linked or embedded. Embedded objects are carried within the RTF data.
But be aware that this is likely to trigger malware protection software. Embedding into Word and RTF files is a common technique for passing trojan horses and phishing attacks.
-
Jun 26th, 2021, 04:53 AM
#18
Thread Starter
Fanatic Member
Re: Template for RichTextBox
Thanks, dilettante.
If I can add text, pictures and VB6Controls like a listbox? into the RTB and I save it to the database, then it would be safe, I presume.
I also presume the rtb.oleobjects add is embedment which can be saved as rtfText.
PK
-
Jun 26th, 2021, 05:40 AM
#19
Re: Template for RichTextBox
I don't think you can embed VB6 intrinsic controls.
Now you need pictures as well? This is getting ugly. How much of this do you have working?
-
Jun 26th, 2021, 06:36 AM
#20
Thread Starter
Fanatic Member
Re: Template for RichTextBox
dilettante,
I have nothing working yet, but I am setting up the architecture by trying to stretch the envelop and see what I can use practically.
I need to give the users some functionality without going to Word.
That's the name of the game.
However, I know I shall stop when you start to frown on me.
Thanks
PK
-
Jun 26th, 2021, 07:47 AM
#21
Re: Template for RichTextBox
Originally Posted by Peekay
...trying to stretch the envelop and see what I can use practically.
If you really want to do that, then don't go down the "RTF-route", I'd say...
Everybody is using HTML these days to show, edit and render "RichText"...
And if your "RichText" has (on top of that) to allow "user-interaction, in-between the RichText",
that's just one more reason to use HTML (because it was developed with that requirement in mind).
Here's a short code-snippet, which fullfills a lot of what you were asking for in just a few lines...
Code:
Option Explicit
Private wbExt As VBControlExtender, wb As Object
Private Sub Form_Load()
InitBrowserCtl
Dim S$: S = S & "<h3>Some Heading</h3>"
S = S & "<p>Some Paragraph with <b>bold</b> and <i>italic</i> formatting...</p>"
S = S & "<input id='chk1' type='checkbox'>My CheckBox 1</input><br>"
S = S & "<input id='chk2' type='checkbox'>My CheckBox 2</input><br>"
wb.document.body.innerHtml = S
End Sub
Private Sub InitBrowserCtl()
Set wbExt = Controls.Add("Shell.Explorer.2", "wbExt")
wbExt.Visible = True
Set wb = wbExt.object
wb.navigate2 "about:blank"
Do Until wb.readystate = 4: DoEvents: Loop
End Sub
HTH
Olaf
Last edited by Schmidt; Jun 26th, 2021 at 07:52 AM.
-
Jun 26th, 2021, 08:16 AM
#22
Thread Starter
Fanatic Member
Re: Template for RichTextBox
Olaf,
It works very well thanks.
Once I have the code for the HTML, do I just save it as rtfText or Text in the database (and how), and retrieve it in a browser?
What about a CSS file. Can I have that as template?
PK
PK
-
Jun 26th, 2021, 09:31 AM
#23
Re: Template for RichTextBox
Originally Posted by Peekay
Once I have the code for the HTML, do I just save it as rtfText or Text in the database (and how)...
Not sure, what you mean, because the goal should be, to get rid of any RTF-Texts (or -Controls).
If I understood you correctly, then the scenario is a bit like a questionnaire, and you need:
- a "nice, rich formatted questionnaire-Template" (which also scrolls nicely, when it's larger than the hosting VB-Form)
- which also allows for a few simple User-Inputs directly within the "RichText" (mostly CheckBoxes and simple Text-Inputs)
As for DB-interaction...
- in Read-Direction you need a Table "Templates" (with Fields: ID Identity, HTML nvarChar(max), CSS nvarChar(max))
- and for Write-Direction you need a Results-Table (with Fields: ID Identity, User_ID Int, Template_ID Int, ResultXML nvarChar(max))
the latter Field ResultXML could e.g. receive the Results of an ADO-Rs (the example below produces that at Form-Unload)
Originally Posted by Peekay
What about a CSS file. Can I have that as template?
Of course, ... as outlined above already (in the Table "Templates") you can store CSS-information for your questionnaire-HTML-Form in a separate Field if you want (in the code below, the two DB-Table-Fields are represented as simple Form-Constants to keep the example easy ).
And as said, the results of your Form-Inputs should be gathered in a different DB-Table (in the demo below, I demonstrate gathering of all potentially defined Input-Fields in a two Column-ADO-Rs first, which is then later serialized into an XML-String - but JSON would work as well)
Code:
Option Explicit
Const HTML = "<h3>Some Heading</h3>" & _
"<p>Some Paragraph with <b>bold</b> and <i>italic</i> formatting...</p>" & _
"<input id='chk1' type='checkbox'>My CheckBox 1</input><br>" & _
"<input id='chk2' type='checkbox'>My CheckBox 2</input><br>" & _
"<p>Text-Input: <input id='txt1' type='text'></p>"
Const STYLE = "body { font-family:Arial; font-size=10pt; }"
Private wbExt As VBControlExtender, wb As Object
Private Sub Form_Load()
InitBrowserCtl
wb.document.createStyleSheet.cssText = STYLE
wb.document.Body.innerHTML = HTML
End Sub
Private Sub InitBrowserCtl()
Set wbExt = Controls.Add("Shell.Explorer.2", "wbExt")
wbExt.Visible = True
Set wb = wbExt.object
wb.navigate2 "about:blank"
Do Until wb.readystate = 4: DoEvents: Loop
End Sub
Private Sub Form_Resize()
wbExt.Move 0, 0, ScaleWidth, ScaleHeight
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim Rs As Object, Stream As Object, XML As String
Set Rs = GetResultRs() 'use a Helper-Function, to get all the Input-Values back in a Recordset
Do Until Rs.EOF
Debug.Print Rs!id, Rs!Value
Rs.MoveNext
Loop
Set Stream = CreateObject("ADODB.Stream")
Rs.Save Stream, 1 '<- adPersistXML
XML = Stream.ReadText(Stream.Size)
Debug.Print XML '<- this could be saved in a DB-Field
End Sub
Private Function GetResultRs() As Object
Set GetResultRs = CreateObject("ADODB.Recordset")
GetResultRs.Fields.Append "ID", vbString
GetResultRs.Fields.Append "Value", vbVariant
GetResultRs.open
Dim Elmt As Object
For Each Elmt In wb.document.getElementsByTagName("INPUT")
Select Case Left$(Elmt.id, 3)
Case "chk": GetResultRs.AddNew Array(0, 1), Array(Elmt.id, Elmt.Checked)
Case "txt": GetResultRs.AddNew Array(0, 1), Array(Elmt.id, Elmt.Value)
End Select
Next
If GetResultRs.RecordCount Then GetResultRs.UpdateBatch: GetResultRs.MoveFirst
End Function
HTH
Olaf
-
Jun 26th, 2021, 09:44 AM
#24
Thread Starter
Fanatic Member
Re: Template for RichTextBox
I understand the data handling side reasonably well, thanks.
As a start I need two windows in my program, I presume, probably a Textbox and/or RichTextBox for data input, or should I build my own HTML editor?
-
Jun 26th, 2021, 10:15 AM
#25
Re: Template for RichTextBox
Originally Posted by Peekay
I understand the data handling side reasonably well, thanks.
I hope you do... (not sure, whether you've properly tested the "Write-Direction" I've covered in the example above yet).
Originally Posted by Peekay
As a start I need two windows in my program, I presume, probably a Textbox and/or RichTextBox for data input, or should I build my own HTML editor?
As said, get rid of any RTF-TextBoxes... (they are not needed with this approach)...
When I talked about "RichText" in my postings here, I meant "HTML-formatted RichText" (not RTF).
Also cannot see currently, where these "two VB-Forms" come in...
In my thinking (not sure if I'm wrong) - it is not your Customer who shall create the Templates for the Input-Forms...
Instead it will be your responsibility to provide "complete, readymade templates" for your questionnaire-forms...
(later available behind a DB, which you ship with your App).
If my assmumption is right, then all boils down to what my latest example does:
- just show a single (potentially modal) VB-Form with a BrowserControl on it
- which gets its content fed from two DB-Template-Fields (as HTML- and CSS-Strings)
- the shown HTML-Control-based Form will then be "filled out" by the Customer or "Inspector" of whoever will use it in the end...
- and at Form-Unload-Time you gather the filled-out HTML-input-fields (their IDs and Values) into a single String (in the Demo done via an Rs -> and then serialized as XML)
Your "other Form" (the Editor-Form) is (IMO) not needed, because you can either install a local HTML-Editor-App to produce the HTML-snippets for your questionnarie-templates...
Or use an Online-Editor for that: https://www.tiny.cloud/docs/demo/classic/
From the link above, you can easily (after switching TinyMCE into html-code-mode) Copy&Paste your Templates and Develop/Edit them there.
It is of course also possible, to host the TinyMCE-Editor within another Browser-Control on a VB-Form (to achieve similar RichEdit-Features to an RTF-Box) - but if you're the only one who edits these Templates, then you don't need to go that route...
Olaf
Last edited by Schmidt; Jun 26th, 2021 at 10:26 AM.
-
Jun 26th, 2021, 10:19 AM
#26
Thread Starter
Fanatic Member
Re: Template for RichTextBox
Thanks Olaf, as always I appreciate your help. It is a lot for me to work through now.
PK
-
Jun 26th, 2021, 11:14 AM
#27
Thread Starter
Fanatic Member
Re: Template for RichTextBox
I need some help to get TinyMCE editor set up on my form.
The setup requires HTML language which is not a VB6 language, or should I start a web page on a web for this purpose?
Here is what I have:
Code:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Response.aspx.vb" Inherits="ClientServices.Response" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <title>Client Services</title>
<script src="https://cdn.tiny.cloud/1/ebjfnqapwrpdelodq6ahfjkfovfscvembyfyvfomhi4lqfq7/tinymce/5/tinymce.min.js" ></script>
<script>
tinymce.init({selector: '#mytextarea'});
</script>
<script>
tinymce.init({
selector: 'textarea', // change this value according to your HTML
plugin: 'a_tinymce_plugin',
a_plugin_option: true,
a_configuration_option: 400
});
</script>
<style type="text/css">
#mytextarea {
width: 1136px;
}
</style>
</head>
<body>
<textarea id="mytextarea">Welcome to TinyMCE!</textarea>
<script
tinymce.init({
selector: 'textarea',
plugins: 'a11ychecker advcode casechange formatpainter linkchecker autolink lists checklist media mediaembed pageembed permanentpen powerpaste table advtable tinycomments tinymcespellchecker',
toolbar: 'a11ycheck addcomment showcomments casechange checklist code formatpainter pageembed permanentpen table',
toolbar_mode: 'floating',
tinycomments_mode: 'embedded',
tinycomments_author: 'Author name',
});
</script>
</body>
</html>
Thanks
PK
Last edited by Peekay; Jun 26th, 2021 at 01:31 PM.
-
Jun 26th, 2021, 10:02 PM
#28
Thread Starter
Fanatic Member
Re: Template for RichTextBox
dilettante,
I really appreciate the time you have spent here, and I know there is no problem you cannot solve! It was done well! Thank you.
However, I sit with this dichotomy of trying to wring information out of zero intrinsic data (such as a pulling a checklist from the air or a rabbit from a hat) which is a non-starter.
In my RichTextBox, I typically have a technical / engineering user responding to a complaint which can be anything a municipality does from omitting to collect refuse to patching a road to making a new water connection to telling a lie.
How will the user express himself? With explanations, speculations, specifications, photos, etc. or a report for management to consider.
He then gets an instruction to implement his recommended response, and again in a textbox he sets out some task with a task specification and he has checks for confirming the task has been done according to specification.
The whole wide world is open as to what solutions may be implemented.
In the trivial solution, I only need to give him a multiline plain TextBox to state his case ... but someone like a contractor must read this and quote for it, and it must look like a professional document.
I thus must go one better and give him the opportunity for formatted text, to increase the intelligibility of this response and make it more professional. Maybe he can better explain himself if he adds a photo or a drawing (jpg or pdf).
So, at this stage I am considering the possibilities.
Starting with an RTB which can be formatted to some extent, like boldface, paragraphs and so on, is a very good beginning. In fact the user can draw up a set of checks in an RTB which does not need to be ticked, but with only a button or tick at the bottom wherein he declares or certifies that the checks were all done.
I realize that I can later add functionality, and maybe I must just start off with formatted text, which will not need any extra records or database fields, except for the formatted text and maybe a photo which can be stored as a bitmap in a separate field in the database table.
I am sorry for the tall order.
PK
-
Jun 27th, 2021, 02:56 AM
#29
Thread Starter
Fanatic Member
Re: Template for RichTextBox
How do I export RTB text as a Word document?
PK
-
Jun 27th, 2021, 03:04 AM
#30
Re: Template for RichTextBox
I don't know of anything that supports that except Word itself or perhaps some Microsoft or 3rd party format conversion utility. There isn't a lot of demand for that.
About the only obvious thing might be to laboriously convert the RTF data into the later non-binary Word formats that wrap XML within a ZIP archive by another name. Good luck!
-
Jun 27th, 2021, 04:39 AM
#31
Thread Starter
Fanatic Member
Re: Template for RichTextBox
-
Jun 27th, 2021, 05:20 AM
#32
Thread Starter
Fanatic Member
Re: Template for RichTextBox
And so my love affair with the RTB ends. From now on I shall know it as the PoorTextBox, as dilettante warned me before I went on this wild goose chase. Some things are just not what they seem to be.
Thanks for everyone who contributed. It was a rich journey for me chasing false gold.
PK
-
Jun 28th, 2021, 08:09 AM
#33
Thread Starter
Fanatic Member
Re: Template for RichTextBox
I am trying to implement Undo and Redo in my PTB.
The internet says the RTB has two methods named Undo() and Redo(), but I do not find it in the Help.
Thanks
PK
-
Jun 28th, 2021, 08:15 AM
#34
Thread Starter
Fanatic Member
Re: Template for RichTextBox
When I use code from elsewhere for the RTB, they use EM_HIDESELECTION as a constant when using the SendMessage API, but I cannot find its meaning or values:
Her is one such:
Code:
x& = SendMessage(frmRTB.rtbEdit.hwnd, EM_HIDESELECTION, 1&, 1&)
Thanks
PK
-
Jun 28th, 2021, 08:28 AM
#35
Re: Template for RichTextBox
Code:
Public Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Long) As Long
Public Const WM_USER = &H400
Public Const EM_HIDESELECTION = WM_USER + 63
https://www.vbforums.com/showthread....ll=1#post57534
-
Jun 28th, 2021, 08:38 AM
#36
Thread Starter
Fanatic Member
Re: Template for RichTextBox
Arnoutdv,
Thank you so much
PK
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|