 |
|
 |
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers, Chris Maunder
The Code Project Co-founder Microsoft C++ MVP
|
| Sign In·View Thread·PermaLink | 3.67/5 |
|
|
|
 |
|
 |
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers, Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
| Sign In·View Thread·PermaLink | 4.40/5 |
|
|
|
 |
|
 |
Hi all , i'm creating a chat lan and i have one problem with the encoding. for example : i send the text "leão" to other chat . At other chat recept "leão" for send i can use the "system.text.encoding.UTF32" but to recept i can't convert . With know how to resolve this problem please help me.
i'll post the code where :
at from = "chat"
Imports System.Text Imports System.Net.Sockets
Public Class Chat
Public ipbox As String = "localhost" Public portbox As String = "5090" Dim TextEnter As New TextBox Dim TextSender As New TextBox
Public Delegate Sub DisplayInvoker(ByVal t As String) Private Declare Function FlashWindow Lib "user32" _ (ByVal hwnd As Long, _ ByVal bInvert As Long) As Long
Dim a As String Dim b As String Dim hrs, secs, mins As Integer Dim f As Integer
Private myclient As TcpClient Private mydata(1024) As Byte Private mytext As New StringBuilder() Public mainClient As String
Private Sub Send(ByVal t As String) On Error Resume Next Dim w As New IO.StreamWriter(myclient.GetStream) w.Write(t & vbCr, & System.Text.Encoding.UTF32) w.Flush() End Sub
Private Sub DoRead(ByVal ar As IAsyncResult) Dim intCount As Integer
Try intCount = myclient.GetStream.EndRead(ar) If intCount < 1 Then chatbox.AppendText("Disconnected" & vbCrLf) Exit Sub End If
BuildString(mydata, 0, intCount)
myclient.GetStream.BeginRead(mydata, 0, 1024, AddressOf DoRead, Nothing) Catch e As Exception End Try End Sub
Private Sub BuildString(ByVal Bytes() As Byte, ByVal offset As Integer, ByVal count As Integer) Dim intIndex As Integer
For intIndex = offset To offset + count - 1 If Bytes(intIndex) = 10 Then mytext.Append(vbLf)
Dim params() As Object = {mytext.ToString} Me.Invoke(New DisplayInvoker(AddressOf Me.DisplayText), params)
mytext = New StringBuilder() Else mytext.Append(ChrW(Bytes(intIndex))) End If Next End Sub
Private Sub DisplayText(ByVal t As String)
If LSet(t, 5) = "clear" Then friendsbox.Items.Clear() chatbox.AppendText("") Else If LSet(t, 7) = "client:" Then f = len(t) b = (Strings.Right(t, f - 7)) friendsbox.Items.Add(Strings.Left(b, Len(b) - 2), 0) chatbox.AppendText("") Else If LSet(t, 8) = "closenow" Or LSet(t, 5) = "User:" Then chatbox.AppendText("") Else t.Replace("<BR>", vbCrLf) chatbox.AppendText(t) FlashWindow(Me.Handle.ToInt64, True) End If
End If End If End Sub
Private Sub sendbox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles sendbox.KeyDown If e.KeyCode = Keys.Return Then btnEnviar.PerformClick()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick secs = secs + 1 GroupBox1.Text = "Conectado a : " & hrs & ":" & mins & ":" & secs If secs = 60 Then mins = mins + 1 secs = 0 End If If mins = 60 Then hrs = hrs + 1 mins = 0 End If
End Sub
Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed Send("closenow" & a) End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles friendsbox.SelectedIndexChanged
End Sub
Private Sub btnSair_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Close() End Sub
Private Sub PortAndIPToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PortAndIPToolStripMenuItem.Click
End Sub
Private Sub DisconectarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisconectarToolStripMenuItem.Click Send("closenow" & a) chatbox.AppendText("Disconnected" & vbCrLf) sendbox.Enabled = False Timer1.Enabled = False GroupBox1.Text = "00:00:00" DisconectarToolStripMenuItem.Visible = False End Sub
Private Sub Chat_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Send("closenow" & a)
End Sub
Private Sub Chat_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If ipbox <> "" And portbox <> "" Then chatbox.AppendText("Requesting Connection..." & vbCrLf) On Error GoTo 10 ipbox = InputBox("Digite o IP", "Digite o IP")
myclient = New TcpClient(ipbox, portbox) myclient.GetStream.BeginRead(mydata, 0, 1024, AddressOf DoRead, Nothing) GroupBox1.Text = "Requesting Connection..." chatbox.AppendText("Connected..." & vbCrLf) chatbox.AppendText("------------------------------------------------------------------------------" & vbCrLf) ChatGroupBox.Text = "Chat - Conectado ao IP : " & ipbox & " - Porta : " & portbox Timer1.Enabled = True a = InputBox("Enter Nickname:", "Chat 2003") If a = "" Then MessageBox.Show("Digite um Nick") Close() Else Send("User:" & a) sendbox.Enabled = True DisconectarToolStripMenuItem.Visible = True End If
End If 10: If sendbox.Enabled = False Then chatbox.AppendText("Unable to resolve to Server...Please try again") End If mainClient = ""
sendbox.Select() End Sub
Private Sub SairToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SairToolStripMenuItem.Click Send("closenow" & a) Close() End Sub
Private Sub btnEnviar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnviar.Click If sendbox.Text = "" Then sendbox.Text = ""
Else Dim text As String = sendbox.Text
text = sendbox.Text.Replace(vbCr, "<BR>") text = Replace(text, vbLf, "") text = text.Trim(" ")
Send(a & " - disse: " & text) Chr(8) sendbox.Clear() sendbox.Select()
End If
End Sub
----------------------------
i have one class for convertion :
Imports System.Net.Sockets Imports System.Text Public Class Client
Public Event Connected(ByVal sender As Client) Public Event Disconnected(ByVal sender As Client) Public Event LineReceived(ByVal sender As Client, ByVal Data As String)
Private mgID As Guid = Guid.NewGuid Private marData(1024) As Byte Private mobjText As New StringBuilder()
Private mobjClient As TcpClient Private mobjSocket As Socket
Public Sub New(ByVal s As Socket) mobjSocket = s RaiseEvent Connected(Me) mobjSocket.BeginReceive(marData, 0, 1024, SocketFlags.None, AddressOf DoReceive, Nothing) End Sub
Public Sub New(ByVal client As TcpClient) mobjClient = client RaiseEvent Connected(Me) mobjClient.GetStream.BeginRead(marData, 0, 1024, AddressOf DoStreamReceive, Nothing) End Sub
Public ReadOnly Property ID() As String Get Return mgID.ToString End Get End Property
Private Sub DoStreamReceive(ByVal ar As IAsyncResult) Dim intCount As Integer
Try SyncLock mobjClient.GetStream intCount = mobjClient.GetStream.EndRead(ar) End SyncLock If intCount < 1 Then RaiseEvent Disconnected(Me) Exit Sub End If
BuildString(marData, 0, intCount) SyncLock mobjClient.GetStream mobjClient.GetStream.BeginRead(marData, 0, 1024, AddressOf DoStreamReceive, Nothing) End SyncLock Catch e As Exception RaiseEvent Disconnected(Me) End Try End Sub
Private Sub DoReceive(ByVal ar As IAsyncResult) Dim intCount As Integer
Try intCount = mobjSocket.EndReceive(ar) If intCount < 1 Then RaiseEvent Disconnected(Me) Exit Sub End If
BuildString(marData, 0, intCount)
mobjSocket.BeginReceive(marData, 0, 1024, SocketFlags.None, AddressOf DoReceive, Nothing) Catch e As Exception RaiseEvent Disconnected(Me) End Try End Sub
Private Function ByteToString(ByVal Bytes() As Byte) As String Dim objSB As New System.Text.StringBuilder(UBound(Bytes) + 1) Dim intIndex As Integer
With objSB For intIndex = 0 To UBound(Bytes) .Append(ChrW(Bytes(intIndex))) Next Return .ToString End With End Function
Private Function ByteToString(ByVal Bytes() As Byte, ByVal offset As Integer, ByVal count As Integer) As String Dim objSB As New System.Text.StringBuilder(count) Dim intIndex As Integer
With objSB For intIndex = offset To offset + count - 1 .Append(ChrW(Bytes(intIndex))) Next Return .ToString End With End Function
Private Sub BuildString(ByVal Bytes() As Byte, ByVal offset As Integer, ByVal count As Integer) Dim intIndex As Integer
For intIndex = offset To offset + count - 1 If Bytes(intIndex) = 13 Then RaiseEvent LineReceived(Me, mobjText.ToString) mobjText = New StringBuilder() Else mobjText.Append(ChrW(Bytes(intIndex))) End If Next End Sub
Public Sub Send(ByVal Data As String) If IsNothing(mobjClient) Then Dim arData(Len(Data) - 1) As Byte Dim intIndex As Integer
For intIndex = 1 To Len(Data) arData(intIndex - 1) = Asc(Mid(Data, intIndex, 1)) Next
mobjSocket.BeginSend(arData, 0, Len(Data), SocketFlags.None, Nothing, Nothing) Else SyncLock mobjClient.GetStream Dim w As New IO.StreamWriter(mobjClient.GetStream) w.Write(Data) w.Flush() End SyncLock End If End Sub
Public Sub Send(ByVal Data() As Byte, ByVal offset As Integer, ByVal count As Integer) If IsNothing(mobjClient) Then mobjSocket.BeginSend(Data, offset, count, SocketFlags.None, Nothing, Nothing) Else SyncLock mobjClient.GetStream mobjClient.GetStream.BeginWrite(Data, offset, count, Nothing, Nothing) End SyncLock End If End Sub
End Class
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Has anybody seen a full implementation for a date(time) class/struct in C#?
I don't need this for a project or anything (the built in one seems adequate for dealing with date and time constructs for business apps). However, I have a friend who is trying to pick up some of the more arcane OO concepts in C# and I thought such an example might give good coverage of operator overloading, serialization, etc. I had to do one way back in the day with C++, so I thought something similar might be a handy way of explaining the same concepts to him.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
I used reflector to browse through the DateTime code a while back. You could always use that.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes. My blog | My articles | MoXAML PowerToys | Onyx
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi all,
I dont know in which forum i have to post this issue. If i am wrong please guide me to post in which form
I am developing a vb.net desktop application that reads mails from the mailserver using pop and imap .
The application is almost fnished .The problem is the some time when a command is send to retrieve a mail using GetMessage() functions the applications is going to a halt
So I tried to run the the code in debug mode and ran line by line . What I noticed is in the while loop in GetMessage() function is
While Not tmpString.StartsWith(sPrefix) tmpString = reader.ReadLine msg = msg & tmpString & vbCrLf End While
The reader reads line by line at certain point of time it got hangs
Some times it ill catch an exception and give an error . I am pasting the exception below "Received an unexpected EOF or 0 bytes from the transport stream"
But some times the applications will hang and go for a halt .This applications has to run 24/7 .So if it hangs in the night or it will be problem .
What I want is if the reader is not able to read from the stream after certain time period . the control has to be removed from the reader and the function has to return a message . I am new to this the network level applications and I am running shot of time So I am in big trouble . If anybody knows this problem please help me
I have pasted the code briefly so that you can get an idea about the program
Dim objTCP As New TcpClient Dim sslstream As Net.Security.SslStream Dim reader As StreamReader = Nothing objTCP.Connect(IMAPserver, Port)
sslstream = New Net.Security.SslStream(objTCP.GetStream()) sslstream.AuthenticateAsClient(IMAPserver) ' authenticate as client GMAIL AuthStatus = sslstream.IsAuthenticated reader = New IO.StreamReader(sslstream)
Function GetMessage(ByVal sCommand As String, ByVal sslstream As SslStream, ByVal reader As StreamReader) As String Dim tmpString As String = "" Dim msg As String = "" Try
sendcmd(sCommand, sslstream) tmpString = reader.ReadLine() If tmpString <> "" Then msg = msg & tmpString & vbCrLf End If While Not tmpString.StartsWith(sPrefix) tmpString = reader.ReadLine msg = msg & tmpString & vbCrLf End While If InStr(msg, "BAD Could not parse command") > 0 Then 'MsgBox("BAD GETMESSAGE") End If Catch ex As Exception appendFile(strErrPath, "Error in GetMessage, BAD command : command : " & sCommand & Space(3) * "User: " & UserName & ex.Message & Date.Now) End Try
Return msg End Function
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi I have to create a windows application which can connect to a remote host through SSH and can perform some operations on the remote host. remote host is a cisco router 3745 Problem I am facing is which ssh client to use and how to use in the application. If anybody knw please update me @ himanshu_agarwal@live.com / himanshu.agarwal@gmail.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi.,
How to print a crystal report in a dotmatrix printer using vb.net code and printing should be fast?
Any ideas...
Thanks & Regards Raj
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hi Raj
You can use 12dpi fonts, all your crytal report contents to be printed should be in 12 dpi font.
These fonts are added to windows fonts once you install Dot matrix printer drivers.
if these fonts are used printing will be faster compared to windows fonts
cheers saleem
cc
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I would like to know if is there any parameter which let me ask for confirmation of the Mail arrival using System.Net.Mail and the sender SMTPClient.
modified on Thursday, November 19, 2009 7:47 AM
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
|
 |
