-
Feb 2nd, 2018, 06:52 AM
#1
Thread Starter
New Member
[RESOLVED] Commands in chat
Hello , I have a chat program based on ftp . I want to make commands , I mean when someone type for example /help than it will show commands that he can type ,but it will show to him only . How can I make it?
-
Feb 2nd, 2018, 03:54 PM
#2
Re: Commands in chat
Welcome to VBForums
When the user enters text, check if it matches one of your commands... if it does then act on it appropriately, otherwise send the text as normal.
How you act on the commands will obviously vary, but in terms of the /help you would just show the information you want to (in whatever way you want).
Give it a try, and if you want more detailed help then show us the relevant code (not the entire project) and let us know what issue(s) you are having at that point (including error messages if apt).
-
Feb 3rd, 2018, 04:36 PM
#3
Thread Starter
New Member
Re: Commands in chat
Thanks , in my chat I have a timer that has this code :
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Yenileyici.Tick
Try
Dim client As New Net.WebClient
client.Credentials = New Net.NetworkCredential("FTP USERNAME", "FTP PASSWORD")
TextBox2.Text = client.DownloadString("ftp://username@ftphost/chat.txt")
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
And this timer gets the chat.txt text from ftp server and show it in TextBox2.Text .
I have a send button and I add some code like this :
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim username As String
username = TextBox1.Text
Dim time As Date = TimeOfDay
Dim symbol As String
symbol = Label4.Text
Try
Dim client As New Net.WebClient
client.Credentials = New Net.NetworkCredential("FTP USERNAME", "FTP PASSWORD")
client.UploadString("ftp://username@ftphost/chat.txt", TextBox2.Text & time & symbol & "* " & username & " " & " : " & " " & RichTextBox2.Text + vbNewLine)
Catch ex As Exception
MsgBox(Err.Description)
End Try
RichTextBox2.Text = ""
If RichTextBox2.Text = "/help" Then
TextBox2.Text = TextBox2.Text + vbNewLine & "/about - about program" + vbNewLine & "/online - online list"
ElseIf RichTextBox2.Text = "/espiri" Then
TextBox2.Text = TextBox2.Text + vbNewLine & "It's a test"
End If
End Sub
But the timer renew textbox2 text . How can I make sure that the commands will appear in Textbox2 but only in users chat??
Last edited by si_the_geek; Feb 3rd, 2018 at 06:39 PM.
Reason: added Code tags
-
Feb 3rd, 2018, 06:39 PM
#4
Re: Commands in chat
The checks you have at the end of Button1_Click need to be moved to the start of it, and the rest of the code needs to be put into an Else block at the end of the checks.
The issues with the textbox being cleared by the timer are more awkward, but I'm afraid it's getting late here and I don't have time at the moment... hopefully I'll post again tomorrow.
-
Feb 4th, 2018, 10:34 AM
#5
Thread Starter
New Member
Re: Commands in chat
First things first , thanks . I made it /help works I replaced /help code with message sending code :
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RichTextBox2.Text = "/help" Then
TextBox2.Text = TextBox2.Text + vbNewLine + "-----*-----" + vbNewLine + "/about - about program" + vbNewLine + "/online - online list" + vbNewLine
ElseIf RichTextBox2.Text = "/about" Then
RichTextBox2.Text = ""
TextBox2.Text = TextBox2.Text + vbNewLine + "Test" + vbNewLine
End If
Dim username As String
username = TextBox1.Text
Dim time As Date = TimeOfDay
Dim symbol As String
symbol = Label4.Text
Try
Dim client As New Net.WebClient
client.Credentials = New Net.NetworkCredential("FTP USERNAME", "FTP PASSWORD")
client.UploadString("ftp://username@ftphost/chat.txt", TextBox2.Text & time & symbol & "* " & username & " " & " : " & " " & RichTextBox2.Text + vbNewLine)
Catch ex As Exception
MsgBox(Err.Description)
End Try
RichTextBox2.Text = ""
End Sub
It works ,but everyone can see it , the application sends message to ftp server . How can I make that it will show to person only ?
Last edited by LegacyDev; Feb 4th, 2018 at 03:45 PM.
-
Feb 4th, 2018, 04:19 PM
#6
Re: Commands in chat
As I mentioned in my previous post (and hinted at in my earlier post): "the rest of the code needs to be put into an Else block at the end of the checks."
So your code should be like this:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RichTextBox2.Text = "/help" Then
TextBox2.Text = TextBox2.Text + vbNewLine + "-----*-----" + vbNewLine + "/about - about program" + vbNewLine + "/online - online list" + vbNewLine
ElseIf RichTextBox2.Text = "/about" Then
RichTextBox2.Text = ""
TextBox2.Text = TextBox2.Text + vbNewLine + "Test" + vbNewLine
Else
Dim username As String
username = TextBox1.Text
Dim time As Date = TimeOfDay
Dim symbol As String
symbol = Label4.Text
Try
Dim client As New Net.WebClient
client.Credentials = New Net.NetworkCredential("FTP USERNAME", "FTP PASSWORD")
client.UploadString("ftp://username@ftphost/chat.txt", TextBox2.Text & time & symbol & "* " & username & " " & " : " & " " & RichTextBox2.Text + vbNewLine)
Catch ex As Exception
MsgBox(Err.Description)
End Try
End If
RichTextBox2.Text = ""
End Sub
-
Feb 5th, 2018, 08:25 AM
#7
Thread Starter
New Member
Re: Commands in chat
I think I'm tired of you , but there is one more thing . Every thing is ok ,but when you type /help and then press the button it's shows the message and then it's disappear . I think that because of timer (I post its code on previous posts) , but is there a way to make that it won't disappear.
-
Feb 6th, 2018, 11:28 AM
#8
Thread Starter
New Member
Re: Commands in chat
Well , I solved problem . I just created new button that's shows a new form which contains command prompt . There is another question for it I want to make a command /music ,but I want to when person enters /music + music name it will play music(There is space between /music and music name and music name is only word.) . Please help me with code!. You can take a MUSICNAME as example for music .
-
Feb 6th, 2018, 01:22 PM
#9
Re: Commands in chat
The String class has various methods you can use, including .StartsWith to check if the start of the string matches something you specify, eg:
Code:
If RichTextBox2.Text.StartsWith("/music ") Then
You can use .SubString() to find the text after the space.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|