473,387 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Check focus of text box

I am reading data from a serial port using the DataReceived event from the
COM control. I need to check which text box has the focus on the form so I
can call the right function. As you can see in my code below I want to
check for the focus. The problem I have is I get a cross thread error when
trying to do this. Is there any way to modify this code so I can check
which control has focus so I can call the right function? Since it is
possible on the form to have move than one item receive data from COM 1 (a
digital scale), I need to know which weight they are sending. Any help is
much appreciated.

John Wright

Code:
Private Sub SerialTare_DataReceived(ByVal sender As Object, ByVal e As
System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialTare.DataReceived

'check which textbox has the focus and then call the right method

If txtTareWeight.Focus = True Then

'check the tare weight field. If there is something there than add the data
to the run weight

txtTareWeight.Invoke(New myDelegate(AddressOf GetTransferWeight))

ElseIf txtEvalWeight.Focus = True Then

txtEvalWeight.Invoke(New myDelegate(AddressOf GetTransferWeight))

End If

End Sub
Jun 27 '08 #1
1 1964
You have to invoke SerialTare_DataReceived

I usually have a line that says:

if me.InvokeRequired then
'Use delegate to invoke sub
else
'do work
end sub
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form...
4
by: Scott Navarre | last post by:
Hi, I have Red Hat 8.0 and have the default Mozilla browser that comes with it. I am programming in javascript and have come across something problematic. Given the following code: <HTML>...
4
by: LRW | last post by:
Very basic, very simple, but I can't get a checkbox to check when the value of a text field changes to something greater than 0. Here's what I have: THE JAVASCRIPT: <script...
9
by: Roger Withnell | last post by:
Tearing hair out time! Simple attached page shows the problem. http://www.brilley.co.uk/TestFocusSelect.htm Using a function to test if too many characters have been keyed in to a textarea....
5
by: orahm | last post by:
I have 2 textboxes and one button and I don't know why my code doesn't work. All I'm trying to do is write a number 1 into the textbox with the focus. so if the user puts the cursor in textBox1 and...
2
by: Yoshitha | last post by:
In my webform i have 2 textbox controls and one button control. in 1st textbox control i'll enter email id when it lost its focus i've tocheck whether the entered email id exist in...
6
by: Jack | last post by:
I have a main webpage that has a list of records, each with a link to a window.open function call. As an example, a page that opens is editrecord.aspx?RecordID=34, and another is...
5
by: eyoung | last post by:
I have a function to check a string to make sure it is 6 digites using the trigger onBlur="CkFrmt(this)" Problem is I've got 4 fields in a row...if I enter a wrong number in the first and hit tab...
4
geo039
by: geo039 | last post by:
I tried to write a simple application that takes user input by text and time selected by date time picker. It displays the appt description in one list box and the time in another list box. I wrote...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.