Moving from textfield to textfield, help needed

I have a row of text boxes in a set, each set to contain one letter. I want to do a text change event so that when I start typing a word in the first box, it will skip to the next box for the next letter and so on.

I can’t quite see how to do this and at the moment I am having to change boxes with the tab key, which is somewhat tedious.

I’d be grateful for some help. Thanks

In .KeyDown, set the focus to where you want…

Yes, as Emile says, do it in KeyDown. But you’ll probably also want to check to see if someone is backspacing, in which case you probably don’t want to advance it right away. You could do it all in TextChanged as well.

Steve,

You’ll probably want to subclass the textfield. This way you could make the textfield do exactly what you want, and the code would all be in one place.

If I understand right, you want each textfield to show only one character ?

Make a control set with your textfields, and add a CurrentTextField as Integer property to your window.

Then in Keydown, put Return True. That will enable KeyUp.

In Keyup, you can then manage focus this way:

If ASC(Key) > 32 then // No control characters, no space
   CurrentTextField = CurrentTextField + 1
   Textfield1(CurrentTextField).SetFocus
end if

When CurrentTextField reaches the maximum of ControlSet, set it to comes back to zero.

3 Likes

Thank you everybody for those suggestions, which I have been trying to incorporate. But it’s slightly more complex than I let on originally.

It is a Mac Desktop crossword app and there is a set of textfields, only visible from 1 to the length of the word required. The first textfield has the focus. All the cells are blank unless a crossing solution has been entered in which case the appropriate cell has the appropriate letter. So the line could read something like

_ _ _ P _ R _ G _ _

Ideally, I would just start typing, then look up to check I hadn’t made any errors, then click on the Accept button. But if I had made errors, I would need to start again or go back to the first mistake by using the shift tab or by clicking and then try to type more carefully.

Of course there are no restrictions on the letters to go into the blank squares but the letters already entered if any, should not be changed.

My best solution so far is a keydown event as follows. I’m sorry, I’ll try, but I’m not sure how to format it as code.

> dim t,ch as string
> dim r, c, length, d, i, n, m as integer
> r=arr_tNums(1)//don’t worry about this
> c=arr_tNums(2)//don’t worry about this
> length=arr_tNums(3)//don’t worry about this
> d=arr_tNums(4)//don’t worry about this
> m=me.index//m for me
> n=m+1//n for next
> t=key
> ch=t.Uppercase
> me.text=ch//keyed-in letter, in caps, goes into the textfield whatever
> if arr_tBuild(m+20)="0" or arr_tBuild(m+20)=""then//no problem as no crossing letter exists
> arr_tBuild(m)=ch.Uppercase//letter goes into a backup array
> tf(n).SetFocus//focus to next textfield
> else//must be a required letter in this cell
> ch=arr_tBuild(m+20)//get it from backup
> me.text=ch//and put it in cell whatever the keydown was
> tf(n).SetFocus//move focus on
> end

But unfortunately, as soon as I start typing, the capitalised letter appears in the appropriate cell but the lowercase letter entered on the keyboard appears in the next cel as well. This is overwritten by the next letter typed, but it is sloppy and it annoys me. Also, if I make a mistake and have to start again, I get various different annoying problems.

I’ve spent at least a day on it now and everything I try has the same problems, so any suggestions would be very welcome. Nearly 1am in the UK so am going to bed now. Thanks, good night! - Steve

Return true at the end of your keydown routine.

3 Likes

Oh magic, thanks very much for that, Bill, it now works a treat. It also works when I make a typing error - I just click on the error and continue typing carefully from there on. I’m very grateful, and also for the other helpful suggestions.

3 Likes