I think what you’re looking for is a using statement. Throw this up at the top with the rest of the using statements. (that’s just an educated guess since you aren’t actually showing us what the error is that your getting of why it’s not working.)
Sorry, I didn’t give much information on that post! Appreciate you helping on such an old thread. I want to implement the barcode scan at the MES menu so that they don’t even have to click on start production activity. I added the code to get the hot key working but I think I am missing how the scanned info gets captured. The only error I get while compiling is about the list adaptor like I mentioned above but even if I get past that I don’t think I have anything to capture the barcode scan? What line in the code tells MES that the information scanned is the _barcode value?
Can you post the code that you are using so I can understand what you have? There is a lot of code being slung around in that last post, and I’d rather just see what you’re trying to do instead of guessing what you’ve put together.
OK, I parsed through the thread a little more. There’s a key press subscription that’s missing. This thread is about what you do after you already have the barcode. There’s posts about how you set up the key watcher. Let me do a quick search.
Actually it’s this code here. But it’s missing the subscriber to actually fire that code. I can’t remember if you can make that with the wizard or not.
// Launch Start Activity from hot key
DateTime _lastKeystroke = new DateTime(0);
List<char> _barcode = new List<char>(10);
LaunchFormOptions lfo = new LaunchFormOptions();
public void MESMenu_KeyPress(object sender, KeyPressEventArgs e)
{
// Check timing (keystrokes within 100 ms)
TimeSpan elapsed = (DateTime.Now - _lastKeystroke);
if (elapsed.TotalMilliseconds > 100)
_barcode.Clear();
// Record keystroke and timestamp
_barcode.Add(e.KeyChar);
_lastKeystroke = DateTime.Now;
// Process barcode
if (e.KeyChar == (char)90 && _barcode.Count > 0)
{
string msg = new String(_barcode.ToArray());
lfo.IsModal = true;
lfo.ContextValue = msg;
_barcode.Clear();
ProcessCaller.LaunchForm(this.oTrans, "SSSM9999", lfo);
this.oTrans.RefreshLaborData();
}
}
Awesome, thanks Brandon, apologies for the extra work starting the new thread.
So I have the following code right at the MESMenu. The shortcut key is set to J and that works (opening start production activity). The compile I error I am getting is: Error: CS0246 - line 379 (1054) - The type or namespace name ‘List’ could not be found (are you missing a using directive or an assembly reference?)
The Code I am using is below…I am stuck on what is telling MES that the barcode I scan should be used for the _barcode value…I think I have missed a step somewhere and based on the error I am missing an assembly reference?
// Launch Start Activity from hot key
DateTime _lastKeystroke = new DateTime(0);
List<char> _barcode = new List<char>(10);
LaunchFormOptions lfo = new LaunchFormOptions();
public void MESMenu_KeyPress(object sender, KeyPressEventArgs e)
{
// Check timing (keystrokes within 100 ms)
TimeSpan elapsed = (DateTime.Now - _lastKeystroke);
if (elapsed.TotalMilliseconds > 100)
_barcode.Clear();
// Record keystroke and timestamp
_barcode.Add(e.KeyChar);
_lastKeystroke = DateTime.Now;
// Process barcode
if (e.KeyChar == (char)106 && _barcode.Count > 0)
{
string msg = new String(_barcode.ToArray());
lfo.IsModal = true;
lfo.ContextValue = msg;
_barcode.Clear();
ProcessCaller.LaunchForm(this.oTrans, "SSSM9999", lfo);
this.oTrans.RefreshLaborData();
}
Ok so everything seems to work/compile after added the code into “Start Production Activity” but when I scan the barcode from the MES screen, I get “Exception has been thrown by the target of an invocation”. I doubled checked the barcode is being read correctly (scanned into word) and that isn’t the issue. It is launching the form but I don’t think the values are being captured in the scan correctly…
Application Error
Exception caught in: mscorlib
Error Detail
============
Message: Exception has been thrown by the target of an invocation.
Inner Exception Message: Index was outside the bounds of the array.
Program: CommonLanguageRuntimeLibrary
Method: InvokeMethod
Client Stack Trace
==================
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Ice.Lib.Customization.CustomScriptMethodInvoker.InvokeScriptMethod(MethodInfo scriptMethod, Object[] parameters)
at Ice.Lib.Customization.CustomScriptMethodInvoker.InvokeCustomFormLoadIfExists(String methodName, Object sender, EventArgs e)
at Ice.Lib.Customization.CustomScriptManager.<>c__DisplayClass104_0.<OnCustomCodeFormLoad>b__0()
at Ice.Lib.Customization.CustomScriptManager.TryActionShowExceptionBoxOrLogVerificationErrorIfException(Action action, String exceptionBoxTitle)
Inner Exception
===============
Index was outside the bounds of the array.
at Script.StartProdForm_Load(Object sender, EventArgs args)
In developer mode, there is a checkbox for “Debug in visual studio” in the bottom corner. Check that box before you open the form and it should open visual studio and start debug mode.
Ok so I was looking in the wrong spot…rookie move…however, it seems that while the checkbox is there its disabled…I have Visual Studio installed but perhaps a setting I need to change? Sorry for the hassle on this
What’s the text of your barcode look like? It’s skipping the first part ( [0] ) and getting the second third and fourth parts of the split string. If you don’t have something in all 4 places, you’ll get that null reference error.