Author Topic: Form Change Causes KeyNotFoundException  (Read 5025 times)

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Form Change Causes KeyNotFoundException
« on: June 25, 2015, 12:04:16 PM »
I can add a new page, put a FromChange button on the main screen & use it once. If I add another page & a FormChange for that I can go to that page, but if I try to go to the earlier accessable page I get a KeyNotFoundException error with the detail "The given key was not present in the dictionary".

If I add another page I can access the new page but both previous pages show the error. I do Build (&/or Rebuild tried too) after adding a new page, compared the properties of the working button with the non-working ones, insured that the FormToOpen is the correct page (& all 3 pages show up to select - so they're there)

Is there something I'm missing here or not doing right?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form Change Causes KeyNotFoundException
« Reply #1 on: June 25, 2015, 12:32:46 PM »
This must be related to something else because the FormChangeButton does not access any dictionaries using keys.

Try using regular buttons and code like this:

- Add a Button from the All Windows Forms group in the Toolbox
- Double Click the button to get back to the code
- Add this code:

Form2.Show
Me.Hide


Change Form2 to the name of the form you want to open with the button.

See if you still get the error.

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: Form Change Causes KeyNotFoundException
« Reply #2 on: June 25, 2015, 12:55:44 PM »
Archie,

Tried that for pages 2 & 3 & constantly get same error for the pages that come up when I enter the code in the ViewCode.

BasicButton1_Click = Page2.Show
                                Me.hide

BasicButton2_Click = Page3.Show
                                Me.hide

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form Change Causes KeyNotFoundException
« Reply #3 on: June 25, 2015, 12:57:46 PM »
What version of AdvancedHMI and what driver are you using?

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: Form Change Causes KeyNotFoundException
« Reply #4 on: June 25, 2015, 02:13:56 PM »
AdvancedHMI Beta v398g
AB DF1Com1 driver (that all the PB's, pilot lights & meters work OK with)

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: Form Change Causes KeyNotFoundException
« Reply #5 on: June 25, 2015, 02:25:32 PM »
Archie,

When the error appears, the following code shows up highlighted (consistently the same section highlighted) but otherwise the DF1 driver works OK.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form Change Causes KeyNotFoundException
« Reply #6 on: June 25, 2015, 02:48:08 PM »
I have been able to reproduce this with the DF1Com driver. I will work on this and get back to you with a fix.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form Change Causes KeyNotFoundException
« Reply #7 on: June 25, 2015, 02:57:48 PM »
It looks like the DF1Com.vb needs 3 modifications:

- Edit AdvancedHMIDrivers\AllenBradley\Df1Com.vb
- Go to line 217 and change to this:

            If MyDLLInstance > 0 AndAlso (DLL IsNot Nothing) AndAlso (DLL.Count > MyDLLInstance) AndAlso DLL(MyDLLInstance) IsNot Nothing Then

- Go to line 242 and change to this:

            If MyDLLInstance > 0 AndAlso DLL.Count > 0 AndAlso DLL(MyDLLInstance) IsNot Nothing Then   'AndAlso Not DLL(MyDLLInstance).IsPortOpen Then

- The all the way near the bottom to line 430:

        If MyDLLInstance > 0 AndAlso DLL IsNot Nothing AndAlso  DLL.Count >= MyDLLInstance AndAlso DLL(MyDLLInstance) IsNot Nothing Then

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: Form Change Causes KeyNotFoundException
« Reply #8 on: June 25, 2015, 04:06:41 PM »
Pasted the 3 lines, but when I Build I get the following 3 errors about Line 243, tried adding parenthesis where i thought they might go, but then got Syntax Error.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form Change Causes KeyNotFoundException
« Reply #9 on: June 25, 2015, 04:17:22 PM »
On line 242, the last part of the expression was commented out. Did you possibly remove that ' for the comment? This is the code at line 242 without the commented part:

 If MyDLLInstance > 0 AndAlso DLL.Count > 0 AndAlso DLL(MyDLLInstance) IsNot Nothing Then
« Last Edit: June 25, 2015, 04:24:12 PM by Archie »

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: Form Change Causes KeyNotFoundException
« Reply #10 on: June 25, 2015, 05:09:16 PM »
The comment is still commented out (')

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form Change Causes KeyNotFoundException
« Reply #11 on: June 25, 2015, 05:31:33 PM »
Some where it is picking up IsPortOpen, but the only place that appeared was in the commented out code. Do you see that any place else?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form Change Causes KeyNotFoundException
« Reply #12 on: June 25, 2015, 05:35:51 PM »
I posted a patch for the DF1Com:

https://sourceforge.net/projects/advancedhmi/files/advancedhmi/3.5/Patches/

- Download and extract the file
- With AdvancedHMI open in Visual Studio, In Solution Explorer right click the folder AdvancedHMIDriver\AllenBradley then select Add->Existing Item
- Browse to the file that was downloaded and extracted
- It will ask if you want to overwrite the file, select Yes
- Rebuild the Solution

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: Form Change Causes KeyNotFoundException
« Reply #13 on: June 25, 2015, 06:35:00 PM »
Downloaded it to my flash drive, will try it tomorrow 1st thing when I get back to work.

Thanks.

AabeckControls

  • Full Member
  • ***
  • Posts: 193
    • View Profile
Re: Form Change Causes KeyNotFoundException
« Reply #14 on: June 26, 2015, 12:34:09 PM »
Archie,

Been a hectic day here & I just got around to this project & the new driver works OK.

Also, I saw the thread going on now about the MfgControl.AdvancedHMI.Drivers so I downloaded & installed that too.

Thank you.