Results 1 to 29 of 29

Thread: Changing text in textbox once something is erased

  1. #1

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Changing text in textbox once something is erased

    Hi all,

    I'm making a Notetaking program that makes it faster for writing notes on the computer. It will add Roman Numerals and Upper Case Letters, Lower Case, ect.

    However, my problem is when I put say three roman numerals into the textbox

    I.

    II.

    III.

    And I erase all three, and put anothe roman numeral in, it will put roman numeral four in (IV) How could I make it so it checks to see what roman numeral is in the textbox and then enters the next one up?

    So if I have I. II. III. in the textbox and erase II. and III. it will enter a II.

    Sorry if you have a hard time understand this

    I have also attached my project so you can maybe take a look at it
    Attached Files Attached Files

  2. #2

  3. #3

  4. #4

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Changing text in textbox once something is erased

    Quote Originally Posted by MartinLiss
    Your project is looking for a password for the vbp file.
    It's not letting you open the project?

  5. #5

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Changing text in textbox once something is erased

    Quote Originally Posted by RhinoBull
    You can declare some global integer counter and then convert arabic number to roman numeral. Have a fun.
    thanks for the code rhino, but I still havn't figured out a way to search the textbox and figure out what roman numerals are in the textbox, so then the next roman numeral that is added is in coordination with the rest already entered.

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing text in textbox once something is erased

    Quote Originally Posted by paralinx
    It's not letting you open the project?
    I swear the 1st time I tried to open the project it wanted a password for the vbp file and when I didn't supply one it deleted the vbp file! Very strange. In any case I downloaded it again and the only thing I can suggest is that instead of generating the roman numerals that you create a type like this

    VB Code:
    1. Private Type RomanNumerals
    2.     rnRoman As String
    3.     rnUsed As Boolean
    4. End Type
    5. Private Romans(99) As RomanNumerals
    and then load it with the 1st hundred(?) roman numerals setting all the rnUsed flags to False. Then of course you can examine the array for the first one that's not used and when deleting one from your note you would set the associated array member to False.

  7. #7

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Changing text in textbox once something is erased

    Good idea Martin, thanks. But how could I figure out what roman numerals were erased if the textbox has something like this in it..

    Code:
    I. Blah blah blah blah
    	A. blah blah blah blah
    	B. blah
    		-blah blah
    		-blah bleh?
    II. Bleh blah blah
    	A. Blah 
    III. Hey more blah
    	a. you want some more blah? 
    	b. because I sure do
    It would be hard to tell when a roman numeral was taken out. Unless there was some way I could search for all roman numerals

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Changing text in textbox once something is erased

    You'd need to scan your text constantly - timer comes to mind first...
    If "I" is found then search for "II" and so on ... InStr() may work but the problem is that you may have refences somewhere in the paragraph (say VI) to another paragraph (some like "...see par IV for more info ...) and that could still be there. So, InStr will return true and indexing will be out of bounds.

  9. #9

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Changing text in textbox once something is erased

    Well that may not be a problem. Because after every roman numeral I have my program insert a ".", I could just search "I."

    But good idea rhino, I'll give this a try.

  10. #10

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing text in textbox once something is erased

    Is it also true that there will never be any text to the left of the roman numeral? If so then that's a test you could use to determine what's there. That would also help you avoid things like "My favorite king is George V."

  12. #12

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Changing text in textbox once something is erased

    There can be text before the roman numerals.

    I tried searching for the roman numerals your way rhino but it does not work. It will get to roman numeral two and continue putting in Roman Numeral twos.

    Heres my code

    VB Code:
    1. Dim sRev As String, sRom As String, sArr() As String
    2.     Dim iNext As Integer, i As Integer, RomanAmt As Integer
    3.     sRev = txtDesign.Text
    4.     sArr() = Split(sRev, vbCrLf)
    5.     For i = 0 To UBound(sArr)
    6.         iNext = InStr(mConvert.NumberToRoman(i + 1), sArr(i))
    7.         If iNext > 0 Then RomanAmt = RomanAmt + 1
    8.     Next i
    9.     txtDesign.Text = txtDesign.Text & (Romans(RomanAmt + 1).rnRoman & ".")
    10.     Romans(NextRoman).rnUsed = True
    11.     txtDesign.SelStart = Len(txtDesign.Text)
    12.     txtDesign.SetFocus

  13. #13
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Changing text in textbox once something is erased

    Using RB's idea as a springboard:

    Depending how high the roman numerals are going to get, you might want to adopt some sort of 'intelligent' (playing fast and loose with that word) searching:

    Say they've gone up to LIII. That would be 53 InStr() calls if you go I., II., III., etc.
    An alternative would be look in intervals and then narrow it:
    Code:
    Look for: XX - Present +20
              XL - Present +20
              LX - Not Present -10
              L - Present +5
              LV - Not Present -3
              LII - Present +1
              LIII - Present +1
              LIV - Not Present - Highest is LIII
    Obviously an optimum algorithm for your senario would take some experimentation.

  14. #14
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Changing text in textbox once something is erased

    I'm afraid it wouldn't be as simple:
    say you typed I,II,III ... X and so on. But then you say "hmmm... IV and V really belong to III" so you erased them both but in your textbox there are VI,VII and so on.
    So, what are you going to set as you next available index? IV? That was my initial concern - you'll get your index out of bounds... (well sorta).
    Honestly, I don't have any more or less reasonable idea at the moment so it will take some experimenting to figure it out how to handle this stuff.

  15. #15
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Changing text in textbox once something is erased

    Try this
    VB Code:
    1. Private Sub txtDesign_KeyPress(KeyAscii As Integer)
    2.  
    3. If KeyAscii = 8 Then
    4.     'If theres no text entered
    5.     If txtDesign.SelStart = 0 Then
    6.         NextRoman = 0
    7.         Exit Sub
    8.     End If
    9.    
    10.     'Remember the deleted text.
    11.     DeletedText = Mid(txtDesign.Text, txtDesign.SelStart, 1) & DeletedText
    12. Else
    13.     DeletedText = ""
    14. End If
    15.  
    16. 'Set the Roman Numeral
    17. If Not ReturnRoman(DeletedText) = 0 Then
    18.     NextRoman = ReturnRoman(DeletedText) - 1
    19. End If
    20.    
    21. End Sub
    22.  
    23. Private Function ReturnRoman(Number As String)
    24. Dim TotalCount As Integer
    25. Dim BeforeCount As Integer
    26. Dim I As Integer
    27.  
    28. BeforeCount = 0
    29. TotalCount = 0
    30.  
    31. For I = 1 To Len(Number)
    32.     Select Case Mid(Number, I, 1)
    33.         Case Is = "I"
    34.             'Count the I's
    35.             BeforeCount = BeforeCount + 1
    36.         Case Is = "V"
    37.             'Subtract number of I's from 5
    38.             TotalCount = 5 - BeforeCount
    39.             'Reset I count
    40.             BeforeCount = 0
    41.         Case Is = "X"
    42.             'Subtract number of I's from 10
    43.             TotalCount = 10 - BeforeCount
    44.             'Reset I count
    45.             BeforeCount = 0
    46.             'End of number
    47.         Case Is = "."
    48.             Exit For
    49.     End Select
    50. Next
    51. 'If there are I's to be added to the total amount
    52. If BeforeCount <> 0 Then
    53.     TotalCount = TotalCount + BeforeCount
    54. End If
    55.  
    56. ReturnRoman = Trim(TotalCount)
    57.            
    58. End Function

    Remember to declare DeletedText as string at the top of your code

    This will remember everything you delete, and check for roman numerals at the start of the text. Deleting a period will reset the remembered text, to notify the program that a possible roman numeral is starting.

    I tested it, but not much, so there may be a few bugs to clear up.

    Hope this gets you on the right track =)

    -Rob
    Last edited by Rob123; Mar 20th, 2006 at 03:09 AM.

  16. #16

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Changing text in textbox once something is erased

    Very nice!!

    thanks a lot bro!

  17. #17

  18. #18

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Changing text in textbox once something is erased

    Quote Originally Posted by MartinLiss
    Does that handle the sentence I suggested in my post #11?
    It seems to, but there is some trouble with the code when you get into higher roman numerals for some reason.

    If you want to take a look at what I have now Marty, I will send it.

    I just hope it doesn't ask for a password to open it again
    Attached Files Attached Files

  19. #19

  20. #20
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing text in textbox once something is erased

    Observations:
    • I thought that if you deleted a line and it's roman that the next time you added a roman it would replece the number you deleted but it doesn't seem to do that.
    • It would be nice I think if upon pressing Enter that the next roman numeral would be generated automatically.
    • Shouldn't the next roman after pressing F7 be "I"?
    • You don't have a function key for "Indent" and you don't have a button for "Clear"

  21. #21

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Changing text in textbox once something is erased

    Ok, thanks for these observations they are a big help.

    I will get on to fixing the problems you found.

    By the way, I start getting troubles when I get up to the 20s and 30s for roman numerals.

  22. #22

  23. #23

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Changing text in textbox once something is erased

    F2 until you get to XIV, then erase the XIV, and hit f2 again and you will see my problem

  24. #24
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing text in textbox once something is erased

    OK, I'll look at that but in the meantime I suggest you gracefully handle a too high roman number with a modification like this.
    VB Code:
    1. Private Sub cmdAddNum_Click()
    2.  
    3.     On Error GoTo ErrorRoutine
    4.  
    5.     NextRoman = NextRoman + 1
    6.     NextAlpha = 0
    7.     txtDesign.Text = txtDesign.Text & (mConvert.NumberToRoman(NextRoman) & ". ")
    8.     Romans(NextRoman).rnUsed = True
    9.     txtDesign.SelStart = Len(txtDesign.Text)
    10.     txtDesign.SetFocus
    11.  
    12.     Exit Sub
    13.  
    14. ErrorRoutine:
    15.  
    16.     If Err.Number = 9 Then
    17.         MsgBox "Sorry Roman Numerals can not exceed " & NumberToRoman(UBound(Romans) + 1)
    18.     Else
    19.         MsgBox Err.Description
    20.     End If
    21.  
    22. End Sub

  25. #25
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing text in textbox once something is erased

    Quote Originally Posted by paralinx
    F2 until you get to XIV, then erase the XIV, and hit f2 again and you will see my problem
    When I do that I get XV. In fact as I mentioned above when I delete any number I just get the highest number plus 1.

  26. #26

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Changing text in textbox once something is erased

    Really? When I do the same thing I get IV. with no X infront..

  27. #27
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing text in textbox once something is erased

    Quote Originally Posted by paralinx
    Really? When I do the same thing I get IV. with no X infront..
    I found the difference. If you highlight-delete-F2 you get XV,but if you backspace to delete the text and then press F2 you get IV.

  28. #28
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing text in textbox once something is erased

    It's happening because when you backspace the ReturnRoman function gives the wrong answer (3) so you see IV.

  29. #29
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Changing text in textbox once something is erased

    After rethinking the problem, the delete-watcher really wasn't necessary
    Use your original program, and try this:
    VB Code:
    1. Dim keyWord As String
    2.     Dim searchCount As Integer
    3.     Dim notFinished As Boolean
    4.  
    5. Private Sub cmdAddNum_Click()
    6.     searchCount = 0
    7.     notFinished = True
    8.     keyWord = " "
    9.        
    10.     Do While notFinished
    11.         searchCount = searchCount + 1
    12.         If InStr(1, txtDesign.Text, keyWord & GetRoman(searchCount) & ".") = 0 Then
    13.             NextRoman = searchCount
    14.             notFinished = False
    15.         End If
    16.     Loop
    17.    
    18.     NextAlpha = 0
    19.     txtDesign.Text = txtDesign.Text & (GetRoman(NextRoman) & ". ")
    20.     txtDesign.SelStart = Len(txtDesign.Text)
    21.     txtDesign.SetFocus
    22. End Sub

    This will search for any missing numeral in the text.
    Replace
    VB Code:
    1. keyWord = " "
    with anything you choose which will be the identifier for the numeral.

    As for the King George V. problem, this will only cause confusion if it is written as the 4th statement, and it will skip the 5th roman numeral.

    If X is written in the 9th statement, the 10th roman numeral will be skipped.

    This shouldn't be too much of a problem, and the only way I can see to avoid this is to insert an indentifier before the roman numeral.

    Hope thats useful
    Last edited by Rob123; Mar 21st, 2006 at 06:36 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width