none
how to pass value to the a variable? RRS feed

  • Question

  • Hi , I am creating a chat like application where I need to send and receive message. Also I need my program to remember the conversation even when I change the recipient. The problem is when I change the recipients the conversation disappear. Please see my codes below:

    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 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

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

    Thank you in advance to your help.

    Wednesday, May 10, 2017 8:24 AM

Answers

  • Hello Bhelle,

    First of all put in top of your code Option Strict On

    Then use for concatenating strings the string concatenation & and not the +

    But there is no need to use that you can use the IO Path combine method

    https://msdn.microsoft.com/en-us/library/system.io.path.combine(v=vs.110).aspx

    As well you use the ToString the DateTime Method, I doubt that it will go. I assume you can use Now there which you have first set to a string (otherwise the milliseconds ticks on and can give differences)

    As last, I assume that the message MainDisplay.Clear is not clever in your code. 


    Success
    Cor

    • Marked as answer by Bhelle Wednesday, May 10, 2017 11:07 PM
    Wednesday, May 10, 2017 8:40 AM

All replies

  • Hello Bhelle,

    First of all put in top of your code Option Strict On

    Then use for concatenating strings the string concatenation & and not the +

    But there is no need to use that you can use the IO Path combine method

    https://msdn.microsoft.com/en-us/library/system.io.path.combine(v=vs.110).aspx

    As well you use the ToString the DateTime Method, I doubt that it will go. I assume you can use Now there which you have first set to a string (otherwise the milliseconds ticks on and can give differences)

    As last, I assume that the message MainDisplay.Clear is not clever in your code. 


    Success
    Cor

    • Marked as answer by Bhelle Wednesday, May 10, 2017 11:07 PM
    Wednesday, May 10, 2017 8:40 AM
  • The problem is when I change the recipients the conversation disappear.

    For the code you have posted, what is a 'conversation'?  Is it the contents of a file, or something that is happening elsewhere else in the code?   What is the code that 'changes' a recipient?

    Wednesday, May 10, 2017 9:01 AM