Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: Ammar Hadi
  Where is Ammar Hadi?
 Al-Samawah
 Iraq
 Ammar Hadi
 To: Alex Gefter
  Where is Alex Gefter?
 Detroit
 Michigan - United States
 Alex Gefter
 Tags
Subject: RE: Set Focus
Thread ID: 232008 Message ID: 232020 # Views: 33 # Ratings: 0
Version: Visual FoxPro 7 Category: General VFP Topics
Date: Friday, June 19, 2009 2:35:15 AM         
   


> Hello,
> I am having difficulty in setting focus on the control I need.
>
> Here is the situatuion.
>
> On my form, I have a textbox that accepts only scans and a button. The button is not enabled until the scan happens.
> There are no keyboard or mouse - just a barcode scanner and a touch screen.
>
> The button should only appear after the barcode is scanned and verified. At this point my barcode is saved and the textbox is cleared. Button only should serve as an available option.
>
> My problem is to return the focus to the textbox and not have it on the button at all.
>
> I am trying to use Control.SetFocus but it doesn't work...
>
> Thank you for your help.
>
>
>
> AG

Hi Alex,

I would like to point here to an idea I used in my POS application.
I've noticed that many of the systems that use a Barcode reader is designed so that there is a textbox that should be in focus when the barcode code is transmitted to the form, because there the code will be collected and then processing occurs to it.

I played around this approach by using the Form keypress event (with keypreview set to .T.) to catch the barcode and after that a method is called to deal with the code.

To do that, I need to change the configuration of the barcode reader. I dealt with barcode readers from 2 vendors and both allows that 1 or more character (ascii code value) be appended to the beginning of the read code before it is sent to the keyboard buffer. In addition to that you can change the terminator to be a TAB , CRLF or else.

The idea her is that in the keypress event the system will check if the starter characters was entered, it will collect the next characters of the barcode till it encounter the terminator code that finishes the process and the code is sent to the method that will send the code to whatever you want based on the current page or mode you are in. (e.g. when I am in the new invoice page, it will select the read item and send its data to the invoice grid. And if I am in the new item page, it will send the code to the textbox reserved for this in the page). So, the use of the barcode this way is much more comfortable and the user will not need to be sure that the focus is at specific textbox.

I save the starter and terminator code as part of the configuration at the beginning of the use of the application, saved later in a dbf to be loaded at run to set of public variables (now I prefer to use 1 public object, I call it here goApp) to be used during barcode reading.

so, the code in the keypress event of the form:

*** KeyPress Event of the form, with keypreview=.T.
* This code deals with one starter code added (I think adding a NULL chr(0) in the
* configuration of the reader to the beginning is better to avoid the use of a key
* that may be needed during work)

LPARAMETERS nKeyCode, nShiftAltCtrl

WITH goAPP
 IF .lBarcodeLoading && the default is .f.
   IF nKeyCode=.nLastBarcodeChar  && last character
     .lBarcodeLoading=.F.
     THISFORM.check_barcode() && a custom method to deal with the barcode
   ELSE
     .cBarcodeString=.cBarcodeString+CHR(nKeyCode)
   ENDIF

   NODEFAULT
 ENDIF

 IF nKeyCode=.nFisrtBarcodeChar && reading from barcode scanner
     .lBarcodeLoading=.T.
     .cBarcodeString=""
     NODEFAULT
 ENDIF

ENDWITH


**** thisform.check_barcode()

** the barcode is in goApp.cBarcodeString
** code accordingly


Hope this Helps

Ammar Hadi ................IRAQ

My Foxite Weblog

---------------
I I I really love foxite
___________________________



COMPLETE THREAD
Set Focus Posted by Alex Gefter @ 6/18/2009 9:35:35 PM
RE: Set Focus Posted by Cetin Basoz @ 6/18/2009 9:57:42 PM
RE: Set Focus Posted by Andy Kramek @ 6/18/2009 11:13:21 PM
RE: Set Focus Posted by Ammar Hadi @ 6/19/2009 2:35:15 AM
RE: Set Focus Posted by Yousfi Benameur @ 6/19/2009 11:04:34 AM