|
What do you mean it doesn't work?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Ok, so the first part of code below works fine...but when I want to do the same thing, just using other cells from sheet 1 and paste into other locations on sheet 4, it doesnt work. Is there something I need to be placing between codes? Yes, I do realize I sound like an idiot.
Range("D14").Select
Selection.Copy
Sheets("Sheet4").Select
lMaxRows = Cells(Rows.Count, "E").End(xlUp).Row
Range("E" & lMaxRows + 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
lMaxRows = Cells(Rows.Count, "E").End(xlUp).Row
Range("E" & lMaxRows + 1).Select
Range("D12").Select
Selection.Copy
Sheets("Sheet4").Select
lMaxRows = Cells(Rows.Count, "D").End(xlUp).Row
Range("D" & lMaxRows + 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
lMaxRows = Cells(Rows.Count, "D").End(xlUp).Row
Range("D" & lMaxRows + 1).Select
|
|
|
|
|
It's hard to tell without being able to run it but you likely just need to selection what you want first. The second set of code does Selection.Copy so before that you need to select what you want copied.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I had a program which was working well. Suddenly it started giving errors while compiling on all the basic commands like MsgBox, Ucase, Len, Trim etc. I have found out the solution but I would like to have some reason why all these commands were working fine when I did not use the import Miscrosoft.visualbasic.
If anybody can enlighten me on this I will be obliged
|
|
|
|
|
There is an "implied" list of imports in the Project Properties. They don't show up in your code, but instead are a checkbox list in the "My Project" node, References tab, under "Imported namespaces". Microsoft.VisualBasic is usually at the top of the list if it's checked. If not, just go check it again and save.
|
|
|
|
|
|
Hello guys,
I need your guidance on how to send an e-mail notification to a list of recipients from a combo box.
I have a save button on a form that saves things into an sql database..I have a combo box that may contain e-mail of recipients.
I'd like to send an e-mail notification on the save event using the the listing from the combo box, without any popup window, just send the e-mail to that particular person.
Here is the scenario:
A form collects information about a complaint. I want an e-mail notification send out to the person who will look at the complaint information once the form is saved.
I am using vb.net on Ms Visual Studio 2010 with SQl.
All the examples I searched on the NET do not seem to be suitable for what I want to accomplish.
Thanks in advance.
|
|
|
|
|
You haven't said anything about what part of this you're having a problem with.
Sending an email is easy. There are examples of this all over the web.
Getting the selected item in a ComboBox is easy. This is just a matter of reading the documentation on the ComboBox class.
There is no "save" event, so that can't be the problem. There is a Button "click" event and really, handling a simple event like that is easy.
Soooo, what part of this is the problem?
|
|
|
|
|
I would like to know how to do a scren capture to a (png or other image format) of a panel control.
if we assume that we have a panel control and in the panel is some graphics and the background of the panel is black. I would like to capture the panel but have the back ground white.
I do want to capture everything in a specific panel control I just want it black and white.
Does anyone have a snippet that will capture the panel control in black and white
|
|
|
|
|
|
Thanks for the list of options. I have been looking at some of those already. I just can't seem to find a way to capture in monochrome.
I appreciate your help
|
|
|
|
|
That's a different issue, you need to find samples that explain how to convert colours to grayscale.
|
|
|
|
|
|
gwittlock wrote:
Ok I will look further You'll get the same answer. If you capture, you capture what is - if you want it to be monochrome, you convert it yourself, as it is not part of capturing.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I understand that. That is what a meant by looking further as in "looking further into the problem Now that I know it does not have to do with capture"
Richard MacCutchan gave me articles to look at and told me it had nothing to do with capturing. To me that was useful in getting to a resolution of my problem.
|
|
|
|
|
hi all.. second question I have put up here and still in my infancy with VB so please be nice...
Yesterday I wrote one of those simple multi-thread applications you see online where you have two buttons which trigger two counts on two separate threads..I used invoke to update the count to the UI avoiding the CheckForIllegalCrossThreadCalls bypass code..
My app behaves weirdly.. when both counts are running the UI locks out, you cannot move it anywhere. I expected the multi thread to free the UI.. and also if you trigger one of the counts again before it reaches the max, the other count lags and can sometimes stand still until the retriggered count finishes.. basically, it just doesn't work like I hoped it would..
I wrote a lot off the top of my head then checked to some online tutorials and the majority are similar so I am pretty sure my code is nearly there - just not sure about my invoke section..
im happy to post my code if someone fancies having a quick look and hopefully giving me a few pointers that would be great!
thanks for reading
tony
|
|
|
|
|
Without seeing the relevant code it's impossible to tell you what you did wrong.
|
|
|
|
|
hi dave... I didn't know if posting the code straight up was the done thing.. thought I would see if anyone would take a look first.
thanks & heres the code -
Imports System.IO
Imports System.Threading
Public Class Form1
Dim i1 As Integer
Dim i2 As Integer
Private Sub count1()
Do While i1 < 3000
i1 += 1
If Me.Label1.InvokeRequired Then
Me.Label1.Invoke(New Action(Sub() Me.Label1.Text = i1))
Me.Label1.Invoke(New Action(Sub() Me.Refresh()))
Else
Me.Label1.Text = i1
Me.Refresh()
End If
Loop
End Sub
Private Sub count2()
Do While i2 < 3000
i2 += 1
If Me.Label2.InvokeRequired Then
Me.Label2.Invoke(New Action(Sub() Me.Label2.Text = i2))
Me.Label2.Invoke(New Action(Sub() Me.Refresh()))
Else
Me.Label2.Text = i2
Me.Refresh()
End If
Loop
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
i1 = 0
Dim t As New Thread(AddressOf count1)
t.Start()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
i2 = 0
Dim t2 As New Thread(AddressOf count2)
t2.Start()
End Sub
End Class
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
EDIT -
Hi Dave.. After looking at some explanations of using delegates and invoke I have changed my code as follows.. Still doesn't work like I would expect!
Imports System.IO
Imports System.Threading
Public Class Form1
Dim i1 As Integer
Dim i2 As Integer
Private Delegate Sub SetCount1()
Private Delegate Sub SetCount2()
Private Sub count1()
Do While i1 < 100000
i1 += 1
updatecount1()
Loop
End Sub
Private Sub count2()
Do While i2 < 100000
i2 += 1
updatecount2()
Loop
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
i1 = 0
Dim t As New Thread(AddressOf count1)
t.Start()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
i2 = 0
Dim t2 As New Thread(AddressOf count2)
t2.Start()
End Sub
Private Sub updatecount1()
If Me.Label1.InvokeRequired Then
Me.Label1.Invoke(New SetCount1(AddressOf updatecount1))
Else
Me.Label1.Text = i1
Me.Refresh()
End If
End Sub
Private Sub updatecount2()
If Me.Label2.InvokeRequired Then
Me.Label2.Invoke(New SetCount2(AddressOf updatecount2))
Else
Me.Label2.Text = i2
Me.Refresh()
End If
End Sub
End Class
modified 6-May-14 9:57am.
|
|
|
|
|
OK, it doesn't work the way you think because you are essentially blocking the UI thread You are having it do thousands of updates to the UI and those updates are competing with the message pump to get the window and controls repainted.
In this example, you may as well not even use threading. The end result is the same. You're not really removing "work" from the UI thread. The only "work" you have on the background threads is incrementing a couple of counters and if statements. The bulk of the "work" is still upating the UI and only the UI thread can do that.
Oh, and you don't need to Invoke consecutive statements and the Refreshes are unnecessary. By putting the Refreshes in, you're actually doubling the number of WM_PAINT messages Windows is sending your application.
Your code should look more like this:
Imports System.Threading
Public Class Form1
Private Const MAXCOUNT As Integer = 10000
Private i1 As Integer
Private i2 As Integer
Private Sub count1()
Do While i1 < MAXCOUNT
i1 += 1
UpdateLabel(i1.ToString, Label1)
Loop
End Sub
Private Sub count2()
Do While i2 < MAXCOUNT
i2 += 1
UpdateLabel(i2.ToString, Label2)
Loop
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
i1 = 0
Dim t As New Thread(AddressOf count1)
t.Start()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
i2 = 0
Dim t2 As New Thread(AddressOf count2)
t2.Start()
End Sub
Private Sub UpdateLabel(message As String, c As Label)
If Me.InvokeRequired Then
Me.Invoke(Sub()
c.Text = message
End Sub)
Else
c.Text = message
End If
Thread.Sleep(1)
End Sub
End Class
But, wait a minute. What's with the Thread.Sleep() ? By sleeping the background threads for a tiny bit, you're preventing them from hogging the CPU and giving the UI thread a chance to process the messages in the message pump. These messages are various UI things like WM_PAINT, WM_MOVE and WM_MOUSEMOVE messages that Windows sends to tell your application to paint various windows and controls, that the window is moving, and the mouse is moving and over a control.
Like I said, if you flood the UI thread with Invokes like you did, the UI will not be able to process these messages and update the window.
|
|
|
|
|
Thank you Dave, most helpful...
Yeah I can see its overkill for the work its doing, it was more a simple exercise to try and learn something about multithreading & invoke than a need for more processing.
I guess I should be putting some effort into passing variables when calling subs so as to cut down on the coding too!
Thanks again
Tony
|
|
|
|
|
That's good. All of the concepts apply to normal applications. We normally put the work on background threads and shove all UI update work to the UI thread.
Normally, you're not updating the UI that often for what you're seeing to be a problem. The Thread.Sleep() is in there just to get the background threads in your example to back off a bit. Normally, you don't need it.
|
|
|
|
|
Thanks for the help and tips for future work...
Tony
|
|
|
|
|
Hi again Dave..
where you say - ' you don't need to Invoke consecutive statements ' how would you script an invoke in the case of needing to perform 2 separate UI updates?
Cheers
Tony
|
|
|
|
|
Private Sub UpdateLabel(message As String, c As Label)
If Me.InvokeRequired Then
Me.Invoke(Sub()
c.Text = message
otherControl.Text = something
someOtherControl.Property = soemthingElse
End Sub)
Else
c.Text = message
otherControl.Text = something
someOtherControl.Property = soemthingElse
End If
Thread.Sleep(1)
End Sub
|
|
|
|
|
A gent and a scholar!
Thanks Dave
|
|
|
|