Results 1 to 10 of 10
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Loops (WinXP/OXP)

    I think my brain must be switched off this morning, but ... I'm stuck on one of my bete noirs, loops.
    <UL><LI>This form has a set of 10 text fields called b1, b2, etc, each of which contains a single word of up to 10 characters length,
    <LI>plus a single character text field for each of these (a1-a0), which contains a number from 1 to 0 (for 10).
    <LI>with each set of ten, the a1 and b1 become a2 and b2, and the text-replace increments straight through to 00 (for 100).
    <LI>Note: txtreplace is a small function that does a find/replace, and the code basically makes the character at the specified point upper case.[/list]As you can see, with ten fields of up to ten characters each, this code runs 100 times. I currently cycle through these fields with code that looks like this:

    If frmML1.a1 = "1" Then TxtReplace "#ms1a01", UCase(mid(frmML1.b1, 1, 1)) Else TxtReplace "#ms1a01", mid(frmML1.b1, 1, 1)
    If frmML1.a1 = "2" Then TxtReplace "#ms1a02", UCase(mid(frmML1.b1, 2, 1)) Else TxtReplace "#ms1a02", mid(frmML1.b1, 2, 1)

    I'm sure it must be possible to do a loop to pick up just the number that changes each time (1 to 0, 10 times), but I'm only capable of very simple loops so far - could someone point me in the right direction, please?

    Ta muchly!
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Loops (WinXP/OXP)

    I don't understand your description or your code. Could you try again?

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Loops (WinXP/OXP)

    Is that after I edited it to correct the silly mistake in the code? If so ...

    Text field b1 contains single word, up to 10 characters. Likewise b2, b3, ... b9, b0 (0 = 10)
    Text field a1 contains a number, 1 to 0 (for 10). Likewise a2, ... a0
    Required result is that the character in the word in b1 that corresponds to number in a1 is upper case.

    eg b1 = "something", a1 = 5, result = "someThing"

    Does that help?
    Beryl M


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Loops (WinXP/OXP)

    I still don't understand most of what you're trying to do:
    <UL><LI>What is the role of the fixed strings "#ms1a01" etc.?
    <LI>What is the function of the Else part in lines such as

    If frmML1.a1 = "1" Then TxtReplace "#ms1a01", UCase(mid(frmML1.b1, 1, 1)) Else TxtReplace "#ms1a01", mid(frmML1.b1, 1, 1)

    <LI>What does "the text-replace increments straight through to 00 (for 100)" mean?[/list]Sorry to be so dense.

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Loops (WinXP/OXP)

    No, it's bound to be me, I often do that; I know what something means, so I don't see that I haven't actually explained it properly!

    At present the code works on a character by character basis; with 10 words of up to 10 characters each, there are up to 100 characters that need to be checked to see if they need to be uppercase; the Else part of the line says enter the lowercase character if it's not the one to be uppercased.

    The text string ("#ms1a01", etc) is the placeholder in the document that is replaced by , with a string for each character of each word (could be replaced with one for each of the 10 words, once the appropriate character in each has been uppercased, maybe?). The document therefore looks like this:

    #ms1a01#ms1a02#ms1a03#ms1a04#ms1a05#ms1a06#ms1a07# ms1a08#ms1a09#ms1a10
    #ms1a11#ms1a12#ms1a13#ms1a14#ms1a15#ms1a16#ms1a17# ms1a18#ms1a19#ms1a20
    etc

    until the find and replace ('txtreplace') runs, to replace it with:

    someThing
    aNything
    notHing
    etc

    I always start these replaceable strings with a # because it never turns up in ordinary text and so won't replace something I don't want to by accident!

    I'm sure it still looks like nonsense, but this is to do with my puzzle-compiling and therefore doesn't need to be in proper English (in fact, if you had a copy of a magazine called 'Chat Puzzles' and found a puzzle called 'Missing Links' in it , you'd be looking at the result of what I'm trying to automate the typing up of (the centre column), if you see what I mean ...)

    Thanks for your help!
    Beryl M


  6. #6
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Loops (WinXP/OXP)

    Sorry, missed the last question!

    There are up to 10 characters in each b? field, 10 b? fields, so a possible 100 characters. The code therefore works through b1, character 1; b1, character 2; b1, character 3, etc to b0, character 9; b0, character 10 - numbering each character incrementally, 1 to 100.

    b1 ch. 1 = 01
    b1 ch. 2 = 02
    ...
    b5 ch. 6 = 46
    b5 ch. 7 = 47
    ...
    b0 ch. 9 = 99
    b0 ch. 0 = 00 (100)

    -------------------------------------------------------
    However, let's start again.

    I need to look at a text field containing a single word, all lower case, take the number from another text field and make the corresponding letter in the word upper case, eg "something", 5 = "someThing", then place that in my document. Repeated 10 times.

    How would you do it?!
    Beryl M


  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Loops (WinXP/OXP)

    Here is the code, using a single loop:

    Dim i As Integer, intPos As Integer, strChar As String
    For i = 1 To 100
    intPos = i Mod 10
    If intPos = 0 Then
    intPos = 10
    End If
    strChar = Mid(frmML1.Controls("b" & (((i - 1) 10 + 1) Mod 10)), intPos, 1)
    If frmML1.Controls("a" & (((i - 1) 10 + 1) Mod 10)) = (i Mod 10) Then
    strChar = UCase(strChar)
    End If
    TxtReplace "#ms1a" & Right("0" & i, 2), strChar
    Next i

    I would have done this slightly differently: make the document contain just 10 codes:

    #ms1a01
    #ms1a02
    #ms1a03
    #ms1a04
    #ms1a05
    #ms1a06
    #ms1a07
    #ms1a08
    #ms1a09
    #ms1a10

    Dim i As Integer, j As Integer, intPos As Integer, strChar As String
    For i = 1 To 10
    j = i
    If j = 10 Then j = 0
    intPos = frmML1.Controls("a" & j)
    If intPos = 0 Then intPos = 10
    strChar = frmML1.Controls("b" & j)
    Mid(strChar, intPos, 1) = UCase(Mid(strChar, intPos, 1))
    TxtReplace "#ms1a" & Format(i, "00"), strChar
    Next i

    Things would be even simpler if you numbered everything starting at 0 instead of at 1.

  8. #8
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Loops (WinXP/OXP)

    Hans, you're a marvel!

    I presume when you say it would be simpler if I numbered from 0 instead of 1 you mean you wouldn't have to do the 10 = 0 and 0 = 10 bits? I did think of that, but I'm working with old code I wrote several years ago and the idea of going through and changing them all individually made me tired at the idea! If I wanted to do that, I presume it would mean "j = 0 to 9" and removing the two "if ... = ... then ... = ..." lines?

    Still, I think it would be worth it, to use the new version you've just suggested! There are a couple of other places where similar code is cluttering up the place something chronic, so I'm going to see if I can apply your method to those, as well ...

    Wish me luck!

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Loops (WinXP/OXP)

    Yes, I meant indeed that numbering 0 ... 9 instead of 1 ... 0 and 00 ... 99 instead of 01 ... 00 would avoid having to juggle the case of 10 (and 100) separately.

    If your code works OK now, you can leave it as it is, but if you feel up to redesigning it, yes, it would be worth it to include the renumbering.

  10. #10
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Loops (WinXP/OXP)

    Well, it seems to me that there is a big difference between changing each of 100 bits of text, and removing all but ten of them before altering the remainder!

    And the practice will do me good - as I said, loops are one of the things I find hardest ... along with arrays ...

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    Beryl M


Posting Permissions

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