Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. vb.net using string and custom objects

vb.net using string and custom objects

Scheduled Pinned Locked Moved Visual Basic
databasecsharpsql-serversysadmin
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dcof
    wrote on last edited by
    #1

    In a vb.net 2010 application, I am trying to determine the best way to accomplish this goal. Write now 1 letter is generated and sent to one guardian. However this application needs to be changed so that the same exact letter can be send to different mailing addresses since each student may have more than one parent/guardian at different mailing addresses. So basically I want to generate more than one letter with the same wording. The only differences between the letters would be the mailingaddresses. I want the letters to be written to the same varchar(max) column in a sql server 2012 database. The letters will be in the same field since the data will be sent to a sql server reporting server where the letters will be generated one after each other.Right now the letters are written to the 'Dim _al As Letters = New Letters()' object. The only way I know to modify text data is to use a string or stringbuilder objects. I do not know yo modify data is other objects. Basically I want to use a string.replace logic to replace the addresses in the second letter. I also want to use stringbuilder.append to place more than one letter following another to be placed in the osne varchar(max) field. I know I can use the following code to convert a custom object to a string.

    Dim _LetterStr As String = String.Empty
     Dim _LetterStrbldr As StringBuilder = New StringBuilder
     _LetterStr = _Letter.Letter.ToString()

    However I do not know how to convert a string object back to a custom object. Here is the original code of the application:

    #Region "Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object,
    ByVal e As System.EventArgs) Handles btnSubmitModifiedLetter.Click"
    Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object, ByVal e
    As System.EventArgs) Handles btnSubmitModifiedLetter.Click
    Dim _al As Letters = New Letters()
    Dim _infinteCampusText As String
    Dim _Letter As Letter = New Letter()
    Dim _startDate As DateTime = Now()
    Dim _term As Integer = 0

        \_Letter.SchoolYear = \_schoolyear 
        \_Letter.Term = \_term 
        \_Letter.Milestone = ddlMilestone.SelectedValue 
        \_Letter.SchoolNumber = Right("000" & ddlSchools.SelectedValue,3) 
        \_Letter.Printed = "Y" 
        \_Letter.Letter = reLetterEditor.Content 
        \_Letter.StudentLink = Right("0000000" & txtStuLink.Text, 7) 
        \_Letter.Language = txtLanguage.Text 
    
        \_infinteCampusText = \_al.BuildText(\_Letter)
    
    L D 2 Replies Last reply
    0
    • D dcof

      In a vb.net 2010 application, I am trying to determine the best way to accomplish this goal. Write now 1 letter is generated and sent to one guardian. However this application needs to be changed so that the same exact letter can be send to different mailing addresses since each student may have more than one parent/guardian at different mailing addresses. So basically I want to generate more than one letter with the same wording. The only differences between the letters would be the mailingaddresses. I want the letters to be written to the same varchar(max) column in a sql server 2012 database. The letters will be in the same field since the data will be sent to a sql server reporting server where the letters will be generated one after each other.Right now the letters are written to the 'Dim _al As Letters = New Letters()' object. The only way I know to modify text data is to use a string or stringbuilder objects. I do not know yo modify data is other objects. Basically I want to use a string.replace logic to replace the addresses in the second letter. I also want to use stringbuilder.append to place more than one letter following another to be placed in the osne varchar(max) field. I know I can use the following code to convert a custom object to a string.

      Dim _LetterStr As String = String.Empty
       Dim _LetterStrbldr As StringBuilder = New StringBuilder
       _LetterStr = _Letter.Letter.ToString()

      However I do not know how to convert a string object back to a custom object. Here is the original code of the application:

      #Region "Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object,
      ByVal e As System.EventArgs) Handles btnSubmitModifiedLetter.Click"
      Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object, ByVal e
      As System.EventArgs) Handles btnSubmitModifiedLetter.Click
      Dim _al As Letters = New Letters()
      Dim _infinteCampusText As String
      Dim _Letter As Letter = New Letter()
      Dim _startDate As DateTime = Now()
      Dim _term As Integer = 0

          \_Letter.SchoolYear = \_schoolyear 
          \_Letter.Term = \_term 
          \_Letter.Milestone = ddlMilestone.SelectedValue 
          \_Letter.SchoolNumber = Right("000" & ddlSchools.SelectedValue,3) 
          \_Letter.Printed = "Y" 
          \_Letter.Letter = reLetterEditor.Content 
          \_Letter.StudentLink = Right("0000000" & txtStuLink.Text, 7) 
          \_Letter.Language = txtLanguage.Text 
      
          \_infinteCampusText = \_al.BuildText(\_Letter)
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Why would you need to do such a conversion? All you need is a template that contains the main text of your letter, a _Letter object that contains the different properties (name, address etc), and a subroutine that formats the data into its printed form.

      D 1 Reply Last reply
      0
      • L Lost User

        Why would you need to do such a conversion? All you need is a template that contains the main text of your letter, a _Letter object that contains the different properties (name, address etc), and a subroutine that formats the data into its printed form.

        D Offline
        D Offline
        dcof
        wrote on last edited by
        #3

        Would you show me an example of the code you are referring to? How should I convert a string object to a custom .net object?

        L D 2 Replies Last reply
        0
        • D dcof

          Would you show me an example of the code you are referring to? How should I convert a string object to a custom .net object?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Quote:

          How should I convert a string object to a custom .net object?

          No idea, the question does not really make sense, since String is already a .NET object.

          1 Reply Last reply
          0
          • D dcof

            Would you show me an example of the code you are referring to? How should I convert a string object to a custom .net object?

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Serialization?

            A guide to posting questions on CodeProject

            Click this: Asking questions is a skill. Seriously, do it.
            Dave Kreskowiak

            1 Reply Last reply
            0
            • D dcof

              In a vb.net 2010 application, I am trying to determine the best way to accomplish this goal. Write now 1 letter is generated and sent to one guardian. However this application needs to be changed so that the same exact letter can be send to different mailing addresses since each student may have more than one parent/guardian at different mailing addresses. So basically I want to generate more than one letter with the same wording. The only differences between the letters would be the mailingaddresses. I want the letters to be written to the same varchar(max) column in a sql server 2012 database. The letters will be in the same field since the data will be sent to a sql server reporting server where the letters will be generated one after each other.Right now the letters are written to the 'Dim _al As Letters = New Letters()' object. The only way I know to modify text data is to use a string or stringbuilder objects. I do not know yo modify data is other objects. Basically I want to use a string.replace logic to replace the addresses in the second letter. I also want to use stringbuilder.append to place more than one letter following another to be placed in the osne varchar(max) field. I know I can use the following code to convert a custom object to a string.

              Dim _LetterStr As String = String.Empty
               Dim _LetterStrbldr As StringBuilder = New StringBuilder
               _LetterStr = _Letter.Letter.ToString()

              However I do not know how to convert a string object back to a custom object. Here is the original code of the application:

              #Region "Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object,
              ByVal e As System.EventArgs) Handles btnSubmitModifiedLetter.Click"
              Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object, ByVal e
              As System.EventArgs) Handles btnSubmitModifiedLetter.Click
              Dim _al As Letters = New Letters()
              Dim _infinteCampusText As String
              Dim _Letter As Letter = New Letter()
              Dim _startDate As DateTime = Now()
              Dim _term As Integer = 0

                  \_Letter.SchoolYear = \_schoolyear 
                  \_Letter.Term = \_term 
                  \_Letter.Milestone = ddlMilestone.SelectedValue 
                  \_Letter.SchoolNumber = Right("000" & ddlSchools.SelectedValue,3) 
                  \_Letter.Printed = "Y" 
                  \_Letter.Letter = reLetterEditor.Content 
                  \_Letter.StudentLink = Right("0000000" & txtStuLink.Text, 7) 
                  \_Letter.Language = txtLanguage.Text 
              
                  \_infinteCampusText = \_al.BuildText(\_Letter)
              
              D Offline
              D Offline
              David Mujica
              wrote on last edited by
              #6

              I'll attempt to answer your question, but if it were me, I think I would re-design this solution. Do you really need to store the letter in the database ? Maybe create a template letter, give it a unique document ID, then you could store multiple records with the student ID, template ID and sequence number. To answer your question ... Create a class and call it LetterDetail; at a minimum it would have a string to store the letter. Create another class and call it MailedLetters; this would contain a List(Of LetterDetail) The second class gives you the ability to have as many letters as you want grouped together. Within the second class, you would need 2 methods, Save and Load. This would serialize the object to an XML string which you could then save in the database. I'll give you some rough code for serialization ...

              Public Shared Function Load(sFname As String) As MailedLetters
              Dim xr As XmlReader
              Dim settings As XmlWriterSettings = New XmlWriterSettings()
              settings.Indent = True
              settings.IndentChars = (ControlChars.Tab)
              settings.OmitXmlDeclaration = True

                  Dim obj As New MailedLetters
                  Dim mySerializer As New XmlSerializer(obj.GetType)
              
                  xr = XmlReader.Create(sFname)
              
                  obj = mySerializer.Deserialize(xr)
              
                  xr.Close()
                  xr = Nothing
              
                  Return obj
              
              End Function
              

              Instead of serializing to a file, you want to serialize it to a string.

              Sub Save(sFname As String)
              Dim xw As XmlWriter
              Dim mySerializer As New XmlSerializer(Me.GetType)
              Dim settings As XmlWriterSettings = New XmlWriterSettings()
              settings.Indent = True
              settings.IndentChars = (ControlChars.Tab)
              settings.OmitXmlDeclaration = False

                  xw = XmlWriter.Create(sFname, settings)
              
                  mySerializer.Serialize(xw, Me)
              
                  xw.Close()
              

              End Sub

              That's the best I can do for you, hope it helps. :java:

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups