Strange problem - InfoPath Dev
in

InfoPath Dev

Strange problem

Last post 07-18-2006 10:22 AM by garym. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-17-2006 08:17 AM

    • garym
    • Top 500 Contributor
    • Joined on 07-12-2006
    • USA
    • Posts 29

    Strange problem

    When executing the following code...

    <InfoPathEventHandler(MatchPath:="/dfs:myFields/dfs:dataFields/d:tblTimeSheet/@Date", EventType:=InfoPathEventType.OnValidate)> _
    Public Sub tblTimeSheet_Date_attr_OnValidate(ByVal e As DataDOMEvent)

    Dim ppStart As String
    Dim ppEnd As String
    Dim ppString As String
    Dim ppYear As String
    Dim ppMonth As String
    Dim ppDay As String
    Dim ppDateString As String

    ppString = e.Source.nodeValue.ToString()
    MessageBox.Show("Date=" + ppString, "Timesheet", MessageBoxButtons.OK)
    ppYear = ppString.Substring(0, 4)

    I recveive the following error....

    System.ArgumentOutOfRangeException
    Index and length must refer to a location within the string.
    Parameter name: length
    at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
    at System.String.Substring(Int32 startIndex, Int32 length)
    at TimeSheet.TimeSheet.tblTimeSheet_Date_attr_OnValidate(DataDOMEvent e) in C:\Documents and Settings\gmonk\My Documents\Visual Studio 2005\Projects\TimeSheet\CANProj1\FormCode.vb:line 99
    at Microsoft.Office.Interop.InfoPath.SemiTrust._DataDOMEventSink_SinkHelper.OnValidate(DataDOMEvent pDataDOMEvent)

    What happens is that the date string displays blank and then I receive the error message. After clicking ok the messagebox message displays again but with the date and the code continues normally.

    Any idea what is happening??

    Thanks,
  • 07-18-2006 09:07 AM In reply to

    I believe you have fallen victim to event bubbling. There are a couple of options here, but what is happening is that the OnValidate event is being called for several nodes through a hierachy. Instead of using e.Source, I suggest using e.Site, and on top of that you should probably put a limiting check on there to make sure you don't get that error:


    Dim ppString As String
    ppString = e.Site.nodeValue.ToString()

    if( ppString.Length < 12 ) 'Make sure that the string is long enough
    return;

    Dim ppStart As String
    Dim ppEnd As String
    Dim ppYear As String
    Dim ppMonth As String
    Dim ppDay As String
    Dim ppDateString As String

    MessageBox.Show("Date=" + ppString, "Timesheet", MessageBoxButtons.OK)
    ppYear = ppString.Substring(0, 4)

    (Sorry about the syntax on the code I edited, I don't really do VB)

    For more information about event bubbling, see this link:http://www.infopathdev.com/howto/tutorials/default.aspx?i=3551199a23ac41f3a155b3a2ffc412c5
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 07-18-2006 10:22 AM In reply to

    • garym
    • Top 500 Contributor
    • Joined on 07-12-2006
    • USA
    • Posts 29
    Matt,

    Thanks, that worked.


    quote:
    Originally posted by Matt Faus

    I believe you have fallen victim to event bubbling. There are a couple of options here, but what is happening is that the OnValidate event is being called for several nodes through a hierachy. Instead of using e.Source, I suggest using e.Site, and on top of that you should probably put a limiting check on there to make sure you don't get that error:


    Dim ppString As String
    ppString = e.Site.nodeValue.ToString()

    if( ppString.Length < 12 ) 'Make sure that the string is long enough
    return;

    Dim ppStart As String
    Dim ppEnd As String
    Dim ppYear As String
    Dim ppMonth As String
    Dim ppDay As String
    Dim ppDateString As String

    MessageBox.Show("Date=" + ppString, "Timesheet", MessageBoxButtons.OK)
    ppYear = ppString.Substring(0, 4)

    (Sorry about the syntax on the code I edited, I don't really do VB)

    For more information about event bubbling, see this link:http://www.infopathdev.com/howto/tutorials/default.aspx?i=3551199a23ac41f3a155b3a2ffc412c5

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.