Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    148
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Code to help user memorize stuff

    Hi Experts,

    See the attached Excel file:

    I am looking for code to hide radom words from a verse of scripture to help the user memorize the verse.

    For example, in the verse below words are hidden when the user clicks the Learn button on the form.In this example, two word are hidden: wisdom and liberally

    5 If any of you lack ???? , let him ask of God, that giveth to all men ???? , and upbraideth not; and it shall be given him.

    The code would select words over three letters and would hide four words before a . (period) appears

    The user would try to remember the missing words. Then click the Restore button to see if he remember the missing words correctly.

    This might be very difficult to code.

    Thank you for any help provided.
    Attached Files Attached Files
    Last edited by Excelnewbie; 2015-10-07 at 22:35.

  2. #2
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,629
    Thanks
    114
    Thanked 645 Times in 589 Posts
    Excel,

    See if this works for you.

    HTH,
    Maud

    Code:
    Private Sub CommandButton3_Click()
    Randomize
    Dim Hword(), Hidden(4), s, t, count As Integer, I As Integer, J As Integer, K As Integer
    Dim Hidden1 As Integer, Hidden2 As Integer, Hidden3 As Integer, Hidden4 As Integer, Message As String
    LVerse.Caption = ""
    '------------------------------------------
    'SPLIT SENTENCES
    s = Split(scripture, ".")
    For I = 0 To UBound(s) - 1
    '------------------------------------------
    'SPLIT EACH SENTENCE
        t = Split(s(I), " ")
        count = 0
    '------------------------------------------
    'ASSIGN WORDS TO HWORD ARRAY IF 4 OR MORE LETTERS
        For J = 0 To UBound(t)
            ReDim Preserve Hword(count)
            If Len(t(J)) > 3 Then
                Hword(count) = t(J)
                Debug.Print Hword(count)
                count = count + 1
            End If
        Next J
    '------------------------------------------
    'REMOVE RANDOM WORDS FROM SENTENCE
        Hidden(1) = Int(((count - 1) * Rnd) + 1)
        Hidden(2) = Int(((count - 1) * Rnd) + 1)
        Hidden(3) = Int(((count - 1) * Rnd) + 1)
        Hidden(4) = Int(((count - 1) * Rnd) + 1)
        For K = 1 To 4
            s(I) = Replace(s(I), Hword(Hidden(K)), "____", vbTextCompare)
        Next K
    '------------------------------------------
    'REBUILD SENTENCE
        LVerse = LVerse & s(I)
    Next I
    
    End Sub
    Excel1.png
    Attached Files Attached Files

  3. The Following 2 Users Say Thank You to Maudibe For This Useful Post:

    Excelnewbie (2015-10-08),mrjimphelps (2015-10-08)

  4. #3
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    148
    Thanks
    67
    Thanked 0 Times in 0 Posts
    Maudibe-

    Absolutely amazing to me. Thank you!

    I wondered if I had come across something that might not be able to be coded.

    The code is working as I had hoped.

    I am still test driving this. I am studying the code to see if I can modify it so I can make some minor changes without troubling you.

    Thanks to you I am learning VBA, slowly for sure, but having a lot of fun along the way.

    Thanks again!

  5. #4
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    148
    Thanks
    67
    Thanked 0 Times in 0 Posts
    Maudibe-

    I worked with this most of the day. It is a pleasure to learn.

    I added the option to select the letter count using a combobox

    1. To do this I added a variable w
    2. Changed Hidden(4) to Hidden (10). w wouldn't work. I don't know why.

    Everything seems to work well with the changes I made. However, the changes I made need to be reviewed by an expert to insure it will work over the long run.


    I would like to add another feature but I don't know where to begin.

    Would it be possible for the user to see the words that were hidden highlighted in red when the restore button is clicked?


    Thanks again.


    Private Sub CommandButton3_Click()
    Randomize

    Dim w As Integer
    w = CbNum 'I added this variable

    Dim Hword(), Hidden(10), s, t, count As Integer, I As Integer, J As Integer, K As Integer
    Dim Hidden1 As Integer, Hidden2 As Integer, Hidden3 As Integer, Hidden4 As Integer, Message As String
    LVerse.Caption = ""


    '------------------------------------------
    'SPLIT SENTENCES
    s = Split(scripture, ".")
    For I = 0 To UBound(s) - 1
    '------------------------------------------
    'SPLIT EACH SENTENCE
    t = Split(s(I), " ")
    count = 0
    '------------------------------------------
    'ASSIGN WORDS TO HWORD ARRAY IF 4 OR MORE LETTERS
    For J = 0 To UBound(t)
    ReDim Preserve Hword(count)
    If Len(t(J)) > w Then
    Hword(count) = t(J)
    Debug.Print Hword(count)
    count = count + 1
    End If
    Next J
    '------------------------------------------
    'REMOVE RANDOM WORDS FROM SENTENCE
    Hidden(1) = Int(((count - 1) * Rnd) + 1)
    Hidden(2) = Int(((count - 1) * Rnd) + 1)
    Hidden(3) = Int(((count - 1) * Rnd) + 1)
    Hidden(4) = Int(((count - 1) * Rnd) + 1)

    For K = 1 To w
    s(I) = Replace(s(I), Hword(Hidden(K)), "____", vbTextCompare)
    Next K
    LVerse = LVerse & s(I)
    Next I

    End Sub

    Private Sub CommandButton4_Click()
    LVerse.Caption = scripture
    End Sub



    Private Sub Userform_Initialize()
    CbNum.List = Array("4", "5", "6", "7", "8", "9")
    End Sub
    Last edited by Excelnewbie; 2015-10-08 at 22:59.

  6. #5
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,629
    Thanks
    114
    Thanked 645 Times in 589 Posts
    Excel,

    Here is your slightly adjusted code that allows the user to select the length criteria of the words to hide

    Code:
    Private Sub CommandButton3_Click()
    Randomize
    Dim w As Integer
    w = CbNum 'I added this variable
    Dim Hword(), Hidden(4), s, t, count As Integer, I As Integer, J As Integer, K As Integer, Q As Integer
    Dim Hidden1 As Integer, Hidden2 As Integer, Hidden3 As Integer, Hidden4 As Integer, Message As String
    LVerse.Caption = ""
    '------------------------------------------
    'SPLIT SENTENCES
    s = Split(scripture, ".")
    For I = 0 To UBound(s) - 1
    '------------------------------------------
    'SPLIT EACH SENTENCE
        t = Split(s(I), " ")
        count = 0
    '------------------------------------------
    'ASSIGN WORDS TO HWORD ARRAY IF >W OR MORE LETTERS
        For J = 0 To UBound(t)
            ReDim Preserve Hword(count + 1)
            If Len(t(J)) > w Then
                count = count + 1
                Hword(count) = t(J)
            End If
        Next J
    '------------------------------------------
    'REMOVE RANDOM WORDS FROM SENTENCE
        For Q = 1 To 4
            Hidden(Q) = Int((count + 1) * Rnd)
        Next Q
        On Error Resume Next
        For K = 1 To 4
            s(I) = Replace(s(I), Hword(Hidden(K)), "____", vbTextCompare)
        Next K
        LVerse = LVerse & s(I)
    Next I
    End Sub
    Attached Files Attached Files

  7. #6
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,629
    Thanks
    114
    Thanked 645 Times in 589 Posts
    Excel,

    Unfortunately, there is no way to have selected words in the caption of a label a different color, bolded, italicized, etc.. It's all or nothing.

    Other options to identify the hidden words could be something like:
    [HiddenWord], *HiddenWord*, |HiddenWord|, or "HiddenWord" in the restored scripture.

    Maud

  8. #7
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,819
    Thanks
    133
    Thanked 480 Times in 457 Posts
    Hi Maud

    ..but you could do it on a worksheet.
    Shall I post a version?

    zeddy

  9. #8
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    148
    Thanks
    67
    Thanked 0 Times in 0 Posts
    Hi Maud-

    Thank you for your help. I am gradually learning.

    MemStuff_Revised2 above encounters a problem when I click restore. I have been working on finding the problem, but this code is way over my newbie skill level.

  10. #9
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    148
    Thanks
    67
    Thanked 0 Times in 0 Posts
    Maud-

    Thank you for all your effort. I think anyone of the ways you pointed out would be just fine.

    [HiddenWord], *HiddenWord*, |HiddenWord|, or "HiddenWord"

    Thanks to you,

    Excel

  11. #10
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,629
    Thanks
    114
    Thanked 645 Times in 589 Posts
    Excel,

    I was working on something in the CommandButton4_Click routine and I forgot to remove the line. Just comment out the lines below

    Code:
    Private Sub CommandButton4_Click()
    'Dim I As Integer
    LVerse.Caption = scripture
    'MsgBox UBound(Hword)
    'For I = 1 To UBound(Hword)
    'Next I
    End Sub

  12. #11
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    148
    Thanks
    67
    Thanked 0 Times in 0 Posts
    Maud,

    It worked like you said. I really like this file. Very useful. I will continue to study the code. Thanks teacher.

  13. #12
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,629
    Thanks
    114
    Thanked 645 Times in 589 Posts
    Excel,

    You are most welcome.

    Zeddy,

    I agree, cells on a spreadsheet would make it possible. I am not sure if Excelnewbie needs it in a form but please, go ahead. In the meantime, I'll come up with a way by altering the label caption. Excel can then decide what best suits his needs.

    Maud

  14. #13
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,819
    Thanks
    133
    Thanked 480 Times in 457 Posts
    Hi Maud

    ..OK, I'm going to try and show it using a Form, "to see the words that were hidden highlighted in red when the restore button is clicked"

    zeddy

  15. #14
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,819
    Thanks
    133
    Thanked 480 Times in 457 Posts
    Hi
    In my attached file, a Form will display a selected Scripture text for memorizing.

    zz1.GIF

    You can select the number of hidden words you want for the test. You can click a [Reveal] button on the Form to show the hidden words highlighted in bold red. You can also click a [Hint] button on the Form, which will show the first 1,2, or 3 letters of the hidden word in bold red (each click of the [Hint] button shows an extra letter, up to a maximum of 3 letters).

    I will be happy to explain how it's done. I have documented the vba code.

    I'm sure Maud will find the method interesting.
    And, as ever, there is always scope for improving my attached version.

    zeddy
    Attached Files Attached Files
    Last edited by zeddy; 2015-10-20 at 11:26.

  16. #15
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,819
    Thanks
    133
    Thanked 480 Times in 457 Posts
    Hi all

    ..so I get back from New York and no-one has asked for an explanation of my method.
    That is good news.
    But I'm going to reply to myself anyway.

    So, Maud is correct,
    Unfortunately, there is no way to have selected words in the caption of a label a different color, bolded, italicized, etc.. It's all or nothing.
    ..so instead of using a Form label control, we use a Form Image control.
    We do our font formatting in a cell, take a snapshot of the cell, copy the snapshot into a temp dummy Chart on the sheet. We can then use the temp Chart to export the image, and then import the image into the Form.
    Hey, I didn't say it was tidy.
    ..but it works nicely.

    You can use my posted file for 'memorize' other stuff too, just paste the text into column [A] with the text 'description' in column [B].


    zeddy

  17. The Following User Says Thank You to zeddy For This Useful Post:

    Excelnewbie (2015-10-26)

Page 1 of 2 12 LastLast

Posting Permissions

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