vbMarkO Posted August 23, 2005 Posted August 23, 2005 (edited) Ok, Here is a textfile a part of a Bible section to show as an example how this looks in my text file... I need to read the line I choose based on the scripture address I suppose some how I would use the : as delimeters truthfully not sure how to tackle this one TEXTFILE looks like this ' USING VB CODE WINDOW TO MAKE THIS LOOK CLEANER FOR BETTER ILLUSTRATION ST. MATTHEW 1:1: The book of the generation of Jesus Christ, the son of David, the son of Abraham. 1:2: Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judas and his brethren; 1:3: And Judas begat Phares and Zara of Thamar; and Phares begat Esrom; and Esrom begat Aram; 1:4: And Aram begat Aminadab; and Aminadab begat Naasson; and Naasson begat Salmon; 1:5: And Salmon begat Booz of Rachab; and Booz begat Obed of Ruth; and Obed begat Jesse; 1:6: And Jesse begat David the king; and David the king begat Solomon of her that had been the wife of Urias; 1:7: And Solomon begat Roboam; and Roboam begat Abia; and Abia begat Asa; 1:8: And Asa begat Josaphat; and Josaphat begat Joram; and Joram begat Ozias; 1:9: And Ozias begat Joatham; and Joatham begat Achaz; and Achaz begat Ezekias; 1:10: And Ezekias begat Manasses; and Manasses begat Amon; and Amon begat Josias; ST.MARK 1:1: The beginning of the gospel of Jesus Christ, the Son of God; 1:2: As it is written in the prophets, Behold, I send my messenger before thy face, which shall prepare thy way before thee. 1:3: The voice of one crying in the wilderness, Prepare ye the way of the Lord, make his paths straight. 1:4: John did baptize in the wilderness, and preach the baptism of repentance for the remission of sins. 1:5: And there went out unto him all the land of Judaea, and they of Jerusalem, and were all baptized of him in the river of Jordan, confessing their sins. 1:6: And John was clothed with camel's hair, and with a girdle of a skin about his loins; and he did eat locusts and wild honey; 1:7: And preached, saying, There cometh one mightier than I after me, the latchet of whose shoes I am not worthy to stoop down and unloose. 1:8: I indeed have baptized you with water: but he shall baptize you with the Holy Ghost. 1:9: And it came to pass in those days, that Jesus came from Nazareth of Galilee, and was baptized of John in Jordan. '///// NOTE: As you can see above each time it comes to a New Book ie St. Matthew or St. Mark should one of these for ' example is what the users is wanting to search for then it should only search for the IndexOf Chapter number and Verse ' Number ie; 1:8: within the chapter and verses imediately following the book requested. ' I am stumped on this one... I figured out how I could add each line to an arrayList then use IndexOf BUT I cant figure out ' how to make it search for chapter and verse within chapter and verse numbers for just that particular BOOK So How can I get it to loop through find the Book then search through the following chapters and verses to bring up the specifc line the user has asked for vbMarkO Edited August 23, 2005 by vbMarkO Quote Visual Basic 2008 Express Edition!
Machaira Posted August 23, 2005 Posted August 23, 2005 One way: Read each line, if the first character is not numeric and has text in it, it's probably a book header, check to see if this text to be searched for is in the line (use the IndexOf String function) if it is set a flag to start finding the chapter and verse as you continue reading line by line. Quote Here's what I'm up to.
vbMarkO Posted August 23, 2005 Author Posted August 23, 2005 (edited) Yes I have updated my request above to be more specific... the IndexOf I am sure is the way to go but as you can see from my edit above I am not sure hot implement it Do you have an example or know of one I might see? vbMarkO Edited August 23, 2005 by vbMarkO Quote Visual Basic 2008 Express Edition!
vbMarkO Posted August 23, 2005 Author Posted August 23, 2005 OK here is the code I have so far. FIrst though what I did was separate the Books to individual text files called Matthew.txt Mark.txt Luke.txt John.txt and so on ect ect ect I have it so when the book is selected from a ComboBox it will then add the contents fo the text file to an array.... As you will see in my Code however I still dont know how to get the certain IndexOf the array to that of the chapter and verse such as 1:5: or 2:3: as examples Here is my code anyone know what to do from here? Dim frPath As String = "C:\Program Files\Dove Media\" frPath = frPath & scripCombo.Text & ".txt" Dim scripture() As String Dim strText As String Try If File.Exists(frPath) Then Dim strRead As StreamReader = File.OpenText(frPath) strText = strRead.ReadToEnd() scripture = Split(strText, vbCrLf) ' Here the array is filled with eachline be added to a new capartment of the array ' At least I am hoping it does havent tested this yet but I wll ' just need to know how to now access the specific user requested line or indexOf End If Catch End Try Help much appreciated vbMarkO Quote Visual Basic 2008 Express Edition!
SonicBoomAu Posted August 23, 2005 Posted August 23, 2005 I don't know if this is what you are after, but it might give you some Ideas. http://www.xtremedotnettalk.com/showthread.php?t=91766 I use this to populate my combobox's from a text file. Dim sr As StreamReader = File.OpenText(strFullDBConfigLoc) Dim input As String = vbNullString Try Do input = sr.ReadLine() Loop Until input = "[WING]" Do input = sr.ReadLine() Me.cboWings.Items.Add(input) Loop Until input = vbNullString Catch ex As ArgumentNullException ' Do nothing Catch ex As Exception MessageBox.Show("Error: " & ex.Message) Finally sr.Close() End Try What it basically does is reads each line until it finds the line [WING]. It then reads and adds each line under it to the combobox until it hits a blank line. Hope this helps Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
vbMarkO Posted August 24, 2005 Author Posted August 24, 2005 I figured out how to do it. Here is the Code I finally came up with. Thank you for your sugestions however. Dim frPath As String = "C:\Program Files\Dove Media\" frPath = frPath & scripCombo.Text & ".txt" Dim scripture() As String Dim strText As String Try If File.Exists(frPath) Then Dim strRead As StreamReader = File.OpenText(frPath) strText = strRead.ReadToEnd() scripture = Split(strText, vbCrLf) Else MsgBox("File isnt there") End If Catch End Try Dim strChap As String Dim strVerse As String Dim strChapVerse As String strChap = chapText.Text strVerse = verseText.Text strChapVerse = strChap & ":" & strVerse & ":" Dim i As Integer For i = 0 To UBound(scripture) If scripture(i).StartsWith(strChapVerse) Then ' This is the code line that gets it done scripText.Text = scripture(i) End If ' TODO: Write Code so User can display in another TextDisplayBox the remaining chapter ' from users Chapter & Verse Search String Next vbMarkO Quote Visual Basic 2008 Express Edition!
bri189a Posted August 24, 2005 Posted August 24, 2005 Instead of using a text file why don't you create a dataset with table relationships and then export the dataset to file, and read from file when you're app loads. Since it appears you don't want to use a database, a dataset would at least give you the quick indexing and look ups. Quote
vbMarkO Posted August 24, 2005 Author Posted August 24, 2005 hmmm a Dataset..... this sounds interesting.... Now if I could create this Dataset and not have to rewrite out all the scriptures I would be of interest However, If I could populate the dataset from the text file that already exist then this might be of interest. However, the problem remains.... I have never done anything with a Dataset so I am not sure where to start with that vbMarkO Quote Visual Basic 2008 Express Edition!
Machaira Posted August 25, 2005 Posted August 25, 2005 You can easily populate a dataset from the text file. You simply read each line as you're doing, create a new datarow, populate the fields and add the datarow to the dataset. The book name, chapter, and verse would be indexed to all searching. There are tons of tutorials for working with datasets out there. Read a couple and you should be ready to go. Quote Here's what I'm up to.
vbMarkO Posted September 7, 2005 Author Posted September 7, 2005 You can easily populate a dataset from the text file. You simply read each line as you're doing, create a new datarow, populate the fields and add the datarow to the dataset. The book name, chapter, and verse would be indexed to all searching. There are tons of tutorials for working with datasets out there. Read a couple and you should be ready to go. Well you know how it is, there tons of tutorials out there on the subject until its the subject you need info on then they seem to hide int he cracks LOL. I did find a tutorial to take me through the steps of creating a dataset.... and I did but once I had created this beautiful first dataset thats were the tutorial ended :( It didnt show me how to Populate it from the textfile I can say this I am very interested in trying this because as you know Textfiles are painfully slow at times especially the bigger ones Like the book of Psalms OUCH I think I may have had time to quickly make a sandwich and grab a soda LOL ok maybe thats an exageration but it was slow and I am in hopes the Dataset idea might produce a little more speed. So, I return with the question, using the Text Files as they are could one show me an example of how to populate it? The text file data looks like this within the text file ST. MATTHEW 1:1: The book of the generation of Jesus Christ, the son of David, the son of Abraham. 1:2: Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judas and his brethren; 1:3: And Judas begat Phares and Zara of Thamar; and Phares begat Esrom; and Esrom begat Aram; 1:4: And Aram begat Aminadab; and Aminadab begat Naasson; and Naasson begat Salmon; 1:5: And Salmon begat Booz of Rachab; and Booz begat Obed of Ruth; and Obed begat Jesse; 1:6: And Jesse begat David the king; and David the king begat Solomon of her that had been the wife of Urias; 1:7: And Solomon begat Roboam; and Roboam begat Abia; and Abia begat Asa; 1:8: And Asa begat Josaphat; and Josaphat begat Joram; and Joram begat Ozias; 1:9: And Ozias begat Joatham; and Joatham begat Achaz; and Achaz begat Ezekias; 1:10: And Ezekias begat Manasses; and Manasses begat Amon; and Amon begat Josias; vbMarkO Quote Visual Basic 2008 Express Edition!
bri189a Posted September 8, 2005 Posted September 8, 2005 Let's assume the dataset looks like this Book -------- ID - Integer (Primary Key - Auto Generated) Name - String BookContents -------------- ID - Integer (Primary Key, Auto Generated) Book - Integer (relates back to 'Book') Chapter - Integer Verse - Integer Text - String Now go through each line of the text file - I assume you know how to do that. Then break the line into a string array: Dim s as String() = LineOfText.Split(":"c, 3) The 3 signifies the maximum number of items to return is 3 - mean that the first item in the array will be the chapter, the second item will be the verse, and the third will be the text. Now I also assume your using a strongly typed dataset. So from here you simply: Bible.BookContents.AddNewBookContentsRow(book, s(0), s(1), s(2)) book represents the 'Book' row that you should already have. I hope this at least points you in the right direction. Quote
vbMarkO Posted September 8, 2005 Author Posted September 8, 2005 Respectfully No, I will keep searching I have been looking for hours, I have found how to populate a DataSet from XML and many other examples but none really apply it to what I am doing or even a close simularity so I might adapt it to my application. I am sure somewhere there has got to be an example of how to populate the Dataset.... Or even an example forth coming that might show how to put one together for a example to learn by or build on. Thanx for the sugestion, we will endeavour to keep looking vbMarkO Quote Visual Basic 2008 Express Edition!
bri189a Posted September 8, 2005 Posted September 8, 2005 Zip up your dataset and your method for reading the text file and post it. When I have a change later this week or this weekend I'll throw it together for you. I'll need a text file that has some of the data in it too to make sure it works....in fact just zip you whole project and post it with some test data. Shouldn't take me long, just have to have the time to do it. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.