|
 |
You need to refactorize the incoming param list, and possible invoke the method if concurrency is required, also create a method extension this will help during execution of the object.
Hope this helps. Further help can be found in the correct programing forum - which I'm sure you will find - assuming you have the aptitude to program computers.
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
|
 |
|
 |
While the above suggestions are all perfectly valid, you may want to consider calling Reflector programmatically with parameters for each version of the .Net Framework. This will give you the option of seeing what your options are for a variety of deployment scenarios.
Once you do that, you can then use Reflector to dynamically decompile System.Net.Mail into usable code which you can then modify to suit your needs.
One such modification you'll want to make sure you do before proceeding any further would be to create a hash structure so that you can easily ascertain whether or not you've already sent an email. Naturally, this hash structure should be built to serialize to the hard disk when memory consumption is too high. This will reduce your overall network overhead and improve your performance.
Trust me, your manager will thank you just for following those 3 simple steps.
Visual Studio is an excellent GUIIDE.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
What your a masochist. You've been here a while and asked some sensible questions in the C# forum and suddenly you do a Don Juan and tilt a programming question at the Lounge, consider yourself SMACKED, now go back to the C# forum and ask this question.
Ahhh I enjoyed that, we don't get enough of these misplaced questions any more.
Never underestimate the power of human stupidity RAH
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Ahh bugger CP moved it. They are taking our targets away, I think we need to protest this.....
Never underestimate the power of human stupidity RAH
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Ok, here is the problem that drives me nuts.
I have a datagrid with various data.The first column is the date of the record and it's a string.
The following code gives the error
tempor=Month(dgv1(0, counter).Value.ToString)
On my PC the code works flawlessly.But when i give the application to someone else for BETA testing, it produces the error.
Does it make sense to you ? I also tried all the variation to the code, i could think of, like using cdate and cstr functions, changing the type of the tempor variable to date, string, using the .string or not at the ende of the code, to no avail
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Johnkokk wrote: Does it make sense to you ?
Not exactly; your title says you are converting from the string "18/8/2009", but your code is converting something ToString(). Can you clarify a bit more what is in dgv1(0,counter)?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
The field of the datagrid contains "18/8/2009".This is a string. I am trying to get the month part of this date.
On my computer whatever i try WORKS. On the other PC whatever i have tried, DOES NOT. Even if i don't put the .string, DOES NOT work on the BETA tester.
To make it simple.How do i get the month part of the above field to use as an index in an array ?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Τhe problem seems to be the regional setting of the other pc, which are different than mine.If they are change to the same as mine, it works Hmmmmm
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
you could split the string ( string.Split() ) and then take the second index of a string array, then you have the number of the month, maybe you could work with that?
Here we rest... So why not make the best of it? 
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |