Question To use or not to use a database

chazrab

Member
Joined
Nov 11, 2022
Messages
23
Programming Experience
10+
An aftetthought on my journey into VS/C#. After a restful night's sleep , awaking to a sunny and cold Sun. AM, I still have the lingering thoughts: me to myself: " I developed this entire Bible application that does everything I want it to and even better than Logos or other tradition BIble applications, why would I want to even consider trying to move this to VS in C#, if it were not for the lingering one thing that keeps bugging me at 2:00 AM most every night: VBA does not allow displaying red text substrings in a Textbox, be it a regular Textbox1 or a Rich Textbox on a userform, given that the Rich Textbox control in is inferior it its ease of programming red text substrings for the 3,000+ Words of Jesus Christ?

And, do I even need a database to do this in VS ? So, following one YT tutorial, I installed MAMP and MySQL Workbench. The point I'm at is to create a schema of the relationship structure. From what little I know about DB's this would look like: Book to Chapter (1-M) ->? Chapter - Verse(1-M) and Verse to Verse Note(1-1) . That would define the ID as the Primary key.

Once that's done, and that seems pretty easy, the next step is to do what I did in the userforms in my VBA app: Textbox1 displays the results of a 5 column database query of the entire 31,103 rows in the db, be it Access or some other db that plays well with VS and C#. The Listbox Rowsource in VBA is the Excel sheet. To me, the Listbox Rowsource in a VS app would be a database.


Once that's done, the last task in telling VS/C# when to begin and end displaying red text in the Textbox.


OI know there are people out there that are light years ahead of me in their experience realm who's probably laughing at my editorial here that could imagine this done with their eyes closed. But I'm not there - yet. Readers of this post would ask "so what's your question, cr ?" - Answer: can VS/C# be used to display red text substrings in a userform textbox, using something like "markers" or displaying red tex from the db that already has red text embedded in its data ? Then all it would be, if that's possible, is just a matter of changing the text color in 3,000+ words in the db.

If hard coding such as
C#:
Private Sub UserForm_Activate()
Dim firstpos As Integer, lastpos As Integer
Inktext.Text = "And Jesus Said to him," & Chr(34) & _
"therefore when you see the abomination of desolation standing in the Holy Place." & Chr(34) &
(therefore when you see the abomination of desolation standing in the Holy Place. display in red text)

linktext is the name of an RTF textbox

needs to be done to accomplish this, then it would not be timewise to try to replicate this in VS/C#.

Thanks to all for help, guidance and criticisms. I have no problem abandoning learning VS/C# if this won't
help me accomplish this. The thing is, though, others have done this many times, as was Wordsearch 12 developed in C#, so why can't I ?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,514
Location
Chesapeake, VA
Programming Experience
10+
And, do I even need a database to do this in VS ? So, following one YT tutorial, I installed MAMP and MySQL Workbench. The point I'm at is to create a schema of the relationship structure. From what little I know about DB's this would look like: Book to Chapter (1-M) ->? Chapter - Verse(1-M) and Verse to Verse Note(1-1) . That would define the ID as the Primary key.
See how this bible database created their database ID key system:

I suspect that your Access database was some kind of fork of the data from that github project.

As a side note, by database design teacher in college would be rolling in his grave when he sees that keying used as the database primary key. From the purist relational point of view, a table's primary key is just a way for the system to relationships of rows in one table with other rows. They should not encode any other semantic information in them. If there is semantic information in the key, the key should be broken up into multiple columns and the primary key should be a composite key. In other words, instead of encoding the book, chapter, and verse into a single key column, there should be a separate book, chapter, and verse columns, and you tell the database that the primary key for that table is the three columns taken together. Most modern RDBMS's support composite keys, but there are old RDBMS's that don't.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,514
Location
Chesapeake, VA
Programming Experience
10+
Answer: can VS/C# be used to display red text substrings in a userform textbox, using something like "markers" or displaying red tex from the db that already has red text embedded in its data ?
As I previously responded in your other thread, no. The textbox is monochrome and single font.

You can use the RichTextBox which is not monochrome nor single font. You just need to load in text with rich text format (RTF) markup.

That will require you to update all your bible verses from your data source (be it a database, text files, CSV files, etc.) to store all the verses in RTF. Alternatively, you could try load your bible verses from your data sources, then dynamically convert to RTF, and then put that into a RichTextBox.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,514
Location
Chesapeake, VA
Programming Experience
10+
As an example:
1668962220582.png


C#:
using System;
using System.Windows.Forms;
using System.Drawing;
using System.IO;

namespace WinForms
{
    class MainForm : Form
    {
        MainForm()
        {
            Text = "Main";
            Size = new Size(800, 600);

            var rtb = new RichTextBox() { Dock = DockStyle.Fill };

            using (var stream = new MemoryStream())
            using (var writer = new StreamWriter(stream))
            {
                writer.Write(@"{\rtf1\ansi ");
                writer.Write(@"{\colortbl \red0\green0\blue0; \red255;green0;blue0; } ");
                writer.Write(@"And their eyes were made open. And Jesus said to them sharply, {\cf1 Let no man have knowledge of it.}");
                writer.Write("}");
                writer.Flush();
                stream.Seek(0, SeekOrigin.Begin);
                rtb.LoadFile(stream, RichTextBoxStreamType.RichText);
            }

            Controls.Add(rtb);

            CenterToScreen();
        }

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
    }
}

Hopefully the screen shot above also demonstrates how bad an idea red text on a white background can be like I also mentioned in another one of your threads.
 

chazrab

Member
Joined
Nov 11, 2022
Messages
23
Programming Experience
10+
Hi maxcata. Thanks for the follow up .

It's not so much a matter of whether to use Access or any other DB as a Datasource, but more of
a display text color substring issue as I mentioned before. I'll use Mongo if that would help my cause. But to
me a DB is a DB - a place to store and access data.

Truthfully, I sort of gave up on learning VS/C# to port my Excel VBA Bible app over. Reason being, as I had mentioned previously, is that the one caveat with a VBA app is that it does not provide an easy way to display the words of Jesus in red in a userform textbox.

The VBA RTF is clumsy and requires hard coding, that is, physically having to
write out every line of text in the editor and put between some "marker" such as quotes.

I need to do this with 3,000+ words in red text. If C# does not have an easier way, there'd be no reason to move the app to VS in C#. If, however, VS/C# does have a way to do this in a copy/paste code block without having
to hard code every word, then it would be very worthwhile for me to continue learning VS/C#.





Two points: someone said that If I would have developed this in Word, displaying red substring text in a Word userform textbox would be very achievable.

The other thing is that every - I mean every Bible application gives the option to display the words of Jesus in red. They found a way to do it, so why can't I, or anyone else for that matter.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,514
Location
Chesapeake, VA
Programming Experience
10+
It's not a matter of C# being able to do it easily. It's a matter of having a data source that either:
  • has the strings already formatted appropriately for the intended display target;
  • has the strings with embedded markup that surrounds that text to be highlighted; or
  • has a parallel data stream that has the offsets and lengths of the highlights.
With the latter two options, it's a matter of converting the plain text into the format appropriate for display.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,514
Location
Chesapeake, VA
Programming Experience
10+

chazrab

Member
Joined
Nov 11, 2022
Messages
23
Programming Experience
10+
Hi Skydiver - thanks for the reply. I read the documentation on link above. This may be a stupid question as I eek my way through figuring this out - but by 'For the second option above, look for your source to be USFM format which has words of Jesus surrounded by \wj and \wj*.' - does that mean I would have to change the text in spreadsheet cells with these markers - or would I have to copy the entire text of Jesus' words to a Word doc and insert these markers between His words and the text?

The Rowsource Property in VBA is where a Userform textbox gets and displays its data. And this is data in the form of an Excel spreadsheet.

In responding back to you, an afterthought just occurred to me - maybe, in order to display the Words of Jesus in red in a Userform textbox, using the source to be USFM format as you mentioned, this can only be done if the application and userform is built in VS using C# - and that the VBA Rowsource property won't be able to read a USFM format.

If VBA is limited to only accepting data from an Excel sheet, and a USFM form does not work with spreadsheet cell data, then the Bible application of mine has to be redeveloped in VS/C# to be able to use the USFM form as a Datasource format.

This is all still a bit jumbled up to me right now, but because I keep seeing a Userform display red substring text in my Bible application I in my minds eye, feel like I have to keep pushing myself to accomplish this. "if it can be conceived, it can be achieved"

Thanks again for not giving up on me. I really appreciate your help and experience. I just need to know if my thinking on this is accurate or not.

cr
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,514
Location
Chesapeake, VA
Programming Experience
10+
Let's step back. With your current data, how are the words of Jesus currently marked up? How do you know (programmatically) which words are His, and which words are not?

Assuming that you currently don't have His words marked up, I was suggesting trying to get verses in USFM format -- and hopefully His words are marked between \wj and \wj*. (The two USFM formatted files I've stumbled across don't seem to have them marked up. I've not looked at any USFX formatted files.)

Assuming you can't find a bible is USFM (or USFX) with words of Jesus already marked up, then you will have to somehow markup all of His words. You don't even have to use the USFM markup. You could go as simple as putting His words in between curly braces, square brackets, etc. It doesn't really matter. You just need to know where His words start and where His words end.

So when it is type to display into a RichTextBox, you would take that text until you hit your beginning marker. Add that text into the RichTextBox. Change the current text color in RichTextBox to your highlight color. Then take the text until you hit your end marker. Add that text into the RichTextBox. Change the current text color in the RichTextBox to your normal color. Repeat until you run out of text from your bible verse. This can be done in VBA. It can be done in C#. It can be done in JavaScript manipulating HTML.

USFM format should be storable in Excel cells. The only special character in USFM is the backslash. Excel just treats a backslash just like any other character in a text cell.

What is not going to happen is that Excel will automatically format your cell. It cannot. It knows nothing about USFM. (I know some Excel wizards maybe able to parse that text with markup an create a new sheet with columns with alternating colors and different widths. They would place the non-His words in the normal cells, and His words in the highlighted cells. I'm just a pedestrian Excel user. I don't have those skills.)
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,514
Location
Chesapeake, VA
Programming Experience
10+
(The two USFM formatted files I've stumbled across don't seem to have them marked up. I've not looked at any USFX formatted files.)
Good news. Bad news. I found some in ebible.org. But alas, the files also are deeply mired in the other markup as well. It's going to take some scripting to remove all the other markup and just be left with just the markup for His words.
 
Top Bottom