Tabbing between fields

I am very basic at programming and I am sure there is a very easy way to have dealt with my tedious entry of one textfield at a time. However, this is what I have done and it “works” I have a questionnaire for patients to complete. The top line has their name, age etc. When they complete the last line and press Return, the cursor jumps to textfield 1 or in this case, q(1). With every data entry I want the cursor to jump to the next field, q(2), q(3) … q(36). In an older version of RealBasic the following worked.

Dim n as integer

if key <> str(1) and key <> str(2) and key <> str(3) and key <> str(4) and key <> str(5) and key <> str(9) then
beep
exit

else

For n = 1 to 35 'This is the command for tabbing to the next field
Select Case Index 'after the right key has been pressed.
Case n
q(n+1).SetFocus
End Select
Next
End if

But now, when the cursor moves to q(1) and I enter a data point it jumps to q(2) and enters the number there. From that point on it works as it did in the older version. Any ideas to help with it moving to q(1), entering data, and then continuing on?

Thanks

Rob

Have you tried just setting the Tab Order for the input fields in the IDE?

Thanks Tanner for the suggestion but the tab order seems correct.

I’m not really following what you need. You want to move the focus when you press enter as if it were the press of a TAB?

What is “if key <> str(1) and key <> str(2) and key <> str(3) and key <> str(4) and key <> str(5) and key <> str(9) then”. If that isn’t satisfied you are always restarting at the top. (Why do you skip from 5 to 9?)

Although I don’t understand your program, it seems to me that you do not need the for…next loop at all.

Just set up your fields, be sure their UseFocusRing is “on” and that the fields are in the correct order. Then no matter which field you select, the tab key will take you to the next one.

Try this

if key <> str(1) and key <> str(2) and key <> str(3) and key <> str(4) and key <> str(5) and key <> str(9) then beep exit else if index = 36 then q(1).setfocus else index = index +1 q(index).setfocus end if end if

Thanks again Gary but that performed the same way my code did. To answer Chris’ post: On the questionnaire the only key entries allowed are the values, 1, 2,3, 4, 5 and 9 for missing data. I checked the UseFocusRIng suggestion but that did not help. I will have another look at the order of fields. I appreciate you folks trying to help with something that I know is probably so obvious to you to fix.

Rob

The only difference I can find between my program that work in Real Studio 2011 and in Xojo which has this glitch is that in Real Studio I could set the index value for each of the 36 textfields starting at 1. There is nothing in the ID panel of Xojo that allows for this. Any thoughts?

There is a way to do that in Xojo too.

View menu, Tab order MenuItem…

If you are using a control set, select the gear icon at the top of the inspector window to get access to the index.

Thanks guys. All is in order with the tabs and index. Not sure why but when I tab from the last field before question number 1 it goes to 1 but when I enter data it takes that number and puts in in textfield #2 and leave textfield #1 blank. This is the code before I tab to textfield 1

dim d as New Date
if key = Chr(13) then
TestDate.text=d.shortdate
//q(1).SetFocus (I have tried it with this active and not but it still moves to field #1 but the data entry goes to field #2

end if

Chr(13) is Return key, should it be tab key, chr(9)?