Form field place holders in strings?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andy B

    Form field place holders in strings?

    If I have the following text in a dataset table column: "This agreement
    establishes that {BandName} will play on {EventDate} between {StartTime} and
    {EndTime}..." How would I then take the field names {BandName}, {StartTime},
    {EndTime} and {EventDate}, match them up with actual dataset table column
    names, and show the actual values instead of the placeholders on the final
    page output? I know this would probably require some string parsing and
    stuff, but I need some good direction here. The other thing is that this
    whole thing is totally dynamic. I wont know any of the text or placeholder
    names (or table column names) in advance. These forms are being creating
    from a wizard control (including what form fields are used). Any ideas on
    where to get started?


  • Stephany Young

    #2
    Re: Form field place holders in strings?

    Lets' start with the assumption that you have 'extracted' the 'display' text
    into a string variable called, say, _displaytext.

    There are 2 things that you know.

    1. There may be 1 or more tokens that startwith { and end with }.

    2. The inner portion of each token is the name of a column in your datarow.

    First, extract inner portion of the tokens into a String array.

    Then, remove all the unwanted text from each element and replace the token
    in _displaytext with the text from the relevant column from your datarow.
    Ignore any elements that do not contain a token:

    Dim _ss As String() = _displaytext.Sp lit("{"c)

    For _i As Integer = 0 To _ss.Length - 1
    If _ss(_i).Contain s("}") Then
    _ss(_i) = _ss(_i).Substri ng(0, _ss(_i).IndexOf ("}"))
    _displaytext = _displayText.Re place("{" & _ss(_i) & "}",
    _datarow(_ss(_i )).ToString())
    End if
    Next

    After the split, the ellements of _ss are:
    This agreement establishes that
    BandName} will play on
    EventDate} between
    StartTime} and
    EndTime}...

    In the loop, the first element will be ignored because it doesn't contain a
    token. The other 4 elements each startwith a token because they contain a }.

    The first statement in the If ... Then ... End If block strips the } and all
    the following text from the token so that the 4 elements of interest become:
    BandName
    EventDate
    StartTime
    EndTime

    The second statement in the If ... Then ... End If block replaces the token
    in _displaytext with the required value from your datarow. Note that the {
    and } must be included in the replace for it to work properly.

    There are some issues that you will have to deal with, some of which are:

    Case-sensitivity: The name for the token MUST match the name of
    the column EXACTLY including casing.

    What if the value from the datarow required further formatting,
    e.g., dates, times, numbers etc.?

    What if the value from the datarow is blank or DbNull?

    These are rhetorical questions but they are things you must consider.

    What I have presented in not the only way of doing it by any means but it
    gives you a starting point.


    "Andy B" <a_borka@sbcglo bal.netwrote in message
    news:eo1AUTtzIH A.4876@TK2MSFTN GP04.phx.gbl...
    If I have the following text in a dataset table column: "This agreement
    establishes that {BandName} will play on {EventDate} between {StartTime}
    and {EndTime}..." How would I then take the field names {BandName},
    {StartTime}, {EndTime} and {EventDate}, match them up with actual dataset
    table column names, and show the actual values instead of the placeholders
    on the final page output? I know this would probably require some string
    parsing and stuff, but I need some good direction here. The other thing is
    that this whole thing is totally dynamic. I wont know any of the text or
    placeholder names (or table column names) in advance. These forms are
    being creating from a wizard control (including what form fields are
    used). Any ideas on where to get started?
    >

    Comment

    • Cor Ligthert[MVP]

      #3
      Re: Form field place holders in strings?

      Andy,

      As it was my problem and it was as simple like you show it, then I would
      make 3 replace statements.

      TheText = TheText.Replace ("{BandName}",T heBandName)
      etc, for the other two.

      Cor


      "Andy B" <a_borka@sbcglo bal.netschreef in bericht
      news:eo1AUTtzIH A.4876@TK2MSFTN GP04.phx.gbl...
      If I have the following text in a dataset table column: "This agreement
      establishes that {BandName} will play on {EventDate} between {StartTime}
      and {EndTime}..." How would I then take the field names {BandName},
      {StartTime}, {EndTime} and {EventDate}, match them up with actual dataset
      table column names, and show the actual values instead of the placeholders
      on the final page output? I know this would probably require some string
      parsing and stuff, but I need some good direction here. The other thing is
      that this whole thing is totally dynamic. I wont know any of the text or
      placeholder names (or table column names) in advance. These forms are
      being creating from a wizard control (including what form fields are
      used). Any ideas on where to get started?
      >

      Comment

      • Stephany Young

        #4
        Re: Form field place holders in strings?

        Read Andy's penultimate sentence again!

        "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
        news:67B0F02F-F46C-4A49-A96E-C6E665B3B112@mi crosoft.com...
        Andy,
        >
        As it was my problem and it was as simple like you show it, then I would
        make 3 replace statements.
        >
        TheText = TheText.Replace ("{BandName}",T heBandName)
        etc, for the other two.
        >
        Cor
        >
        >
        "Andy B" <a_borka@sbcglo bal.netschreef in bericht
        news:eo1AUTtzIH A.4876@TK2MSFTN GP04.phx.gbl...
        >If I have the following text in a dataset table column: "This agreement
        >establishes that {BandName} will play on {EventDate} between {StartTime}
        >and {EndTime}..." How would I then take the field names {BandName},
        >{StartTime}, {EndTime} and {EventDate}, match them up with actual dataset
        >table column names, and show the actual values instead of the
        >placeholders on the final page output? I know this would probably require
        >some string parsing and stuff, but I need some good direction here. The
        >other thing is that this whole thing is totally dynamic. I wont know any
        >of the text or placeholder names (or table column names) in advance.
        >These forms are being creating from a wizard control (including what form
        >fields are used). Any ideas on where to get started?
        >>
        >

        Comment

        • Cor Ligthert[MVP]

          #5
          Re: Form field place holders in strings?

          Stephany,

          It is not worse then yours, if you don't know were New Zealand is, you
          probably can go to Holland, Danmark, those two isles 2000 km east of
          Australia or other place in the world.

          Andy tells that he does not know anything, therefore I gave him a start as I
          would start.

          Although I often used IndexOf (kind of javascript background), I would not
          use it here.

          Cor

          "Stephany Young" <noone@localhos tschreef in bericht
          news:e7JbZouzIH A.5816@TK2MSFTN GP02.phx.gbl...
          Read Andy's penultimate sentence again!
          >
          "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
          news:67B0F02F-F46C-4A49-A96E-C6E665B3B112@mi crosoft.com...
          >Andy,
          >>
          >As it was my problem and it was as simple like you show it, then I would
          >make 3 replace statements.
          >>
          >TheText = TheText.Replace ("{BandName}",T heBandName)
          >etc, for the other two.
          >>
          >Cor
          >>
          >>
          >"Andy B" <a_borka@sbcglo bal.netschreef in bericht
          >news:eo1AUTtzI HA.4876@TK2MSFT NGP04.phx.gbl.. .
          >>If I have the following text in a dataset table column: "This agreement
          >>establishes that {BandName} will play on {EventDate} between {StartTime}
          >>and {EndTime}..." How would I then take the field names {BandName},
          >>{StartTime} , {EndTime} and {EventDate}, match them up with actual
          >>dataset table column names, and show the actual values instead of the
          >>placeholder s on the final page output? I know this would probably
          >>require some string parsing and stuff, but I need some good direction
          >>here. The other thing is that this whole thing is totally dynamic. I
          >>wont know any of the text or placeholder names (or table column names)
          >>in advance. These forms are being creating from a wizard control
          >>(including what form fields are used). Any ideas on where to get
          >>started?
          >>>
          >>
          >

          Comment

          • Stephany Young

            #6
            Re: Form field place holders in strings?

            You must have got some really bad grass today!

            Since when have Holland, Danmrak (sic) been isles and since when have they
            been 2000 Km east of Australia.

            He stated very clearly that he does NOT know, at design-time, what the
            tokens will be nor does he know, at design-time, the names of the columns in
            the datatable that relate to the tokens.


            "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
            news:280A907F-ABC1-4C0A-902C-3891EAC58DFA@mi crosoft.com...
            Stephany,
            >
            It is not worse then yours, if you don't know were New Zealand is, you
            probably can go to Holland, Danmark, those two isles 2000 km east of
            Australia or other place in the world.
            >
            Andy tells that he does not know anything, therefore I gave him a start as
            I would start.
            >
            Although I often used IndexOf (kind of javascript background), I would not
            use it here.
            >
            Cor
            >
            "Stephany Young" <noone@localhos tschreef in bericht
            news:e7JbZouzIH A.5816@TK2MSFTN GP02.phx.gbl...
            >Read Andy's penultimate sentence again!
            >>
            >"Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
            >news:67B0F02 F-F46C-4A49-A96E-C6E665B3B112@mi crosoft.com...
            >>Andy,
            >>>
            >>As it was my problem and it was as simple like you show it, then I
            >>would make 3 replace statements.
            >>>
            >>TheText = TheText.Replace ("{BandName}",T heBandName)
            >>etc, for the other two.
            >>>
            >>Cor
            >>>
            >>>
            >>"Andy B" <a_borka@sbcglo bal.netschreef in bericht
            >>news:eo1AUTtz IHA.4876@TK2MSF TNGP04.phx.gbl. ..
            >>>If I have the following text in a dataset table column: "This agreement
            >>>establishe s that {BandName} will play on {EventDate} between
            >>>{StartTime } and {EndTime}..." How would I then take the field names
            >>>{BandName} , {StartTime}, {EndTime} and {EventDate}, match them up with
            >>>actual dataset table column names, and show the actual values instead
            >>>of the placeholders on the final page output? I know this would
            >>>probably require some string parsing and stuff, but I need some good
            >>>direction here. The other thing is that this whole thing is totally
            >>>dynamic. I wont know any of the text or placeholder names (or table
            >>>column names) in advance. These forms are being creating from a wizard
            >>>control (including what form fields are used). Any ideas on where to
            >>>get started?
            >>>>
            >>>
            >>
            >

            Comment

            • Cor Ligthert[MVP]

              #7
              Re: Form field place holders in strings?

              Ignoring your bad humor to day, he does not even know it there any {} in it,
              so your solution does not work as well.

              Otherwise it is of course Regex.

              Cor

              "Stephany Young" <noone@localhos tschreef in bericht
              news:uSejGHvzIH A.1772@TK2MSFTN GP03.phx.gbl...
              You must have got some really bad grass today!
              >
              Since when have Holland, Danmrak (sic) been isles and since when have they
              been 2000 Km east of Australia.
              >
              He stated very clearly that he does NOT know, at design-time, what the
              tokens will be nor does he know, at design-time, the names of the columns
              in the datatable that relate to the tokens.
              >
              >
              "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
              news:280A907F-ABC1-4C0A-902C-3891EAC58DFA@mi crosoft.com...
              >Stephany,
              >>
              >It is not worse then yours, if you don't know were New Zealand is, you
              >probably can go to Holland, Danmark, those two isles 2000 km east of
              >Australia or other place in the world.
              >>
              >Andy tells that he does not know anything, therefore I gave him a start
              >as I would start.
              >>
              >Although I often used IndexOf (kind of javascript background), I would
              >not use it here.
              >>
              >Cor
              >>
              >"Stephany Young" <noone@localhos tschreef in bericht
              >news:e7JbZouzI HA.5816@TK2MSFT NGP02.phx.gbl.. .
              >>Read Andy's penultimate sentence again!
              >>>
              >>"Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
              >>news:67B0F0 2F-F46C-4A49-A96E-C6E665B3B112@mi crosoft.com...
              >>>Andy,
              >>>>
              >>>As it was my problem and it was as simple like you show it, then I
              >>>would make 3 replace statements.
              >>>>
              >>>TheText = TheText.Replace ("{BandName}",T heBandName)
              >>>etc, for the other two.
              >>>>
              >>>Cor
              >>>>
              >>>>
              >>>"Andy B" <a_borka@sbcglo bal.netschreef in bericht
              >>>news:eo1AUTt zIHA.4876@TK2MS FTNGP04.phx.gbl ...
              >>>>If I have the following text in a dataset table column: "This
              >>>>agreement establishes that {BandName} will play on {EventDate} between
              >>>>{StartTim e} and {EndTime}..." How would I then take the field names
              >>>>{BandName }, {StartTime}, {EndTime} and {EventDate}, match them up with
              >>>>actual dataset table column names, and show the actual values instead
              >>>>of the placeholders on the final page output? I know this would
              >>>>probably require some string parsing and stuff, but I need some good
              >>>>direction here. The other thing is that this whole thing is totally
              >>>>dynamic. I wont know any of the text or placeholder names (or table
              >>>>column names) in advance. These forms are being creating from a wizard
              >>>>control (including what form fields are used). Any ideas on where to
              >>>>get started?
              >>>>>
              >>>>
              >>>
              >>
              >

              Comment

              • Stephany Young

                #8
                Re: Form field place holders in strings?

                It will work perfectly well if there are no tokens in it!


                "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                news:9A5B954D-18DC-4DC6-B1F2-B98B50F4CB29@mi crosoft.com...
                Ignoring your bad humor to day, he does not even know it there any {} in
                it, so your solution does not work as well.
                >
                Otherwise it is of course Regex.
                >
                Cor
                >
                "Stephany Young" <noone@localhos tschreef in bericht
                news:uSejGHvzIH A.1772@TK2MSFTN GP03.phx.gbl...
                >You must have got some really bad grass today!
                >>
                >Since when have Holland, Danmrak (sic) been isles and since when have
                >they been 2000 Km east of Australia.
                >>
                >He stated very clearly that he does NOT know, at design-time, what the
                >tokens will be nor does he know, at design-time, the names of the columns
                >in the datatable that relate to the tokens.
                >>
                >>
                >"Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                >news:280A907 F-ABC1-4C0A-902C-3891EAC58DFA@mi crosoft.com...
                >>Stephany,
                >>>
                >>It is not worse then yours, if you don't know were New Zealand is, you
                >>probably can go to Holland, Danmark, those two isles 2000 km east of
                >>Australia or other place in the world.
                >>>
                >>Andy tells that he does not know anything, therefore I gave him a start
                >>as I would start.
                >>>
                >>Although I often used IndexOf (kind of javascript background), I would
                >>not use it here.
                >>>
                >>Cor
                >>>
                >>"Stephany Young" <noone@localhos tschreef in bericht
                >>news:e7JbZouz IHA.5816@TK2MSF TNGP02.phx.gbl. ..
                >>>Read Andy's penultimate sentence again!
                >>>>
                >>>"Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                >>>news:67B0F02 F-F46C-4A49-A96E-C6E665B3B112@mi crosoft.com...
                >>>>Andy,
                >>>>>
                >>>>As it was my problem and it was as simple like you show it, then I
                >>>>would make 3 replace statements.
                >>>>>
                >>>>TheText = TheText.Replace ("{BandName}",T heBandName)
                >>>>etc, for the other two.
                >>>>>
                >>>>Cor
                >>>>>
                >>>>>
                >>>>"Andy B" <a_borka@sbcglo bal.netschreef in bericht
                >>>>news:eo1AUT tzIHA.4876@TK2M SFTNGP04.phx.gb l...
                >>>>>If I have the following text in a dataset table column: "This
                >>>>>agreemen t establishes that {BandName} will play on {EventDate}
                >>>>>between {StartTime} and {EndTime}..." How would I then take the field
                >>>>>names {BandName}, {StartTime}, {EndTime} and {EventDate}, match them
                >>>>>up with actual dataset table column names, and show the actual values
                >>>>>instead of the placeholders on the final page output? I know this
                >>>>>would probably require some string parsing and stuff, but I need some
                >>>>>good direction here. The other thing is that this whole thing is
                >>>>>totally dynamic. I wont know any of the text or placeholder names (or
                >>>>>table column names) in advance. These forms are being creating from a
                >>>>>wizard control (including what form fields are used). Any ideas on
                >>>>>where to get started?
                >>>>>>
                >>>>>
                >>>>
                >>>
                >>
                >

                Comment

                • Steve Gerrard

                  #9
                  Re: Form field place holders in strings?

                  Cor Ligthert[MVP] wrote:
                  Andy,
                  >
                  As it was my problem and it was as simple like you show it, then I
                  would make 3 replace statements.
                  >
                  TheText = TheText.Replace ("{BandName}",T heBandName)
                  etc, for the other two.
                  >
                  Cor
                  >
                  >
                  If you had a datarow and did not know the column names at design time, you could
                  loop through the columns, using the above as a template:

                  Private Sub FillFields(ByVa l TheText As String, ByVal TheData As DataRow)
                  Dim DC As DataColumn

                  For Each DC In TheData.Table.C olumns
                  TheText = TheText.Replace ("{" + DC.ColumnName + "}",
                  TheData.Item(DC ).ToString)
                  Next DC

                  End Sub



                  Comment

                  • Andy B

                    #10
                    Re: Form field place holders in strings?

                    Hi.

                    I have a question related to your example steeve. How would you actually
                    determine if there are any {token} elements in the text of a particular text
                    string? What I have to do, is to go through all of the text sections and
                    determine if there are any token elements. If there are token elements,
                    replace them with the actual column values. We have this part covered so
                    far. If there are no token elements in the text strings, just append the
                    "form fields" that have been created already at the end of the string values
                    (like an attached form for a contract for service). Do you think this is a
                    good way of doing things? Or should I just create a whole other creation
                    wizard just for this type of form? I don't really know if there would be a
                    ton of overhead, since only 2 people will have access to this feature set
                    and it isn't expected to be used a whole lot as it is anyways. Tnx for the
                    help already given and the help in advance...


                    "Steve Gerrard" <mynamehere@com cast.netwrote in message
                    news:I5SdnWwFV8 fepcjVnZ2dnUVZ_ gidnZ2d@comcast .com...
                    Cor Ligthert[MVP] wrote:
                    >Andy,
                    >>
                    >As it was my problem and it was as simple like you show it, then I
                    >would make 3 replace statements.
                    >>
                    >TheText = TheText.Replace ("{BandName}",T heBandName)
                    >etc, for the other two.
                    >>
                    >Cor
                    >>
                    >>
                    >
                    If you had a datarow and did not know the column names at design time, you
                    could loop through the columns, using the above as a template:
                    >
                    Private Sub FillFields(ByVa l TheText As String, ByVal TheData As DataRow)
                    Dim DC As DataColumn
                    >
                    For Each DC In TheData.Table.C olumns
                    TheText = TheText.Replace ("{" + DC.ColumnName + "}",
                    TheData.Item(DC ).ToString)
                    Next DC
                    >
                    End Sub
                    >
                    >
                    >

                    Comment

                    • Steve Gerrard

                      #11
                      Re: Form field place holders in strings?

                      If the strings are not too long, I see nothing wrong with doing something like
                      Dim TheOriginal As String = TheText

                      ' do the substitution loop here...

                      ' now see if it changed

                      If TheText = TheOriginal Then
                      ' nothing was changed, do alternative
                      ' perhaps another loop through,
                      ' appending the field values instead:
                      TheText += vbCrLf + TheData.Item(DC ).ToString
                      ' or whatever you want/need
                      End If


                      Andy B wrote:
                      Hi.
                      >
                      I have a question related to your example steeve. How would you
                      actually determine if there are any {token} elements in the text of a
                      particular text string? What I have to do, is to go through all of
                      the text sections and determine if there are any token elements. If
                      there are token elements, replace them with the actual column values.
                      We have this part covered so far. If there are no token elements in
                      the text strings, just append the "form fields" that have been
                      created already at the end of the string values (like an attached
                      form for a contract for service). Do you think this is a good way of
                      doing things? Or should I just create a whole other creation wizard
                      just for this type of form? I don't really know if there would be a
                      ton of overhead, since only 2 people will have access to this feature
                      set and it isn't expected to be used a whole lot as it is anyways.
                      Tnx for the help already given and the help in advance...
                      >
                      "Steve Gerrard" <mynamehere@com cast.netwrote in message
                      news:I5SdnWwFV8 fepcjVnZ2dnUVZ_ gidnZ2d@comcast .com...
                      >>
                      >If you had a datarow and did not know the column names at design
                      >time, you could loop through the columns, using the above as a
                      >template: Private Sub FillFields(ByVa l TheText As String, ByVal TheData As
                      >DataRow) Dim DC As DataColumn
                      >>
                      >For Each DC In TheData.Table.C olumns
                      > TheText = TheText.Replace ("{" + DC.ColumnName + "}",
                      >TheData.Item(D C).ToString)
                      >Next DC
                      >>
                      >End Sub

                      Comment

                      Working...