OK, this is probably obvious but the anser is avoiding me.
I'm using a barcode scanner to populate a string gadget, none of the barcodes have end of line indicators so i have to go on length.
I'm using the on change event but the barcodes can be of varying lengths ( usualy between 7 and 10 characters ).
So how do/can i indicate that the barcode scan is completed ?
Any pointers or help appreciated.
Captain S.
StringGadget & onchange event
- captain_skank
- Enthusiast

- Posts: 646
- Joined: Fri Oct 06, 2006 3:57 pm
- Location: England
Re: StringGadget & onchange event
Depending on the type of scanner you're using, there is usually an option to set an "end of scan" character that the scanner adds for just this purpose.
- Mindphazer
- Enthusiast

- Posts: 532
- Joined: Mon Sep 10, 2012 10:41 am
- Location: Savoie
Re: StringGadget & onchange event
To complete ebs's answer, usually you can set an option on the scanner to produce a LF or/and CRLF at the end of the scan
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 26.1 - Iphone 17 Pro Max - iPad at home
...and unfortunately... Windows at work...
...and unfortunately... Windows at work...
- captain_skank
- Enthusiast

- Posts: 646
- Joined: Fri Oct 06, 2006 3:57 pm
- Location: England
Re: StringGadget & onchange event
Unfortunately this does not have the expected result.
In notepad it's fine but in a string gadget the CR LF are stripped out at some point.
In notepad it's fine but in a string gadget the CR LF are stripped out at some point.
Re: StringGadget & onchange event
I have set my hand scanner to send me an end of text signal. (#ETX$)
Code: Select all
;-TOP
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(0)
dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
; Resize Gadgets
EndProcedure
Procedure Main()
Protected dx, dy, temp.s
#WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Test Window", #WinStyle)
; MenuBar
CreateMenu(0, WindowID(0))
MenuTitle("File")
; StatusBar
CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(0)
dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
StringGadget(0, 10, 10, 200, 25, "")
SetGadgetText(0, #ETX$)
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
; Main Loop
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case 0
Break
EndSelect
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_Change
temp = GetGadgetText(0)
If Right(temp, 1) = #ETX$
Debug "End Scan"
EndIf
EndSelect
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
Re: StringGadget & onchange event
viewtopic.php?t=51634
…or perhaps it will work with FindString() or Right() and/or by using an (hidden?) EditorGadget…
…or perhaps it will work with FindString() or Right() and/or by using an (hidden?) EditorGadget…
Re: StringGadget & onchange event
You could just use a timeout period, during which you don't consider the string input as being yet complete. Only following the timeout do you regard the string as complete, in the below case 750ms. You're giving the barcode reader plenty of time to transmit all its characters, regardless of the length of input. Hope it helps, it's the way I've often written serial I/O comms systems.captain_skank wrote: Tue Feb 24, 2026 3:43 pm I'm using a barcode scanner to populate a string gadget, none of the barcodes have end of line indicators so i have to go on length. I'm using the on change event but the barcodes can be of varying lengths ( usualy between 7 and 10 characters ). So how do/can i indicate that the barcode scan is completed ?
Code: Select all
;
; Example of barcode input with 750ms timeout to trigger complete code
; Run with debugger
EnableExplicit
Define event.i, evgadget.i, evtype.i, inpflag.i
Define t1.q
#TIMEOUT = 750 ; Desired ms timeout for barcode reader
If OpenWindow(0, 0, 0, 500, 200, "Barcode input change timeout", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(1, 15, 15, 100, 25, "Barcode input")
StringGadget(2, 160, 12, 306, 20, "")
SetActiveGadget(2)
Repeat
event.i = WaitWindowEvent(50) ; Loop timeout required, to allow us to continue to detect no further input
If event.i
evgadget.i = EventGadget()
evtype.i = EventType()
If evgadget.i = 2 And evtype.i = #PB_EventType_Change
t1.q = ElapsedMilliseconds() ; Set the last input time
inpflag.i = #True ; Received at least some input
EndIf
EndIf
If inpflag.i And ElapsedMilliseconds() > t1.q + #TIMEOUT
Debug "Complete barcode : " + GetGadgetText(2)
t1.q = 0 ; Reset time, accommodating next input
inpflag.i = #False ; Don't keep repeating
EndIf
Until Event = #PB_Event_CloseWindow
EndIf

