vbMarkO Posted September 27, 2005 Posted September 27, 2005 I have findly got my Tool I have created to help automate the task of converting text in text files where the text looks like this 1:1: In the begining was VB 1:2: and they saw it was good 2:1: blah blah blah blah 2:2: more text on this line and so on '/// Hehe couldnt help myse;lf ...ofcourse the text is actual scripture :) anyway Its being converted in an RTB to look like this 1:1 Line of Text ' Note each chapter ofcourse has a diferent number of verses 2 Line of Text 2:1 Line of Text 2 Line of Text 3 Line of Text Now this brings us to what I need I need to be able in a button click to take the final result you see above and add this to it [center][color=Blue][size=5][b]John 1[/b][/size][/color][/center] [color=Blue]1:1[/color] Line of Text which is scripture NOTE actual text will span ful length of page the above headers are center page [color=Blue] 1[/color] more text here [color=Blue] 2[/color] more text [center]' Note this blank line[/center] [center][color=Blue][size=5][b]John 2[/b][/size][/color][/center] [color=Blue]2:1[/color] more text [color=Blue] 2[/color] more text [color=Blue] 3[/color] more text [center][color=Blue][size=5][b]John 3[/b][/size][/color][/center] [color=Blue]3:1[/color] more text [color=Blue] 2[/color] more text So as you can see I need to be able to do the following 1. determine right where the last verse is or start of next chapter so that it will enter a a. Blank line b. CHapter Header ie John 1 c. Change its Font to rtbText.SeletionFont = New Font("Arial", 22, rtb.fontstyle.Bold) ' I know this is not eact but the idea is right d. Then another blank line belwo the header 2. determine next chapterstart and so on ect ect ect Also, it will need to turn all Numbers within the text to Blue NOTE all scripture text is to remain Black or Normal I know what I am asking is no easy task or at least I dont think it is I have been trying for days to figure out how to change all numbers to Blue and how to add the chapter headers SO here I am again to ask to PLEASE HELP :) point me in the right direction at least anything that might shed some light is much appreciated vbMarKO Quote Visual Basic 2008 Express Edition!
Nate Bross Posted September 28, 2005 Posted September 28, 2005 Try this you will need to customize it somewhat and I am at school now and cannot compile and test this code on your sample text; however, you should be able to fix any errors I have made. 'Assuming all the text is already formated in the tb. 'Untested code, but you get the idea... Public Function InsertBoldTitles(byref rtb as RichTextBox) as Boolean Dim wv as String = rtb.Text Dim wa() as String Dim CurrentChapter as Integer Dim i as Long wa = rtb.Text.Split(Environment.NewLine) rtb.Clear() For i = lbound(wa) to ubound(wa) If wa(i).ToString.StartsWith(CurrentChapter) Then 'Just append the text rtb.SelectionStart = rtb.TextLength rtb.SelectionText = wa(i).ToString() & Environment.NewLine ElseIf wa(i).ToString.StartsWith(CurrentChapter + 1) Then 'Increment Chapter CurrentChapter += 1 'Make the large blue title rtb.SelectionStart = rtb.TextLength rtb.SelectionColor = Color.Blue rtb.SelectionFont = New Font("Times New Roman",22, Style.Bold) rtb.SelelectionText = "John" & Environment.NewLine 'Begin writing out the next chapter rtb.SelectionColor = Color.Black rtb.SelectionFont = New Font("Times New Roman",12) rtb.SelectionText = wa(i).ToString() & Environment.NewLine End If Next i End Function Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
vbMarkO Posted September 28, 2005 Author Posted September 28, 2005 Sorry I did not realize you had responded I forgot to subscribe to this thread. Anyway, I have run your code, you were right I did have to make some changes, just a few. Such as style.bold to FontStyle.Bold SelectionText to SelectedText Results if my changes didnt mess things up was this It adds 1 John oh yeah I changed it to 1 John since that was the text I was testing it on. Anyway, 1 John is added to the begining of the Book uh at the top but it did not increment or even place the word 1 John before any of the other chapters but looking at your code I sort of see what you have done... Splitting the lines or text into an array The only thing is I cant figure out how it can distinguish between chapter 1:1 Line of Text and 2:2 Line of text Unless, this If wa(i).ToString.StartsWith(CurrentChapter) Then the starts with takes just the 1 of the 1:1 Line of Text Not sure I havent debuged it yet see exactly how it is splitting it yet... Anyway Any ideas? vbMarkO Quote Visual Basic 2008 Express Edition!
Leaders dynamic_sysop Posted September 28, 2005 Leaders Posted September 28, 2005 try the PARAFORMAT2 Structure the bits you want for your spacing are ... dySpaceBefore Size of the spacing above the paragraph, in twips. To use this member, set the PFM_SPACEBEFORE flag in the dwMask member. The value must be greater than or equal to zero. dySpaceAfter Specifies the size of the spacing below the paragraph, in twips. To use this member, set the PFM_SPACEAFTER flag in the dwMask member. The value must be greater than or equal to zero. dyLineSpacing Spacing between lines. For a description of how this value is interpreted, see the bLineSpacingRule member. To use this member, set the PFM_LINESPACING flag in the dwMask member. my translation ( which you can find in a previous post from a couple of weeks ago if you do a forum search for post with my name ) of the structure is ... <StructLayout(LayoutKind.Sequential)> _ Public Structure PARAFORMAT2 Public cbSize As Int32 Public dwMask As Int32 Public wNumbering As Int16 Public wReserved As Int16 Public dxStartIndent As IntPtr Public dxRightIndent As IntPtr Public dxOffset As IntPtr Public wAlignment As Int16 Public cTabCount AsShort <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _ Public rgxTabs() As IntPtr Public dySpaceBefore As IntPtr Public dySpaceAfter As IntPtr Public dyLineSpacing As IntPtr Public sStyle AsShort Public bLineSpacingRule AsByte Public bOutlineLevel AsByte Public wShadingWeight As Int16 Public wShadingStyle As Int16 Public wNumberingStart As Int16 Public wNumberingStyle As Int16 Public wNumberingTab As Int16 Public wBorderSpace As Int16 Public wBorderWidth As Int16 Public wBorders As Int16 End Structure you can also align your paragraphs etc... with this struct. Quote
vbMarkO Posted September 28, 2005 Author Posted September 28, 2005 UPDATE I made another change Debugging it I saw that it wasnt truely splitting the lines of text into the array so I changed this ' wa = rtb.Text.Split(vbCrLf) <----- YOUR LINE ' changed it to whats below it now splits it into the array each element consist of one line of text Dim myString As String For Each line As String In rtb.Lines myString = myString & line & vbCrLf wa = Split(myString, vbCrLf) ReDim Preserve wa(0 To UBound(wa)) Next RESULT Now its adding 1 John after every verse like this 1 John 1:1 Line of Text 1 John 2 Line of Text and so on ect ect ect But hey way cool I can now at least see its headed the right direction vbMarkO Quote Visual Basic 2008 Express Edition!
vbMarkO Posted September 28, 2005 Author Posted September 28, 2005 Update again Ok I got really excited about this because I now have it so that it finds each chapter it placed 1 John and also adds the chapter number ie; 1 John 2 or 1 John 3 and so on and increments where it suppsed to and places these chapters headers right before each chapter One major problem though LOL all the scriptures in between have now went by by But hey it was exciting to see it sort of worked LOL Here is the code all of it so you can see what I am doing worng LOL Dim wv As String = rtb.Text Dim wa() As String Dim CurrentChapter As String Dim i As Long Dim myString As String For Each line As String In rtb.Lines myString = myString & line & vbCrLf wa = Split(myString, vbCrLf) ReDim Preserve wa(0 To UBound(wa)) Next 'wa = rtb.Text.Split(vbCrLf) rtb.Clear() Dim ix As Integer ix = 1 ' To increment the chapters CurrentChapter = ":1" ' To pint tothe specific chapter so they can be found For i = LBound(wa) To UBound(wa) If wa(i).ToString.StartsWith(ix & CurrentChapter) Then 'Just append the text rtb.SelectionFont = New Font("Arial", 12, FontStyle.Bold) rtb.SelectionStart = rtb.TextLength rtb.SelectedText = wa(i).ToString() & Environment.NewLine ElseIf wa(i).ToString.StartsWith(ix + 1 & CurrentChapter) Then 'Increment Chapter ix += 1 'CurrentChapter += 1 'Make the large blue title rtb.SelectionStart = rtb.TextLength rtb.SelectionColor = Color.Blue rtb.SelectionFont = New Font("Arial", 22, FontStyle.Bold) rtb.SelectionAlignment = HorizontalAlignment.Center rtb.SelectedText = "1 John " & ix & Environment.NewLine 'Begin writing out the next chapter rtb.SelectionColor = Color.Black rtb.SelectionFont = New Font("Arial", 12, FontStyle.Bold) rtb.SelectedText = wa(i).ToString() & Environment.NewLine End If Next i Ok, I am probably not fixing this or even heading the right direction but I am giving it a good go dont you think ? :) Just the same it does find the chapters properly now and places the chapter headers right where they are suppsoed to be LOL it just leaves of the first chapters header 1 John 1 and all the scriptures in between each chapter but this is looking like we are heading the right direction vbMarkO Quote Visual Basic 2008 Express Edition!
Nate Bross Posted September 28, 2005 Posted September 28, 2005 Could you post the output, or an abreviated form of the actual output? Also, what is the format of your input? Chapter#:Verse# Verse Text? Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted September 28, 2005 Posted September 28, 2005 On second thought, if you could provide a real sample of input data, along with the actual output data of the function above that would be very useful in debuging. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
vbMarkO Posted September 28, 2005 Author Posted September 28, 2005 Here is the Text that is in the rtb its is between the dashed lines -------------------------------------------------------------------------- 1 John 1 1:1 That which was from the beginning, which we have heard, which we have seen with our eyes, which we have looked upon, and our hands have handled, of the Word of life; 2 (For the life was manifested, and we have seen it, and bear witness, and shew unto you that eternal life, which was with the Father, and was manifested unto us;) 3 That which we have seen and heard declare we unto you, that ye also may have fellowship with us: and truly our fellowship is with the Father, and with his Son Jesus Christ. 4 And these things write we unto you, that your joy may be full. 5 This then is the message which we have heard of him, and declare unto you, that God is light, and in him is no darkness at all. 6 If we say that we have fellowship with him, and walk in darkness, we lie, and do not the truth: 7 But if we walk in the light, as he is in the light, we have fellowship one with another, and the blood of Jesus Christ his Son cleanseth us from all sin. 8 If we say that we have no sin, we deceive ourselves, and the truth is not in us. 9 If we confess our sins, he is faithful and just to forgive us our sins, and to cleanse us from all unrighteousness. 10 If we say that we have not sinned, we make him a liar, and his word is not in us. 2:1 My little children, these things write I unto you, that ye sin not. And if any man sin, we have an advocate with the Father, Jesus Christ the righteous: 2 And he is the propitiation for our sins: and not for ours only, but also for the sins of the whole world. 3 And hereby we do know that we know him, if we keep his commandments. 4 He that saith, I know him, and keepeth not his commandments, is a liar, and the truth is not in him. 5 But whoso keepeth his word, in him verily is the love of God perfected: hereby know we that we are in him. 6 He that saith he abideth in him ought himself also so to walk, even as he walked. 7 Brethren, I write no new commandment unto you, but an old commandment which ye had from the beginning. The old commandment is the word which ye have heard from the beginning. 8 Again, a new commandment I write unto you, which thing is true in him and in you: because the darkness is past, and the true light now shineth. 9 He that saith he is in the light, and hateth his brother, is in darkness even until now. 10 He that loveth his brother abideth in the light, and there is none occasion of stumbling in him. 11 But he that hateth his brother is in darkness, and walketh in darkness, and knoweth not whither he goeth, because that darkness hath blinded his eyes. 12 I write unto you, little children, because your sins are forgiven you for his name's sake. 13 I write unto you, fathers, because ye have known him that is from the beginning. I write unto you, young men, because ye have overcome the wicked one. I write unto you, little children, because ye have known the Father. 14 I have written unto you, fathers, because ye have known him that is from the beginning. I have written unto you, young men, because ye are strong, and the word of God abideth in you, and ye have overcome the wicked one. 15 Love not the world, neither the things that are in the world. If any man love the world, the love of the Father is not in him. 16 For all that is in the world, the lust of the flesh, and the lust of the eyes, and the pride of life, is not of the Father, but is of the world. 17 And the world passeth away, and the lust thereof: but he that doeth the will of God abideth for ever. 18 Little children, it is the last time: and as ye have heard that antichrist shall come, even now are there many antichrists; whereby we know that it is the last time. 19 They went out from us, but they were not of us; for if they had been of us, they would no doubt have continued with us: but they went out, that they might be made manifest that they were not all of us. 20 But ye have an unction from the Holy One, and ye know all things. 21 I have not written unto you because ye know not the truth, but because ye know it, and that no lie is of the truth. 22 Who is a liar but he that denieth that Jesus is the Christ? He is antichrist, that denieth the Father and the Son. 23 Whosoever denieth the Son, the same hath not the Father: (but) he that acknowledgeth the Son hath the Father also. 24 Let that therefore abide in you, which ye have heard from the beginning. If that which ye have heard from the beginning shall remain in you, ye also shall continue in the Son, and in the Father. 25 And this is the promise that he hath promised us, even eternal life. 26 These things have I written unto you concerning them that seduce you. 27 But the anointing which ye have received of him abideth in you, and ye need not that any man teach you: but as the same anointing teacheth you of all things, and is truth, and is no lie, and even as it hath taught you, ye shall abide in him. 28 And now, little children, abide in him; that, when he shall appear, we may have confidence, and not be ashamed before him at his coming. 29 If ye know that he is righteous, ye know that every one that doeth righteousness is born of him. 3:1 Behold, what manner of love the Father hath bestowed upon us, that we should be called the sons of God: therefore the world knoweth us not, because it knew him not. 2 Beloved, now are we the sons of God, and it doth not yet appear what we shall be: but we know that, when he shall appear, we shall be like him; for we shall see him as he is. 3 And every man that hath this hope in him purifieth himself, even as he is pure. 4 Whosoever committeth sin transgresseth also the law: for sin is the transgression of the law. 5 And ye know that he was manifested to take away our sins; and in him is no sin. 6 Whosoever abideth in him sinneth not: whosoever sinneth hath not seen him, neither known him. 7 Little children, let no man deceive you: he that doeth righteousness is righteous, even as he is righteous. 8 He that committeth sin is of the devil; for the devil sinneth from the beginning. For this purpose the Son of God was manifested, that he might destroy the works of the devil. 9 Whosoever is born of God doth not commit sin; for his seed remaineth in him: and he cannot sin, because he is born of God. 10 In this the children of God are manifest, and the children of the devil: whosoever doeth not righteousness is not of God, neither he that loveth not his brother. 11 For this is the message that ye heard from the beginning, that we should love one another. 12 Not as Cain, who was of that wicked one, and slew his brother. And wherefore slew he him? Because his own works were evil, and his brother's righteous. 13 Marvel not, my brethren, if the world hate you. 14 We know that we have passed from death unto life, because we love the brethren. He that loveth not his brother abideth in death. 15 Whosoever hateth his brother is a murderer: and ye know that no murderer hath eternal life abiding in him. 16 Hereby perceive we the love of God, because he laid down his life for us: and we ought to lay down our lives for the brethren. 17 But whoso hath this world's good, and seeth his brother have need, and shutteth up his bowels of compassion from him, how dwelleth the love of God in him? 18 My little children, let us not love in word, neither in tongue; but in deed and in truth. 19 And hereby we know that we are of the truth, and shall assure our hearts before him. 20 For if our heart condemn us, God is greater than our heart, and knoweth all things. 21 Beloved, if our heart condemn us not, then have we confidence toward God. 22 And whatsoever we ask, we receive of him, because we keep his commandments, and do those things that are pleasing in his sight. 23 And this is his commandment, That we should believe on the name of his Son Jesus Christ, and love one another, as he gave us commandment. 24 And he that keepeth his commandments dwelleth in him, and he in him. And hereby we know that he abideth in us, by the Spirit which he hath given us. --------------------------------------------------------------------------- The above represents the Book of 1 John the text above is exactly what is in my rtb with one exception that is the chapter header at the top ie; 1 John 1 is much bigger font size 22 to be exact and is Bold and Blue and centered. before it was this the text would begin with something like this 1:1: Then scripture text 1:2: more scipture text 2:1: new chapter and scripture text 2:2: more text I converted this text from a text file to be as you see above between the dashed lines like this 1:1 Scipture text 2 scripture text 3 scrip text 2:1 text lines 2 I think you get the idea vbMarkO P.S. it wouldnt let me post the entire text body above so I knocked a chaptr or 2 off but then that shouldnt matter because each book of the bible is different sizes some are only one chapter Quote Visual Basic 2008 Express Edition!
Nate Bross Posted September 29, 2005 Posted September 29, 2005 Is it necessary to be converted to the second form? It is much easier programatically to take care of it in the 1:1: Then scripture text 1:2: more scipture text 2:1: new chapter and scripture text 2:2: more text form. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
vbMarkO Posted September 29, 2005 Author Posted September 29, 2005 Well let me say this, If we could take this form here 1:1: Text 1:2: Text 2:1: Text 2:2: Text 2:3: Text and make it this John 1 1:1: Text 1:2: Text John 2 2:1: Text 2:2: Text 2:3: Text If that will simplify things I could deal with that. The code I have writen for the other conversion will not be effected by that it will still take it where I need it to go. Truth is I dont know why I didnt think of that in the first place... but still I am not quite sure how to get even this to work exactly right so if you wish to try it the other way I would certainly be interested in seeing what you have in mind. vbMarkO Quote Visual Basic 2008 Express Edition!
vbMarkO Posted September 29, 2005 Author Posted September 29, 2005 On second thought I went and tried this out and gave it a run through. To place the chapter headers in place when the text is in this form 1:1: Text 1:2: Text 2:1: Text 2:2: Text This will not work.... what happens after they are entered and run through my program it puts the text backtogether but it will not leave the chapter headers in place... I didnt account for them as they simply were not there. I actually figured a way of doing this, I just dont know hwo to implement it. It might not be efficient but it sounds like a fix.... Ill shoot it past you see what you think first find chapter 2 somthing like this sectionStart = rtb.Find("2:1", RichTextBoxFinds.None) sectionEnd = Len(rtb.Text) Not sure this is right but the idea would be to start at chapter 2 and select all the text from chap 2 to length of text or end. Then Copy to Clipboard and cut the text from the RTB. Then rtb.Text = rtb.Text & vbCrLf & vbCrLf & "1 John" & ix & vbCrLf & vbCrLf & ClipboardContents Then sectionStart = rtb.Find("3:1", RichTextBoxFinds.None) sectionEnd = Len(rtb.Text) Repeat the process until done or reach Ubound(myChap) so when it has completed unitl last chapter What do you think? Theres just one question that would remain then, How do you select all of that text??? I have searched all over and most examples find one line or a phrase or a word search but nothing of a block of text. vbMarkO Quote Visual Basic 2008 Express Edition!
Nate Bross Posted September 30, 2005 Posted September 30, 2005 Okay, the function below will work with this input. 1:1: Text 1:2: Text 2:1: Text 2:2: Text 2:3: Text Public Function ProessRTB(rtb as RichTextBox) as Boolean Dim wv As String = rtb.Text Dim wa() As String Dim CurrentChapter As Integer = 0 Dim i As Long Dim myString As String For Each line As String In rtb.Lines myString = myString & line & vbCrLf wa = Split(myString, vbCrLf) ReDim Preserve wa(UBound(wa)) Next 'wa = rtb.Text.Split(vbCrLf ) rtb.Clear() Dim ix As Integer ix = 0 ' To increment the chapters For i = LBound(wa) To UBound(wa) CurrentChapter += 1 If wa(i).ToString.StartsWith(ix & ":" & CurrentChapter) Then 'Just append the text rtb.SelectionFont = New Font("Arial", 12, FontStyle.Bold) rtb.SelectionStart = rtb.TextLength rtb.SelectedText = wa(i).ToString() & Environment.NewLine ElseIf wa(i).ToString.StartsWith(ix + 1 & ":" & CurrentChapter) Or wa(i).ToString.StartsWith(ix + 1 & ":" & 1) Then 'Increment Chapter ix += 1 CurrentChapter = 1 'Make the large blue title rtb.SelectionStart = rtb.TextLength rtb.SelectionColor = Color.Blue rtb.SelectionFont = New Font("Arial", 22, FontStyle.Bold) rtb.SelectionAlignment = HorizontalAlignment.Center rtb.SelectedText = "1 John " & ix & Environment.NewLine 'Begin writing out the next chapter rtb.SelectionColor = Color.Black rtb.SelectionFont = New Font("Arial", 12, FontStyle.Bold) rtb.SelectedText = wa(i).ToString() & Environment.NewLine End If Next i End Function Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
vbMarkO Posted September 30, 2005 Author Posted September 30, 2005 Oh wow, I will certainly give this some study tomorrow.... I tested it and it worke great... I will see how I can exapand it to the final stage Thank you for your great input and effort in this endeavour vbMarkO Quote Visual Basic 2008 Express Edition!
Nate Bross Posted September 30, 2005 Posted September 30, 2005 Not a problem at all, I'm glad I was able to help you out. Let me know if you have any problems with it tomorrow. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
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.