Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Ok heres some code

 

In this code you will see something like this

For iv As Integer = 1 To verseCombo.Items.COunt

 

nextThe way the verseCOmbo works is this

 

when chapCombo.Text has chapter 1 for exampe then it populates verseCombo with item numbers 1 to what ever the total Number of verses in the chapter are

that info is pulled from a vInfo file which looks like this

Example

For the Book of 1 John there are

1-10 Chap 1 has 10 vereses

2-29

3-24

4-21

5-21 Chap 5 has 21 vereses

 

So again when chapCombo.Text reads chap "1" Then verseCombo is populated with the numbers 1 - 10

 

Ok with that said here is my code

 

Oh one more thing, the results I am getting is this, it finds chapter 1 and colors all the numbers Blue in chapter 1 but will not increment and then do chapter 2

 

Need Help on this one

 

           Dim ic As Integer
           Dim iv As Integer
           
           ic = 1
           If ic = "1" Then
               chapCombo.Text = ic
               For iv = 1 To verseCombo.Items.Count
                   rtbText.Find(ic & ":" & iv, RichTextBoxFinds.None)
                   rtbText.SelectionColor = Color.Blue

                   rtbText.Find(iv, RichTextBoxFinds.None)
                   rtbText.SelectionColor = Color.Blue

               Next
               ic = ic + 1
           Else
               chapCombo.Text = ic
               For iv = 1 To verseCombo.Items.Count
                   rtbText.Find(ic & ":" & iv, RichTextBoxFinds.None)
                   rtbText.SelectionColor = Color.Blue

                   rtbText.Find(iv, RichTextBoxFinds.None)
                   rtbText.SelectionColor = Color.Blue

               Next
               ic = ic + 1

           End If

 

I am on the right track because for the first time I can get it to change the first chapter... the fact that it is changing numbers at ll like this was a great relief just knowing it could be done LOL

I nearly did a Walter Brennon Dance :)

 

WHat am I not seeing here?

 

Pointers please

 

vbMarkO

Visual Basic 2008 Express Edition!
Posted (edited)

Bible Importer

 

Mark,

 

I'm doing a website for our church and have to do a Bible searcher, and I've thought of your woes when you were importing data and I said I would make one for you that would use a dataset (so you could do cool things like dsBible.FindByBookChapterVerse(book, chapterNumber, verseNumber) and be able to things that make you never want to work with a text file again. Anyway I had to download a text file of the Bible and get it into dataset format. Attached is the utility program I created to do it, along with the strongly typed dataset and the xml file that represents the Bible that you can use with the dataset if you'd like to for your project (see my utility program for how to load the XML file into the dataset). If nothing else I hope it can provide some light for you on strongly typed datasets (it's not very clean, but it's functional)...besides I did it in VB just for you...I normally do my home project in C#, but I know that wouldn't do you much good. :) Good luck in your endevors!

 

Brian

Bible.zip

BibleImporter.zip

Edited by PlausiblyDamp
Posted

I'll point out a couple of errors,

 

1. You're doing ic = "1" .. ic's an integer, not a string, you want ic = 1 instead.

 

2. look at your code, ic will never be any value other than one or two. The code runs, ic is set to one. if ic = 1 then.... ic = ic + 1.. so, ic = 2. If you run it again, ic will be set to one again, and thus it will continue.

 

3. Suggestion: I'm not sure exactly what you want to do, but maybe this could be a fix?

 

Static ic As Integer
'static means it will retain its previous value instead of being reset 
          Dim iv As Integer
           
          ' i took out ic = 1.  
           If ic = 1 Then 'You had if ic = "1".  ic is an integer, not a string.  
               chapCombo.Text = convert.tostring(ic) 'Try programming with option strict on.  It will point out these errors for you.  
               For iv = 1 To verseCombo.Items.Count
                   rtbText.Find(ic & ":" & iv, RichTextBoxFinds.None)
                   rtbText.SelectionColor = Color.Blue

                   rtbText.Find(iv, RichTextBoxFinds.None)
                   rtbText.SelectionColor = Color.Blue

               Next
               ic = ic + 1 'For a quicker way to type this, you can use ic += 1.  does the same thing, but looks nicer.  
           Else
               chapCombo.Text = convert.tostring(ic)  'Same as before
               For iv = 1 To verseCombo.Items.Count
                   rtbText.Find(ic & ":" & iv, RichTextBoxFinds.None)
                   rtbText.SelectionColor = Color.Blue

                   rtbText.Find(iv, RichTextBoxFinds.None)
                   rtbText.SelectionColor = Color.Blue

               Next
               ic = ic + 1

           End If 

 

