Page 1 of 1

Working with barcode

Posted: Wed Feb 14, 2018 8:44 pm
by TimStone
I have a dialog that contains a get field and an array browse.

I'm trying to capture a scanned code ( UPC : Universal Part Code ) into the Get, as keyboard input followed by a CRLF.

Then, the code is added to the array that is displayed in the browse.

No problem doing this. However, I then want the GET field to be blank and put back into focus.

I can use a VALID to execute everything except putting the cursor back in the single GET field. Right now I can do the scan, which puts the code into the GET, and the CRLF makes it add to the browse list, and a refresh clears the data. However I then have to click on the GET field for it to be in focus.

Code: Select all

METHOD BuildBarCodeList() CLASS tWorkorder

    LOCAL aBrowseCodes := {}, lAddItems := .f., cBarCode := SPACE(30)

    // Display dialog
    DEFINE DIALOG oBCdlg1 RESOURCE "WOBARCODE" TRANSPARENT OF oWnd TITLE "Input from barcode reader"

    REDEFINE GET oBC1 VAR cBarCode  ID 200 OF oBCdlg1 UPDATE ;
        VALID ( AADD( aBrowseCodes, cBarCode),;
        oLbc1:update(),;
        cBarCode := SPACE(30),;
        oBCdlg1:update(), .t.) 
        [b]// Trying to add oBC1:setfocus() to the valid causes a compile syntax error[/b]

    // Create the list control
    REDEFINE  XBROWSE oLbc1 ;
    DATASOURCE aBrowseCodes ;
    ID 300 OF oBCdlg1 ;
    HEADERS " Partnumber " ;
    COLUMNS 1 ;
    AUTOSORT UPDATE 

        // Provide the header gradient
        oLbc1:bClrGrad := aPubGrad 
        // Set the styles
        oLbc1:nMarqueeStyle := MARQSTYLE_HIGHLROW
        oLbc1:nColDividerStyle := LINESTYLE_RAISED
        oLbc1:nRowDividerStyle := LINESTYLE_RAISED
        oLbc1:nHeadStrAligns  := AL_CENTER
        oLbc1:nStretchCol := STRETCHCOL_LAST
        
        REDEFINE BUTTONBAR oBCBarA ID 100 SIZE 60,60 OF oBCdlg1 2015
            oBCBarA:bClrGrad := aPubGrad

        DEFINE BUTTON oBtnBC1 OF oBCBarA RESOURCE "HRADD"  PROMPT "Add" TOOLTIP "Add parts to the workorder" ;
          ACTION ( lAddItems := .t., oBCdlg1:end( ) )
        DEFINE BUTTON oBtnBC2 OF oBCBarA RESOURCE "HREXIT" PROMPT "Exit" TOOLTIP "Exit the without adding" ;
          ACTION oBCdlg1:end( ) 
    
        // Activate the dialog screen
        ACTIVATE DIALOG oBCdlg1 CENTERED

RETURN nil
 
Any thoughts on how to resolve this ?

Re: Working with barcode

Posted: Wed Feb 14, 2018 10:07 pm
by Gale FORd
Maybe add oBC1:oJump := oBC1 to valid

Code: Select all

    REDEFINE GET oBC1 VAR cBarCode  ID 200 OF oBCdlg1 UPDATE ;
        VALID ( AADD( aBrowseCodes, cBarCode),;
        oLbc1:update(),;
        cBarCode := SPACE(30),;
        oBCdlg1:update(), ;
        oBC1:oJump := oBC1,;  // This might work here
        .t.)
        [b]// Trying to add oBC1:setfocus() to the valid causes a compile syntax error[/b]

 

Re: Working with barcode

Posted: Thu Feb 15, 2018 1:32 am
by TimStone
Thanks, Gale, but it doesn't work. Yes it moves it to the right position, but it also prevents the dialog from being closed by the button controls. In addition, it seems to be adding blank arrays.

Tim

Re: Working with barcode

Posted: Thu Feb 15, 2018 2:09 am
by nageswaragunupudi

Code: Select all

      VALID ( AAdd( aBrowseCodes, cBarCode   ), ;
              oLbc1:Refresh(), ;
              cBarCode     := Space( 30 ), ;
              oBC1:Refresh(), .f. )
 

