0

I have a VB.NET application that has instant messaging-like functionality with a database. It can retrieve the values just fine, but the problem is the formatting isnt coming out right. I want the format to be as follows:

Sender: Message

(so...)

David: Hey guys

What I've tried below doesn't get me the result I'm looking for, it just prints the sender at the top of the rich textbox in my application and the message at the bottom, does anyone have any ideas?

 '-------------------Retreives the message-------------------------------------------------------------
        Dim sqlStr As String = "SELECT * FROM dojodb.chats"
        Dim chatcommand As New MySqlCommand(sqlStr, MysqlConn)
        Dim rdr As MySqlDataReader = chatcommand.ExecuteReader()
        Dim tbl As New DataTable
        tbl.Load(rdr)


        '-------For every row, print the message, skip a line, and add 1 so it goes to next msg--     ------
        For i As Integer = 0 To tbl.Rows.Count - 1
            rowIndex = i

            strSender &= CStr(tbl.Rows(rowIndex)("Sender")) & vbNewLine

            strMessage &= CStr(tbl.Rows(rowIndex)("Message")) & vbNewLine

            strOutPut = strSender + ": " + strMessage

        Next
        txtGroupChat.Text = strOutPut

        'Keeps the richtextbox scrolled to the bottom so that most recent msg is always shown
        txtGroupChat.SelectionStart = txtGroupChat.Text.Length
        txtGroupChat.ScrollToCaret()

        strOutPut = "" 'clearing the string so that it does not print out duplicate info next time
        strSender = ""
        strMessage = ""
        '-------------------------End Retrive---------------------------------------

1 Answer 1

1

I feel a bit embarrassed posting this, but...

  strSender = CStr(tbl.Rows(rowIndex)("Sender")) & ": "

  strMessage = CStr(tbl.Rows(rowIndex)("Message")) & vbNewLine

strOutPut &= strSender & strMessage

What do you think vbNewLine does? Also, be careful of &=

Sign up to request clarification or add additional context in comments.

1 Comment

Well, give us a clue then. What happens?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.