PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 12, 2022

[FIXED] Why does when I append the textbox value to the new message it gives me incorrect display?

 July 12, 2022     append, chat, concatenation, message, vb.net     No comments   

Issue

I wish to append the message of the sender and the message of the receiver. However when I used

Me.MainDisplay.Text = Me.MainDisplay.Text & MessageToDisplay & Environment.NewLine 

The messages do not append instead it displays incorrectly. For example I send

1
2
3

it will display

1
1
2
1
2
3

I intend my program to display what I have sent and add to the list the next message that I will be sending or the message that the receiver will reply. Please help.

For your further reference you may refer to the below codes:

For Each filename In SortedFilenames
    If filename.Folder = "User" Then
        RecipientFolder = "C:\Users\bele\Desktop\" + CurrentUser + "'sInbox\" + CurrentRecipient + "'sFolder\"
    ElseIf filename.Folder = "Recipient" Then
        RecipientFolder = "C:\Users\bele\Desktop\" + CurrentRecipient + "'sInbox\" + CurrentUser + "'sFolder\"
    End If

    FileContents = My.Computer.FileSystem.ReadAllText(RecipientFolder + filename.Id.ToString("MMddyyyyhhmmss") + ".txt")

    If MessageToDisplay = "" Then
        If filename.Folder = "User" Then
            MessageToDisplay = CurrentRecipient + ": " + FileContents + Environment.NewLine + filename.Id.ToString("MM/dd/yyyy hh:mm:ss")
        ElseIf filename.Folder = "Recipient" Then
            MessageToDisplay = CurrentUser + ": " + FileContents + Environment.NewLine + filename.Id.ToString("MM/dd/yyyy hh:mm:ss")
        End If

    Else
        If filename.Folder = "User" Then
            MessageToDisplay = MessageToDisplay + Environment.NewLine + CurrentRecipient + ": " + FileContents + Environment.NewLine + filename.Id.ToString("MM/dd/yyyy hh:mm:ss")
        ElseIf filename.Folder = "Recipient" Then
            MessageToDisplay = MessageToDisplay + Environment.NewLine + CurrentUser + ": " + FileContents + Environment.NewLine + filename.Id.ToString("MM/dd/yyyy hh:mm:ss")
        End If

    End If
    Me.MainDisplay.Text = Me.MainDisplay.Text + MessageToDisplay & Environment.NewLine

    My.Computer.FileSystem.MoveFile(RecipientFolder + filename.Id.ToString("MMddyyyyhhmmss") + ".txt",
                                    "C:\Users\bele\Desktop\" + User + "'sInbox\" + User + "'sReadMessage\" & filename.Id.ToString("MMddyyyyhhmmss") + ".txt")
Next

Please help


Solution

Change:

If MessageToDisplay = "" Then
    If filename.Folder = "User" Then
        MessageToDisplay = CurrentRecipient + ": " + FileContents + Environment.NewLine + filename.Id.ToString("MM/dd/yyyy hh:mm:ss")
    ElseIf filename.Folder = "Recipient" Then
        MessageToDisplay = CurrentUser + ": " + FileContents + Environment.NewLine + filename.Id.ToString("MM/dd/yyyy hh:mm:ss")
    End If

Else
    If filename.Folder = "User" Then
        MessageToDisplay = MessageToDisplay + Environment.NewLine + CurrentRecipient + ": " + FileContents + Environment.NewLine + filename.Id.ToString("MM/dd/yyyy hh:mm:ss")
    ElseIf filename.Folder = "Recipient" Then
        MessageToDisplay = MessageToDisplay + Environment.NewLine + CurrentUser + ": " + FileContents + Environment.NewLine + filename.Id.ToString("MM/dd/yyyy hh:mm:ss")
    End If

End If
Me.MainDisplay.Text = Me.MainDisplay.Text + MessageToDisplay & Environment.NewLine

To:

If filename.Folder = "User" Then
    MessageToDisplay = CurrentRecipient + ": " + FileContents + Environment.NewLine + filename.Id.ToString("MM/dd/yyyy hh:mm:ss")
ElseIf filename.Folder = "Recipient" Then
    MessageToDisplay = CurrentUser + ": " + FileContents + Environment.NewLine + filename.Id.ToString("MM/dd/yyyy hh:mm:ss")
End If

Me.MainDisplay.Text = Me.MainDisplay.Text + MessageToDisplay & Environment.NewLine


Answered By - Idle_Mind
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing