|
Oops, just noticed that the file expired... hehe :/
Here is a more recent build: Cick Here, again[^]
|
|
|
|
|
|
You seriously expect us to run an exe file from the web?
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
How about a portable version instead of the NSIS installer. Portable
modified 3-Sep-16 7:27am.
|
|
|
|
|
Hello!
In my data entry form, all the fields are bound to a tblStaff table through BindingSource (staffInfoBS).
One of these controls is a cboGender ComboBox.
I want to manually populate the cboGender with only two items -- "Male" and "Female" and the SelectedValue be saved in the underlying table.
If I try to use something like Items.Insert, I receive error:
Items collection cannot be modified when the DataSource property is set.
How can get it done. Please suggest.
|
|
|
|
|
You either have to have items in the datasource that your combo seems to be bound to or you have to scrap the binding on the combo and put the items in yourself. You can't have both.
|
|
|
|
|
I'm having problems with sending email using CBeyond from all of my programs in VB.
So I decided to change my send function to SendAsync, and Async, and just send each message 1 at at a time and wait for the results so it can be logged when done. (Thus the SQLite Question earlier)
So I thought this would be pretty easy, just change SmtpClient.Send(mailMessage) to smtpClient.SendAsync(mailMessage, cancelToken), but I guess now I need to add a callback.
So I got some ideas from this link, and used some of the concepts.
The part I don't understand is calling the function, and setting the Public Event for the callback.
c# - Send email when using SmtpClient - Stack Overflow[^]
I c#, the code is this, but I have no clue what it is, it's beyond my c# skills.
var sender = new EmailSender();
sender.SendEmailCompleted += (o, eventArgs)
=> Console.WriteLine(eventArgs.RetryCount);
sender.SendEmailAsync(new MailMessage(), 5);
And I translated it using CodeTranslator CodeTranslator: Code Translation From VB.NET
I'm looking at it and I have no clue what it is, I only recognize the first and last lines.
Dim sender As var = New EmailSender
sender.SendEmailCompleted = (sender.SendEmailCompleted + o)
,eventArgs
Unknown=GreaterConsole.WriteLine(eventArgs.RetryCount)
sender.SendEmailAsync(New MailMessage, 5)
This is what I wrote from the C# example in the web page link. I'm pretty sure I got it right and updated some of the event handlers.
Imports System.ComponentModel
Imports System.Net.Mail
Public Class SendEngine
Private _currentRetryCount As Integer
Private _maxRetryCount As Integer
Private _mailMessage As MailMessage
Private _isAlreadyRun As Boolean
Public Event SendEmailCompleted As SendEmailCompletedEventHandler
Public Sub SendEmailAsync(ByVal smtpClient As SmtpClient, ByVal message As MailMessage, ByVal retryCount As Integer)
If _isAlreadyRun Then
Throw New InvalidOperationException("sendEngine doesn't support multiple concurrent invocations.")
End If
_isAlreadyRun = True
_maxRetryCount = retryCount
_mailMessage = message
AddHandler smtpClient.SendCompleted, AddressOf SmtpClientSendCompleted
SendMessage(smtpClient)
End Sub
Private Sub SendMessage(ByVal smtpClient As SmtpClient)
Try
smtpClient.SendAsync(_mailMessage, Guid.NewGuid)
Catch exception As Exception
EndProcessing(smtpClient)
End Try
End Sub
Private Sub EndProcessing(ByVal smtpClient As SmtpClient)
If (_mailMessage IsNot Nothing) Then
_mailMessage.Dispose()
End If
If (smtpClient IsNot Nothing) Then
RemoveHandler smtpClient.SendCompleted, AddressOf SmtpClientSendCompleted
smtpClient.Dispose()
End If
OnSendCompleted(New SendEmailCompletedEventArgs(Nothing, False, Nothing, _currentRetryCount))
_isAlreadyRun = False
_currentRetryCount = 0
End Sub
Private Sub SmtpClientSendCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
Dim smtpClient = CType(sender, SmtpClient)
If ((e.Error Is Nothing) OrElse (_currentRetryCount >= _maxRetryCount)) Then
EndProcessing(smtpClient)
Else
_currentRetryCount = (_currentRetryCount + 1)
SendMessage(smtpClient)
End If
End Sub
Protected Overridable Sub OnSendCompleted(ByVal args As SendEmailCompletedEventArgs)
RaiseEvent SendEmailCompleted(Me, args)
End Sub
End Class
Public Delegate Sub SendEmailCompletedEventHandler(ByVal sender As Object, ByVal e As SendEmailCompletedEventArgs)
Public Class SendEmailCompletedEventArgs
Inherits AsyncCompletedEventArgs
Private mRetryCount As Integer
Public Sub New(ByVal ex As Exception, ByVal canceled As Boolean, ByVal userState As Object, ByVal retryCount As Integer)
MyBase.New(ex, canceled, userState)
retryCount = retryCount
End Sub
Public Property RetryCount As Integer
Get
Return mRetryCount
End Get
Set(value As Integer)
value = mRetryCount
End Set
End Property
End Class
modified 13-May-16 3:00am.
|
|
|
|
|
The code translator seems to have screwed up the event handler. The C# code:
sender.SendEmailCompleted += (o, eventArgs)
=> Console.WriteLine(eventArgs.RetryCount);
would translate as something like this:
AddHandler sender.SendEmailCompleted, Sub(ByVal sender As Object, ByVal e As SendEmailCompletedEventArgs)
Console.WriteLine(eventArgs.RetryCount)
End Sub
If you're using .NET 4.5 or later, I'd be inclined to use an Async[^] method, and use the SmtpClient.SendMailAsync method[^]:
Public Async Function SendEmailAsync(ByVal smtpClient As SmtpClient, ByVal message As MailMessage, ByVal retryCount As Integer) As Task(Of SendEmailCompletedEventArgs)
Dim currentTry As Integer = 0
While currentTry < retryCount
Try
Await smtpClient.SendMailAsync(message)
Return New SendEmailCompletedEventArgs(Nothing, False, Nothing, currentTry)
Catch exception As Exception
currentTry += 1
If currentTry >= retryCount Then
Return New SendEmailCompletedEventArgs(ex, True, Nothing, currentTry)
End If
End Try
End While
Return New SendEmailCompletedEventArgs(Nothing, True, Nothing, currentTry)
End Function
Your calling code can then use a Using block to clean up the SmtpClient and MailMessage instances:
Public Async Function SendAllMessages() As Task
Using smtpClient As SmtpClient = CreateSmtpClient()
For Each item As SomeType In SomeListOfData
Using message As MailMessage = CreateMessageFor(item)
Dim result As SendEmailCompletedEventArgs = Await SendEmailAsync(smtpClient, message, RetryCount)
ProcessSendResult(item, result)
End Using
Next
End Using
End Function
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I knew it was a handler with the +=, but had no idea it was a sub call, Thanks!
I was thinking last night how to handle the smtpclient with using so it can release it resources.
I have a dialog that loops the collection of jobs in a listview, that generates a PDF attachment and then composes the message via await. In the composer function, it calls the SendMessage which is not await. I need to rethink that. It's OK to await again?
I didn't want to pollute my composition function with the Send Function and separated them.
Well, I'll add the handler and give it a spin, and then work on using the smtpclient.
Thanks Richard! and Upvote
for each job in jobs
Await Compose
next
Function Compose()
Build Message
Attach PDF
Build smtpClient
Send
Log send error
End Function
Function Send
SendAsync
End Function
|
|
|
|
|
jkirkerx wrote: It's OK to await again?
Yes, awaiting from within an async method that's been awaited is perfectly fine.
You might want to add .ConfigureAwait(False) to the awaited expressions, where the remainder of the method doesn't need to execute in the same context:
Await smtpClient.SendMailAsync(message).ConfigureAwait(False)
Async/Await - Best Practices in Asynchronous Programming[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
OK, I understand.
Well, so far in code I got what I wanted out of it. I just need to log the error in the database so I can conclude that the email was sent to the Cbeyond mail servers, and it's out of my hands.
'This is the new sendEngine
Dim sE As New SendEngine()
sE.SendEmailAsync(smtpClient, mailMessage, 5)
AddHandler sE.SendEmailCompleted, _
Sub(sender As Object, e As SendEmailCompletedEventArgs)
Console.WriteLine(e.Error)
If (e.Error IsNot Nothing) Then
model.Error_Text = e.Error.HResult
model.Error_Text = e.Error.Message.ToString
model.TimeStamp_Error = DateTime.Now()
ef_model_smtp_resend.Write_Smtp_Send_Record(model)
End If
End Sub
Thanks for the help Richard!
It would of taken me days to figure out the handler.
|
|
|
|
|
Hi.
How do you check to see the full length of a string coming from a RS232 port and how to 'TRIM" unwanted characters?
Thanks in advance.
|
|
|
|
|
The same way you do with any string from any provider. When reading from an external source (RS232, TCP/IP etc.) you need the source to also provide information as to the length of the string. Either by delimiters, meta information or similar means.
|
|
|
|
|
Depends on how you read it.
In VB you should generally do something like:
com1 = My.Computer.Ports.OpenSerialPort("COM1")
com1.ReadTimeout = 10000
Do
Dim Incoming As String = com1.ReadLine()
If Incoming Is Nothing Then
Exit Do
Else
returnStr &= Incoming & vbCrLf
End If
Incoming is just a string - you can trim, replace chars etc to suit.
ReadLine reads from the serial port, until the first newline char.
Do another ReadLine to get the next bit.
Alternatives:
ReadChar - reads one character
ReadByte - ditto for one byte
ReadTo - Read up to a given char
ReadExisting - Read whatever is in port buffer
This is a good tutorial on how to do serial port comms in VB: http://www.me.umn.edu/courses/me2011/smartprodcourse/technotes/docs/serial-port-vb.pdf[^]
|
|
|
|
|
Thanks Robert and Richard. Will give it a go this weekend.
|
|
|
|
|
I see what you mean. I am programming for a weight scale but can't get the "Tare" values from the indicator. I've read the user manual but can't get get the code to work when the Tare button is pressed on the indicator. Any help will be much appreciated.
|
|
|
|
|
Gus:
I did a lot of code interfacing with industrial weight scales back in the late nineties (with VB6).
I did have some generic routines that would talk good with most scales out there. Among the places my code was running was a cheese factory (small scales - a few kilos), and a fertilizer depot (big scales - 15 ton trucks).
Not sure if I can find that code now (nearly 20 years later).
Post the code you use, and the scale brand and model - I will have a look
|
|
|
|
|
Hi Robert.
The indicator is a XK3101(N). I have found this code to guide me in the right direction but can't get it to work the way I want it.
Public Class Form1
Dim myport As Array
Dim strWeight As String
Public Delegate Sub myDel(ByVal txtBox As TextBox)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
myport = SerialPort.GetPortNames
AddHandler SerialPort1.DataReceived, AddressOf SerialPort1_DataReceived
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
txtBox.Invoke(New myDel(AddressOf UpdateTextBox), New Object() {txtBox})
End Sub
Public Sub UpdateTextBox(ByVal UpDateTextBox As TextBox)
Dim bytes As Integer = SerialPort1.BytesToRead
Dim Buffer(bytes) As Byte
SerialPort1.Read(Buffer, 0, bytes)
strWeight = System.Text.Encoding.Default.GetString(Buffer)
txtBox.AppendText(strWeight)
GetTareandWeight(strWeight)
End Sub
Private Sub GetTareandWeight(ByVal weight As String)
Dim strWeights() As String
Dim newWeight As String = Replace(weight, " ", " ")
strWeights = Split(weight, ",")
txtBox2.Text &= newWeight & vbCrLf
txtBox2.Text &= strWeights.Length.ToString & vbCrLf
txtBox2.Text &= "Tare: " & strWeights(1).ToString
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
SerialPort1.PortName = "COM5"
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Open()
SerialPort1.Write(vbCr)
End Sub
If I can get it to work, I will have to incorporate it into my main program. I get the weight readings but gives an error when I press the Tare button on the indicator. Hope you can help. I got the manual but can't put a picture here. Hope you can help.
|
|
|
|
|
Gus:
Some comments on that code:
(a) It looks like it is working. You have defined an event handler for receiving data from the serial port. You "get the weight readings", so we know that event handler works.
(b) The "GetTareAndWeight" code tells me that the scale sends both Weight and Tare in the same string.
Something like "10.3, 2.0".
This must be working when you "get weight readings" - otherwise it would crash with an array error.
(c) After receiving a weight txtBox2 (a multiline textbox) should look something like this:
"10.3, 2.0"
"2"
"Tare: 2.0"
(d) If your code received a string containing Tare only, ie, "2.0", then it will crash in "GetTareAndWeight" on the line 'txtBox2.Text &= "Tare: " & strWeights(1).ToString'
Question for you Gus:
"gives an error when I press the Tare button on the indicator". What is the error?
|
|
|
|
|
Hi Robert.
The error occurs at the line: txtBox2.Text &= "Tare: " & strWeight(1).ToString with error message; IndexOutOfRangeException was unhandled by user code. Index was outside the bounds of the array. How would I go about to fix the code?
|
|
|
|
|
I have changed the code a bit but now there is no output in txtBox2 but the the error message when I open the port.
|
|
|
|
|
Gus:
I think you can see that you have a simple array error. The compiler seems to have been quite clear about that.
I suggest that you resolve that array error.
The code will then work fine.
I cannot help you any further with this issue Gus.
|
|
|
|
|
Hello,
I am automating the outlook using vb.net using
Microsoft.Office.Interop.Outlook
I want to add a unsubscribe link to the mail header.
I have done mail automation using asp.net which has option to add unsubscribe link in header
Dim Mail As New System.Net.Mail.MailMessage()
.Headers.Add("List-Unsubscribe", oModPass.OurunsubscribeMailId)
But this is not working in outlook.
Is there any alternatives for '.header.add' in 'Microsoft.Office.Interop.Outlook'
In simple I want to add a link as shown in this link
Google Images[^]
Please help.
|
|
|
|
|
According to this StackOverflow thread[^], something like this should work:
Public Sub AddCustomHeader(ByVal mail As MailItem, ByVal headerName As String, ByVal headerValue As String)
Dim prop As String = "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/" + headerName
mail.PropertyAccessor.SetProperty(prop, headerValue)
End Sub
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you, When users click on 'unsubscribe' what will happen ? To whom the unsubscribe notification goes ?
|
|
|
|
|