4. By the looks of it, you don't need that if statement there at all. Not sure what you want exactly, but maybe this would do?

 

Static ic As Integer = 1
'static means it will retain its previous value instead of being reset it starts at 1.  
          Dim iv As Integer
           
          ' i took out ic = 1.  
  
               chapCombo.Text = convert.tostring(ic) 
               For iv = 1 To verseCombo.Items.Count
                   rtbText.Find(ic & ":" & iv, RichTextBoxFinds.None)
                   rtbText.SelectionColor = Color.Blue

                   rtbText.Find(iv, RichTextBoxFinds.None)
                   rtbText.SelectionColor = Color.Blue

               Next
               ic = ic + 1

          

 

5. The title of this thread implies that you want ic to increment with the for-next loop, so you might want to change it so ic is in the for-next loop. If you wanted that, then you might want to re-change 'static ic as integer = 1' to 'dim ic as integer = 1'

Posted
Mark,

 

I'm doing a website for our church and have to do a Bible searcher, and I've thought of your woes when you were importing data and I said I would make one for you that would use a dataset (so you could do cool things like dsBible.FindByBookChapterVerse(book, chapterNumber, verseNumber) and be able to things that make you never want to work with a text file again. Good luck in your endevors!

 

Brian

 

Brian, I must say the dataset idea has been passed by me before, I got excited about it only to find very little documentation, or maybe better stated to say lack of examples I could find to help me understand it.

 

I found a great tutorial on how to build a data set only to be disapointed by it not showing me how to populate it.

It was even sugested to me that I should populate my dataset from my text file...... but then..... I couldnt find one example of how that might be done.

 

 

I DLed your 2 files, however I was not able to get it to work, I think the problem is I am using VB 2005 Express Edition

So on first open it converted it this may have changed it enough that it wouldnt work.

 

I was however able to browse through the code, and it does interest me with the exception of the xml I know nothing of it... I tried working with it once in fact I wrote an address book or started to but was unable at the time to figure out how to edit it,

 

Anyway, I am sorry you went through so much to show me another way and it not work for you.

 

I am going to consider a dataset, but a quesstion does come to mind here... Why couldnt a text file be loaded to a dataset?

Isnt the idea here, that its the dataset that will speed things up and also give more options for the access of the data?

Thus getting around the limitations or woes of the text files.

 

This sort of why I have gone from text files to working with Rich Text Files...

The speed is much better loading them into an RTB then manipulating the data within the RTB.

 

My searches are 10 times faster than with text files....

 

Anyway, so far I am learning to a lot with them in fact, I keep discovering something new about how to make what I need done easier.

 

However, more than once I have been frustrated with what sometimes takes hours of searching for help or examples to reverse engineer so to speak so that I might take a nugget here or there to get what is needed done.

 

Truthfully, I have said, after writing this, I would re write it using database or something....

anythoughts about how maybe to get a textfile into a dataset using this format in the textfile

 

John

1:1: Bible text here

1:2: Bible text

2:1: Bible text

 

and so on Oh btw I uploaded the text files I am using to convert them

I have been trying to build a tool that will convert them with a few button clicks into this form below

 

John 1

1:1 Bible text goes here

2 more text

3 more text

John 2

2:1 Bible text

2 more text

 

This quite easy to go to scripture in an rtb with this

 

In fact I can load the John.rtf file which looks a lot like the above example

 

'All I have to do is load the file

rtbText.LoadFile(path)

' Then find the chapter header

rtbText.Find("John 1")

' Then start of chapter

rtbText.Find(":1")

' Then the verse

rtbText.Find("5")

' Then

rtbText.scrollToCarret()

 

That gets it done and fast to........ but still this could speed up if I was to use a different bible format ...meaning like this

 

Joh 1:1 Bible Text

Joh 1:2 Bible Text

instead of what I am using as shown above

Then I could simplify that to a single find method.

 

Anyway, I appreciate your effort, and your thoughts on the matter

 

vbMarkO

John.txt

Visual Basic 2008 Express Edition!
Posted
I'll point out a couple of errors,

 

1. You're doing ic = "1" .. ic's an integer, not a string, you want ic = 1 instead.

 

2. look at your code, ic will never be any value other than one or two. The code runs, ic is set to one. if ic = 1 then.... ic = ic + 1.. so, ic = 2. If you run it again, ic will be set to one again, and thus it will continue.

 

3. Suggestion: I'm not sure exactly what you want to do, but maybe this could be a fix?

'

 

What I am trying to is this color all the numbers within the rtb to Blue :)

 

