|
Well, you're code skips a few things, like checking if e actually has a value to format. You also don't tell the DGV that you applied formatting to the value, and you don't do any error checking in case a non-numeric value is passed in to your column.
Private Sub MyDataGrid2_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCelLFormattingEventArgs) Handles MyDataGrid2.CellFormatting
' Only apply formatting to a value that exists...
If e.Value IsNot Nothing Then
If e.ColumnIndex = 2 Then
' Format the value to 2 decimal places using culturally-aware format.
e.Value = String.Format("{0:N2}", e.Value)
e.FormattingApplied = True
End If
End If
End Sub
I didn't both with any error trapping in this example. I leave that as an excersize to you.
|
|
|
|
|
Thank You Very....Very....Much To You !
Those remote connections,etc...from .net I learned from you...!
All Your Guidences....Gave Great Knowledge to improve myself.....!
You have to live good, Dave..!
My Best Wishes From
PARAMU
|
|
|
|
|
Dear All,
I do not know asp or c#. i just use visual basic.
now i develop an application in order to send mail with attach file to multiple recipience.
I take some sample code from websites for study as well but it still can not.
my code is:
With Mail
.From = New System.Net.Mail.MailAddress(mFrom.Trim, pDisplayName)
.To.Add(mTo.Trim)
.Priority = pPriority
.IsBodyHtml = pIsBodyHtml
If mCC <> "" Then .CC.Add(mCC.Trim)
If mBCC <> "" Then .Bcc.Add(mBCC.Trim)
.Subject = CStr(mSubject).Trim
.Body = mBody.Trim
.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
End With
Smtp.Host = CStr("mail.company.com")
Smtp.Port = 888
Dim myCredential As New System.Net.NetworkCredential("golden.meas", "gggggggggg")
Smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
Smtp.Credentials = myCredential
Smtp.Send(Mail)
End With
================
After i sent i can not know weather it success or not.
I test to send to my friend mail but can not know weather is success or not and we do not get.
what any sold for this ? And do you have any source code related it ?
Thanks for your help...
Best regards,
VB.Net
|
|
|
|
|
Have a look ! Just I found in MSDN, Answered by Martin, also it will save the mail message as textfile.
Imports System.Net.Mail
Imports System.IO
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mailInstance As MailMessage = New MailMessage("FromMailAdress", "ToMailAdress")
Try
mailInstance.Subject = "This is mail subject"
mailInstance.Body = "This is mail body content"
mailInstance.Attachments.Add(New Attachment("filename")) 'Optional
Dim mailSenderInstance As SmtpClient = New SmtpClient("smtpHostAdress", 25) '25 is the port of the SMTP host
mailSenderInstance.Credentials = New System.Net.NetworkCredential("LoginAccout", "Password")
mailSenderInstance.Send(mailInstance)
mailInstance.Dispose() 'Please remember to dispose this object
Catch ex As Exception
MessageBox.Show(ex.Message)
Dim sw As StreamWriter = New StreamWriter(My.Computer.FileSystem.SpecialDirectories.Desktop & "\myMail.txt")
sw.WriteLine(mailInstance.From)
sw.WriteLine(mailInstance.To)
sw.WriteLine(mailInstance.Subject)
sw.WriteLine(mailInstance.Body)
sw.WriteLine(mailInstance.Attachments)
sw.Close()
End Try
End Sub
|
|
|
|
|
Thanks Paramu,
In that source is send to only one mail right ?
it seems to me that it has no Cc and Bcc.
If I would like to send to multiple recipienceand
,Cc,Bcc and with attach multiple files, what should i do?
On the other hand when i test to send it by this code which copy from you:
Imports System.Net.Mail
Imports System.IO
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mailInstance As MailMessage = New MailMessage("MyEmailAddress", "RecipienceAddress")
Try
mailInstance.Subject = Trim(Me.txtSubject.Text)
mailInstance.Body = Trim(Me.txtBody.Text)
mailInstance.Attachments.Add(New Attachment("D:\11112009204.jpg"))
Dim mailSenderInstance As SmtpClient = New SmtpClient("mail.tmic.com.kh", 587)
mailSenderInstance.Credentials = New System.Net.NetworkCredential("myLongAccount", "MyPassowrd")
mailSenderInstance.Send(mailInstance)
mailInstance.Dispose() 'Please remember to dispose this object
Catch ex As Exception
MessageBox.Show(ex.Message)
Dim sw As StreamWriter = New StreamWriter(My.Computer.FileSystem.SpecialDirectories.Desktop & "\myMail.txt")
sw.WriteLine(mailInstance.From)
sw.WriteLine(mailInstance.To)
sw.WriteLine(mailInstance.Subject)
sw.WriteLine(mailInstance.Body)
sw.WriteLine(mailInstance.Attachments)
sw.Close()
End Try
End Sub
It got message error that "Syntax error in parameters or arguments. The server response was: Authentication failed: malformed response"
what is that problem ?
VB.Net
modified on Tuesday, December 8, 2009 9:44 PM
|
|
|
|
|
Dear All,
I need help regarding , i want to save a csv file into sql 2000 database in a single field as image datatype using VB6.0 , how should i proceed i m not getting it.
Parag
|
|
|
|
|
By using ADO, there's an example on uploading files here[^].
Good luck
I are Troll
|
|
|
|
|
This works only if i want to upload image but when i try to upload csv/excel/pdf/audio file then it gives error at LoadFileFrom command as "file could not be open."
Parag
|
|
|
|
|
Parag Raibagkar wrote: This works only if i want to upload image
Wrong. An image is nothing but a stream of bytes, just like any other file. If you give the LoadFromFile method just the filename, it's assuming that the file is in whatever the CurrentDriectory is. Instead of trying to change the current directory, give the LoadFromFile method the fully qualified path to the file you're trying to upload into the database.
|
|
|
|
|
I have an application using multithreading to read and parse a stream of data from the serial port into packets and extract information out of it to be displayed by the main thread using DirectX interface.
The application is working properly etc, but the thread that reads and parses the com port information is utilising close to 100% cpu usage which is rather annoying me and im not sure what to do about it...a fragment of the code is posted below:
Packets are streamed from the device at 100ms intervals, and the program can't afford to back buffer as the information it is displaying needs to be live, nor can it miss a packet as it needs to check each packet for a particular condition that doesnt get repeated once it occurs...
Public Sub CommReadThread()
Dim bByte As Byte, bPacket(73) As Byte, lResult As Long, tsData As TimeSpan
Try
LinkDev = New SerialPort("COM1", 19200)
LinkDev.Open()
Catch ex As Exception
MsgBox("COM ERROR: " & ex.Message)
Exit Sub
End Try
While bStop = False
tsData = DateTime.Now.Subtract(_iLastData)
CommIdleTime = tsData.TotalMilliseconds
CommBufferSize = LinkDev.BytesToRead
'If no data received for period, flag as disconnected
If CommIdleTime >= _dataTiemout Then
bIsConnected = False
Else
bIsConnected = True
End If
If CommBufferSize > 0 Then
If iFFCount = 2 Then
'found a header, read the rest of the packet
If CommBufferSize >= 70 Then
lResult = LinkDev.Read(bPacket, 0, 70)
_iLastData = DateTime.Now
'Build the packet putting the header back in there for processing
For x As Integer = UBound(bPacket) To 2 Step -1
bPacket(x) = bPacket(x - 2)
Next
bPacket(0) = &HFF
bPacket(1) = &HFF
bPacket(2) = &HFF
LinkPacket = New Packet(bPacket)
'...do packet processing, the New function of the packet class processes it...
LinkPacket = Nothing
iFFCount = 0
End If
Else
'Find a header in the data stream
bByte = LinkDev.ReadByte()
_iLastData = DateTime.Now
If iFFCount > 0 Then
If Hex(bByte) <> "FF" Then
iFFCount = 0
End If
End If
If Hex(bByte) = "FF" Then
iFFCount += 1
End If
End If
End If
End While
End Sub
modified on Monday, December 7, 2009 6:59 AM
|
|
|
|
|
Have you looked at using the DataReceived event? From what I can see of your code here, it looks as if you are just whizzing round in a while loop constantly checking to see if there is anything to read from the port. So you are burning up CPU time doing nothing. The DataReceived event means that you can sit and wait and do nothing until something is ready to read from the port, then you grab it and process it. That might help.
|
|
|
|
|
yeah i was using that before...its just the header of the packet can be anywhere in the stream and the stream is constant thats all...working on extracting the individual packets was proving interesting...hence why i went with this approach...
find the header, wait until the entire packet is in the buffer and read it in, find the next header, wait for the packet...and so on...
|
|
|
|
|
Well, if you have a constant stream then DataReceived probably won't help because there will always be something to read. If you have a constant stream of data to read and parse, I'm not sure what else you can do except throttle back the rate at which you're reading it.
I suppose you could sleep the thread for a few milliseconds before reading from the port if you don't find a header. I don't know the exact requirements for your application, but would it really be that big a deal if there was a 10 millisecond delay before a message header was processed? Actually, even if you specify Sleep(0) immediately before the read it might help because it will yield the thread and give other threads a chance to cut in and do some processing. It's a bit clunky but it would reduce the amount of CPU time the thread is using.
|
|
|
|
|
sorry I'm not reading your code unless you edit it and put it in PRE tags, resulting in proper coloring and indentation.
[ADDED] you should not have polling loops without delays, so when no data is available, waste some time by calling Thread.Sleep(30); or use events. And watch for incomplete packets! [/ADDED]
modified on Monday, December 7, 2009 7:31 AM
|
|
|
|
|
honestly if that's how you feel, then don't read it, simple, I really don't need to know u don't want to read my code, thanks for letting me know tho...its in CODE tags at the moment but i'll change it to PRE...
to be honest I diddn't realise it diddn't indent as I don't post on here too often...a simple "hey, try using the PRE tags instead of CODE tags and your code should indent properly and will be easier for people to read" wouldn't really be be so hard would it? its probably even less characters to type...
|
|
|
|
|
the fix is simple, and much shorter than your above message. However I'm not sure you are really interested, as you downvoted my previous message. Making code readable is the first step to solving problems, and me asking and you adding PRE tags did help. I think I'll wait for you to change your vote.
|
|
|
|
|
Luc Pattyn wrote: as you downvoted my previous message
I balanced it.
Best wishes,
Navaneeth
|
|
|
|
|
|
I need to know how to be able to type a quotation mark into a text box in Visual Basic 2008.
like so...
TextBox1.Text = "[a href=""]LINK[/a]"
Had to substitute the < and > for [ and ].
That is a bad example, because I've already gotten that to work for me... but like how to get the Quotes after the href= to show up in the textbox.
|
|
|
|
|
You already did it. VB.NET uses two double-quote marks to escape one. So, this:
TextBox1.Text = "<a href="""">LINK</a>"
will show this in the textbox:
<a href="">LINK</a>
|
|
|
|
|
I have two form :
class form1 'parent form
dim number as integer
public sub create ()
dim f2 as new form2
f2.MdiParent = me
f2.show()
end sub
public sub test()
end sub
endclass
In form2.vb how to use variable number and method test
thank you very much
Regards
|
|
|
|
|
If "test" is an event handler, you should be using a delegate to handle the event in other forms. If it a method that provides some common functionality, it should be placed in a separate class file, something like "Common.vb" and should be placed there. There you can have it as an internal static or an internal method to call it in any of the forms in your application.
You can make the method internal in the MDI parent itself and access it in the child using Me.MDIParent property.
To access the variable number, you can make use of a internal/public property and can access it using me.MDIParent again.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
In Form1:
Public number As Integer
In Form2:
Form1.Test()
Debug.Writeline(Form1.number.ToString)
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
|
This is a graduation project and you're asking us for the code to solve a problem?? You don't really deserve to graduate then, do you?
If you can't dig around in your brain and write the code yourself, what good is your degree then?
|
|
|
|