Re: Working with barcode

Posted: Thu Feb 15, 2018 5:49 am
by TimStone
Thanks ... I should have thought of that.

Now, there is another problem. Here is the existing Method:

Code: Select all

METHOD BuildBarCodeList() CLASS tWorkorder

    LOCAL aBrowseCodes := {}, cBarCode := SPACE(30), oLbc1, oBCdlg1, oBC1

    // Display dialog
    DEFINE DIALOG oBCdlg1 RESOURCE "WOBARCODE" TRANSPARENT OF oWnd TITLE "Input from barcode reader"

    REDEFINE GET oBC1 VAR cBarCode  ID 200 OF oBCdlg1 UPDATE ;
        VALID  ( AADD( aBrowseCodes, cBarCode), ;
        oLbc1:refresh(), ;
        cBarCode := SPACE(30), ;
        oBC1:refresh(), ;
        .f. )

    // Create the dialog box
    REDEFINE  XBROWSE oLbc1 ;
    DATASOURCE aBrowseCodes ;
    ID 300 OF oBCdlg1 ;
    HEADERS " Partnumber " ;
    COLUMNS 1 ;
    AUTOSORT EDITABLE UPDATE 

        // Provide the header gradient
        oLbc1:bClrGrad := aPubGrad 
        // Set the styles
        oLbc1:nMarqueeStyle := MARQSTYLE_HIGHLROW
        oLbc1:nColDividerStyle := LINESTYLE_RAISED
        oLbc1:nRowDividerStyle := LINESTYLE_RAISED
        oLbc1:nHeadStrAligns  := AL_CENTER
        oLbc1:nStretchCol := STRETCHCOL_LAST
        
        REDEFINE BUTTONBAR oBCBarA ID 100 SIZE 60,60 OF oBCdlg1 2015
            oBCBarA:bClrGrad := aPubGrad

        DEFINE BUTTON oBtnBC1 OF oBCBarA RESOURCE "HRADD"  PROMPT "Add" TOOLTIP "Add parts to the workorder" ;
          ACTION ( lAddItems := .t., oBCdlg1:end( ) )
        DEFINE BUTTON oBtnBC2 OF oBCBarA RESOURCE "HREXIT" PROMPT "Exit" TOOLTIP "Exit the without adding" ;
          ACTION oBCdlg1:end( ) 
    
        // Activate the dialog screen
        ACTIVATE DIALOG oBCdlg1 CENTERED
    

RETURN nil

 
It correctly adds the UPC to the array and displays it. Now, however, oBtnBC2, instead of closing the dialog, simply adds a blank element to the array. Keep clicking it, and it keeps adding the blank lines.

Thoughts on this ?

Re: Working with barcode

Posted: Thu Feb 15, 2018 11:21 am
by nageswaragunupudi
Please add this line after defining oBtnBC2

Code: Select all

oBtnBC2:lCancel := .t.
This solves your problem.

It is any way desirable to make the valid clause safer:

Code: Select all

      VALID ( If( Empty( cBarCode ), nil, AAdd( aBrowseCodes, cBarCode   ) ), ;
              oLbc1:Refresh(), ;
              cBarCode     := Space( 30 ), ;
              oBC1:Refresh(), .f. )
 

Re: Working with barcode

Posted: Thu Feb 15, 2018 5:22 pm
by TimStone
Thank you. It is now working perfectly.

In case someone wants to add this type of capability to their program, with the small hand held barcode readers, and use of UPCs, any type of inventory or sales work is simplified. Some of the small readers can now be remotely used up to 300 meters from the computer.

In this program, the idea is that a person can select the Barcode button, then walk around the stock room and scan the parts pulled to use on the service. At the computer, the parts will be on a list. At the time of the scan, the program will actually look at the inventory and get the other data on each part and add it to the array. When finished, the person can edit the data in the browse if desired, then push a button to add the whole list to the invoice. This makes it quite quick to do this work.

These new barcode readers work with bluetooth or a USB dongle. It's also possible to pair them with a small handheld tablet and use them for inventory control work in the stock room. The possibilities are many.

Re: Working with barcode