They are in this format within the rtb

 

1:1 Bible text

2 Bible text

3 Bible text

2:1 Bible text

2 Bible text

 

and so on

Now what I can do, I can easily loop through and color each chapter start numbers such as

1:1

and

2:1

But I can only seem to get the verses of chapter 1

 

In fact your code only got chapter starts and verses within chapter 1

 

But then I know you are working with not knowing exactly where I was going

 

But anyway,

My code some explanation

When chapCOmbo.text = "1" Then this populates verseCombo with the amount of verses in chapter 1.

 

thus vi = 1 To verseCombo.Count

now what I was tring to do is once it itterated through verses in chapters 1

and vi reached its final count of verses within the chapter ie the UBound so to speak

 

That ic would then increment by 1 thus chapCombo would increase by one

thus vi would or should now have a new set of numbers as verseCombo has been populated with the number of verses of chapter 2

 

At least this is what I was tring to do, but not really getting it to happen

at least not yet anyway

 

vbMarkO

Visual Basic 2008 Express Edition!
Posted (edited)

I am going to consider a dataset, but a quesstion does come to mind here... Why couldnt a text file be loaded to a dataset?

Isnt the idea here, that its the dataset that will speed things up and also give more options for the access of the data?

Thus getting around the limitations or woes of the text files

 

That is exactly the idea of the XML file Mark; what I've done is taken a text file, ran it through my utility (which brings the text file into the dataset) and then I save the dataset as XML. This allows me to never have to parse the text file again (since it took all of 5 seconds on my P4 with 1G ram. In the future I just load the XML files (takes less than a second) into the dataset directly - the XML files contains the schema (what the tables are, any relationships, and datatypes for each column of each table, plus any special rules or expressions). So the church web site now has a search engine for the entire bible that takes less than a second to load - the search utilizes the Find and Select methods of the dataset.

 

Working with the actual web page I've found that I need to restructure my dataset anyway (this usually happens when you don't plan properly - and I know better, but I was in a rush). The problem is that I designed the dataset as it would be used in a database - a table that represents the books, and a table that represents the chapter/verse number with verse text with a relationship back to the book that it is contained in. In a database it would be horrible just to have a single table that just represented chapters (because the amount of data would be more than if you just stored the chapter number in the verses table) - but because there is no 'SELECT DISTINCT' on a dataset - least not that I'm aware of, so I need to seperate the chapters into its own table to reduce duplication.

 

If you want to see the little we're doing with it currently (it's in it's first iteration) goto http://www.salemumcwidewater.org and click Bible.

 

To your question the format you are using would require you to do some special string manipulation as I am in my utility - ideally this should be regular expressions but I'm not good with them, so even though I'm doing it a 'slower' way - overall it's still fast and it gets the job done - you know is this a personal project of yours or something for your church? If you tell me a little more about the overall purpose of the project and how it is to be used I might be able to help you with yours a little better if it's close to what I'm doing for our church's web site...the web site is N tiered so a lot of the logic could be pulled right into a windows program.

Edited by bri189a
Posted

Hi again,

 

I was able to load the xml into DreamWeaver so I could have a look at it.

 

I would like to test just how easy it might be to read the xml file you sent me ...Bible.xml

 

I have been doing a few searches to try and find how to call for data from the xml...

 

But if I understood you, its actually loaded back into the Dataset.... Correct?

 

Then you simply manipulate the data within the dataset as needed.... right?

 

What I am doing started out as simply a desire to see if I could write a program to call for scripture.... then it grew to wanting to write my own Sermon editor using an RTB alllowing Highlight, text color change, and all of the usual standards like you find in Word only I wanted to also make available a Bible Program that worked in harmony with the editor so that I could place scripture and notes together in an inviroment that they might compliment each other.

 

Then as I was doing this, I felt I shold then share this with others in our Church.... and now its grown that I will be making this available to all of our ministers once it is completed.

 

It is a personal endeavour in that I will get no compensation for the effort except perhaps a wonderful blessing :)

 

Im not qualified for commercial yet anyway, but for free Hey free is free, and so far this has been a great help in my Sermon preparations.

 

I am a Pastor, and I am finding this project a real blessing for me, just to have a tool to work the way I want it to.

 

 

I see the logic of doing this your way, but then I havent the experience you have with xml and datsets.

 

I am willing to learn, very willing....

 

 

I am curious, do you know what version of Bible you have in the XML.... it appeared as though it was KJV which is what I am using now... in fact I am using KJV 1611

 

 

Anyway,

How would I call for a scripture such as John 3:16

How would you do a phrase search in the xml file?

Or a Word search returning each scripture or scriptural address of where

the word was found?

 

I may have asked to much, but in an RTB this is pretty easy except for the

very last part returning or actually displaying all scriptures found LOL havent figured that one out yet :)

I can highLight every word and or phrase and even scroll to it, but I would like to see where for every instance of a word pr phrase that in another rtb it displays every scripture that contains the search target

 

vbMarKO

Visual Basic 2008 Express Edition!
Posted
but because there is no 'SELECT DISTINCT' on a dataset - least not that I'm aware of, so I need to seperate the chapters into its own table to reduce duplication.

 

You can achieve this by setting the Unique property of the column to TRUE:

 

myDS.Tables(0).Columns(0).Unique = True

 

This will prevent duplicate values from being added to a column. Be aware that if you try to add a duplicate value to a column an exception is thrown. You just need to handle it gracefully and keep processing.

Posted (edited)

I am aware of this, the problem was that this was a composite key table, not a single key so in the below schema it would be perfectly valid to have a duplicate BookID or Chapter but not a duplicate BookID-Chapter combination:

 

BookID : Chapter

-------------------------

1 : 1 'Valid Composite Key 'even though there is a book 1 elsewhere

1 : 2 'Valld Composite Key

1 : 3 'Valid Composite Key

2 : 1 'Valid Composite Key - even though there is a chapter 1 elsewhere

2 : 2 'Valid Composite Key

2 : 1 'Inalid Composite Key - the combination of 2-1 already exists.

BibleDemo.zip

Edited by bri189a
Posted

Simple Demo

 

Okay Mark, this is a buggy (not too bad considering I wrote it in 30 minutes) Console app demo that goes over some of the important functionallity of strongly typed datasets, haven't done the search yet, but this should give you quite a bit to chew on for some time until I can get around to how to do a search (similiar to how I find the books). You need to put the Bible.xml file in your C:\ root drive or change the code in the application to the correct path.

 

Hope this helps you.

BibleDemo.zip

Posted

Its giving an error but not one I dont think can be fixed...

 

Its saying simply Bible is not defined which usually means I think I need to refference something....

 

Do I need to

IMports System.IO or xml or something like that?

 

vbMarkO

Visual Basic 2008 Express Edition!
Posted
What you need to do is open the Bible.xsd file in the IDE. Right click (in the yellow area - where there is no text) and uncheck 'Generate Dataset' by clicking on that menu option if it is checked. If it is not continue with the next step. Next right click and check 'Generate Dataset' by clicking on that menu option. This is the function that actually builds the vb file (class) which is what we call the functions from.
Posted (edited)

Ok,

 

It started to run this time but stopped with an error at dsBible.Merge(ds)

 

 

 

vbMarkO

Edited by vbMarkO
Visual Basic 2008 Express Edition!
Posted

Interesting, I have no errors - if you set a break point on the dsBible.Merge(ds) line, in the Immediate window type

 

?ds.Tables(0).Rows.Count

 

You should get 66 or something close (as long as it's not zero) - do you get this? Do the same for ds.Tables(1).Rows.Count and ds.Tables(2).Rows.Count, none should have 0 records. What is the exact error?

Posted
Mark, make sure you're using the attached XML file as your 'source' too - you may be getting that error because of the original XML file I sent in ealier attachments from last week that don't have the same schema.

Bible.zip

Posted

It worked once I deleted the Bible.xml and replaced it with this one.

 

Pretty Cool!

 

To call specific chapter like that is neat, this is the first tme I actually used the console like that.

 

But tell me, is the response supposed to be slow like that?

Or is it only slow bcause you are using the console? Perhaps it is faster with an rtb, or textbox to return the chapter search? Right?

 

vbMarkO

Visual Basic 2008 Express Edition!
Posted
The only thing that should take any time is loading the bible because it's such a large file - it take about 1 second on my computer but I have a Pentium 4 on a 800FSB with 1 GB of ram - so if you're on an older computer it might take a little longer - past that though everything is 'in-memory' so it's as fast as it can possibily be on a particular computer (my computer it has no delay what-so-ever). It would definitely be faster than doing it with a flat file because that would require I/O to the hard disk; again the only place this is present is when loading the bible xml file. I'm glad you like it and I hope it can help you in your efforts. If you need help with anything else let me know.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...