Option Explicit Private Sub Form_Load() rtbOutput.Locked = True rtbOutput.Text = "" End Sub Private Sub btnSend_Click() SendMessage End Sub Private Sub txtInput_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0 SendMessage End If End Sub Private Sub SendMessage() Dim http As Object Dim stream As Object Dim url As String Dim msg As String Dim response As String msg = txtInput.Text If msg = "" Then Exit Sub AddLine "You", msg url = "http://10.41.1.3:8543/chat?msg=" & URLEncode(msg) On Error GoTo errh Set http = CreateObject("MSXML2.XMLHTTP") http.Open "GET", url, False http.Send Set stream = CreateObject("ADODB.Stream") stream.Type = 1 stream.Open stream.Write http.responseBody stream.Position = 0 stream.Type = 2 stream.Charset = "windows-1251" response = stream.ReadText stream.Close AddLine "AI", response txtInput.Text = "" Exit Sub errh: AddLine "AI", "connection error" End Sub Private Sub AddLine(ByVal who As String, ByVal Text As String) With rtbOutput .SelStart = Len(.Text) If who = "You" Then .SelBold = True .SelColor = RGB(0, 0, 255) .SelText = "You: " .SelBold = False Else .SelBold = True .SelColor = RGB(200, 0, 0) .SelText = "AI: " .SelBold = False End If .SelColor = RGB(0, 0, 0) .SelText = Text & vbCrLf ' Автопрокрутка вниз .SelStart = Len(.Text) .SelLength = 0 End With End Sub Private Function URLEncode(ByVal Text As String) As String Dim stream As Object Dim bytes() As Byte Dim i As Long Dim result As String Set stream = CreateObject("ADODB.Stream") stream.Type = 2 stream.Charset = "utf-8" stream.Open stream.WriteText Text stream.Position = 0 stream.Type = 1 bytes = stream.Read stream.Close For i = 0 To UBound(bytes) Select Case bytes(i) Case 48 To 57, 65 To 90, 97 To 122 result = result & Chr(bytes(i)) Case 45, 46, 95, 126 result = result & Chr(bytes(i)) Case Else result = result & "%" & Right("0" & Hex(bytes(i)), 2) End Select Next i URLEncode = result End Function