Posted: Fri Jun 29, 2018 1:08 pm
by Marc Venken
TimStone wrote:Thank you. It is now working perfectly.

In case someone wants to add this type of capability to their program, with the small hand held barcode readers, and use of UPCs, any type of inventory or sales work is simplified. Some of the small readers can now be remotely used up to 300 meters from the computer.

In this program, the idea is that a person can select the Barcode button, then walk around the stock room and scan the parts pulled to use on the service. At the computer, the parts will be on a list. At the time of the scan, the program will actually look at the inventory and get the other data on each part and add it to the array. When finished, the person can edit the data in the browse if desired, then push a button to add the whole list to the invoice. This makes it quite quick to do this work.

These new barcode readers work with bluetooth or a USB dongle. It's also possible to pair them with a small handheld tablet and use them for inventory control work in the stock room. The possibilities are many.
Tim,

This is exactly what i need.

Can you share the final working code please ?

Re: Working with barcode

Posted: Fri Jun 29, 2018 10:34 pm
by TimStone
This is the core part of the Method. Once the Dialog is exited, then the array is read and the values applied through a lookup scheme, and adding parts to where they apply, ie. inventory, etc. You could also write code to add parts to an invoice, or to store values that are later used to compare your inventory stock value versus the actual count.

Code: Select all

METHOD BuildBarCodeList() CLASS tWorkorder

    LOCAL aBrowseCodes := {}, cBarCode := SPACE(30), oLbc1, oBCdlg1, oBC1, aBarCode
    LOCAL oEditWork := self, lAddItems := .f.

    // Display dialog
    DEFINE DIALOG oBCdlg1 RESOURCE "WOBARCODE" TRANSPARENT OF oWnd TITLE "Input from barcode reader"

    REDEFINE GET oBC1 VAR cBarCode  ID 200 OF oBCdlg1 UPDATE ;
        VALID  ( IIF( Empty( cBarCode ), nil,;
        ( aBarCode := oEditWork:LookupBarCode( cBarCode ), AADD( aBrowseCodes, aBarCode))), ;
        oLbc1:refresh(), ;
        cBarCode := SPACE(30), ;
        oBC1:refresh(), ;
        .f. )

    // Create the dialog box
    REDEFINE  XBROWSE oLbc1 ;
    DATASOURCE aBrowseCodes ;
    ID 300 OF oBCdlg1 ;
    HEADERS " Quantity ", " UPC ", " Partnumber ", " Description " ;
    SIZES 100, 200, 200, 500 ;
    COLUMNS 1, 2, 3, 4 ;
    FASTEDIT UPDATE 

        REDEFINE BUTTONBAR oBCBarA ID 100 SIZE 60,60 OF oBCdlg1 2015
            oBCBarA:bClrGrad := aPubGrad

        DEFINE BUTTON oBtnBC1 OF oBCBarA RESOURCE "HRADD"  PROMPT "Add" TOOLTIP "Add parts to the workorder" ;
          ACTION ( lAddItems := .t., oBCdlg1:end( ) )
            oBtnBC1:lCancel := .t.
        DEFINE BUTTON oBtnBC2 OF oBCBarA RESOURCE "HREXIT" PROMPT "Exit" TOOLTIP "Exit without adding" ;
          ACTION oBCdlg1:end( ) 
          oBtnBC2:lCancel := .t.
    
        // Activate the dialog screen
        ACTIVATE DIALOG oBCdlg1 CENTERED

  // Application code follows that takes the stored values an applies them to various situations.

RETURN NIL

// And in the .rc file:

WOBARCODE DIALOG 0, 0, 660, 410
STYLE WS_POPUP | WS_CAPTION
CAPTION "Barcode Input"
{
    CONTROL                 "", 100, "TBar", 0|WS_CHILD|WS_VISIBLE, 0,0, 660, 30
    LTEXT           "Barcode",-1,15,40,50,13
    EDITTEXT        200,75,40,200,13
    CONTROL         "",300,"TxBrowse",WS_BORDER | WS_VSCROLL | WS_TABSTOP,15,70,630,330
}
 

Re: Working with barcode

Posted: Mon Jul 02, 2018 7:16 am
by Marc Venken
Thanks. Will look into it.