Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textbox arrays problem 3

Status
Not open for further replies.

fingers

Programmer
Nov 17, 2000
17
0
0
I have 125 textboxes each limited to one character broken into 5 lines of 25. The indexes are 0-124. Object is to write words/sentences continuously and program will do the word wrapping. At each space, I check to see if there are enough boxes for the just-written word and if not, fill the remaining boxes with spaces and wrap the word to the next line.
My problem is, after wrapping, the focus is not given to the correct box. What troubles me is - if I put a breakpoint in and single step through the wrapping process, everything works fine and focus is given to the box after the wrapped word and space. However, when I just execute the routine, focus is placed several boxes before the correct one, thus erasing a letter from the wrapped word.
I have double and triple checked my textboxes and their index values. All are consecutive from 0 to 124. My code, for instance, after wrapping a word will specify sending focus to index 59 and textbox(56) will receive it. Yet, single stepping through the same code, index 59 is specified and textbox(59) gets it.
Does anyone have any idea why code will work single-steping and not work during regular execution?
 
Sounds like the wrapping process could be going to the "next" box and evaluating the index property to figure out where it is. Are you familiar with the difference between index and tabindex, and do you have all of your tabindex values equal exactly to your index values?
 
I suggest you put a few Debug.Prints in your code to confirm that it is progressing procedurally in the manner you expect, currently I expect it is not (such stuff may not show up when you step thru the code in the IDE). If you have any Doevents in there your code may be be shooting off and doing something that is causing the problem.
 
Not sure if this will help, but check out this thread, which includes an excellent description by strongm of how a Textbox's KeyUp, KeyDown, and KeyPress events respond when in the IDE with (and without) breakpoints.

thread222-1270631
 
Re BobRodes reply: Today, I deleted the 125 boxes and started from scratch just to make sure all indexes were correct. - Same problem. After reading your response, I checked tabindex and they were all crazy, so I reset them so that each corresponded to the txtbox index. Unfortunately, same problem.

Re HughLerwill reply: No doevents in code. Will try your idea of debugprint tomorrow.

Re quitarzan reply: Have downloaded your suggested thread and see if it leads me anywhere!

Thanks guys for your interest.
 
Hi Bob!

Yesterday, I did a work-around since nothing else worked. I am now entering the entire text into a character array and processing that, adding spaces to account for line length/wrapping. Then I copy the array to the 125 text boxes. This seems to work OK.

However, in the interest of "you're never too old to learn something", here is the snippet of code you wanted to see. Fresh eyes (and smarter eyes) can't hurt!

Thanks again for your interest.

Bud (fingers)


Private Sub txtCT_KeyPress(Index As Integer, KeyAscii As Integer)
Dim X As Integer

If KeyAscii > 96 Then
KeyAscii = KeyAscii - 32
ElseIf KeyAscii = 8 Then
txtCT(Index).Text = ""
Index = Index - 1
If thisword <> "" Then
thisword = Left$(thisword, Len(thisword) - 1)
End If
txtCT(Index).Text = ""
txtCT(Index).SetFocus
Exit Sub
End If
Index = Index + 1
txtCT(Index).SetFocus


End Sub

Private Sub txtCT_LostFocus(Index As Integer)
Dim X As Integer
Dim char As String

If txtCT(Index) = "" Then
Exit Sub
Else
If txtCT(Index).Text = clueletter Then
Beep
errorframe.Visible = True
Exit Sub
End If
char = txtCT(Index)
If Asc(char) = 13 Then
labPrompt1.Visible = False
cmdQuote.Enabled = False
Exit Sub
End If
If Asc(char) = 32 Then ' wordwrap routine
If Len(thisword) > 0 Then
thisword = thisword + " "
wordlen = Len(thisword)
If wordlen <= (endcount - lastspace) Then ' word will fit on line
thisword = ""
lastspace = Index
Else 'word too long to fit on line - space out rest of line and put word on next line
If lastspace < endcount Then
For Index = lastspace To endcount
txtCT(Index) = " "
Next Index
End If
Index = endcount
For Index = endcount + 1 To endcount + wordlen
txtCT(Index) = Mid$(thisword, Index - endcount, 1)
Next Index
endcount = endcount + 25
thisword = ""
lastspace = Index - 1
txtCT(Index).SetFocus
Exit Sub
End If
End If
End If
If (Asc(char) > 32) And (Asc(char) < 91) Then
thisword = thisword + txtCT(Index)
End If
Index = Index + 1
txtCT(Index) = ""
txtCT(Index).SetFocus
End If


End Sub
 
Glad you got it working.

FYI, your
Code:
    If KeyAscii > 96 Then
        KeyAscii = KeyAscii - 32
can be replaced by
Code:
KeyAscii = Asc(UCase(Chr(KeyAscii)))
Furthermore, your solution would cause {}| to read []\, so you should fix that logic.

Also, with a preliminary look at the code you provide I can't see how you actually get text into the txtCT array in the first place.

Bob
 
Hi Bob!

I type each character in the text box (txtCT()).

Actually, this is a little worksheet for solving crypto quips published in the papers. I type the quote, one character per box. In solve mode, you type the cipher character you want to replace followed by the character you think it should be. The program then places the plain text character above the cipher text character(s) and updates an "available characters" box.

This is just a program for my use and it sure saves a lot of erasing "wrong guesses".

With the work-around, I now type the whole quote in a single textbox and then process a new string to account for wrapping, adding spaces to fill out a line, etc. Then I use that to load the txtCT() array. Since I am just copying a character from 0 to 124 directly in the array, the txtCT index doesn't seem to get confused.

BTW, thanks for the tip on KEYASCII. Your solution saves a few lines of code. I'll start using that when I'm writing something that expects to see only upper case. In this particular case I wouldn't need the [] exclusion because I only allow ascii 65 to 90 to form "thisword".

Again, I really appreciate your interest. Since I'm retired, I don't have a local "guhru" to consult when I get stuck. This is really a self-taught hobby in an attempt to keep my mind busy!

Bud
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top