?
Solved

Placing result of  a calculation into a textbox

Posted on 2005-03-17
5
Medium Priority
?
167 Views
Last Modified: 2010-04-23
I have an input form on which I have created a button which invokes a little calculator I have written to do simple arithmetic calculations.

The result in my little calculator is placed into a textbox called RESULT on the calculator form.

I would like to close my calculator and have the result stuffed into the textbox which has the focus on my  original form.

How can I get the value from the  RESULT textbox transferred to the  original textbox  which has the focus in VBNet.

(I have done this before in VB6 using a  GotFocus sub for every textbox but there must be an easier way!!)


Thanks
0
Comment
Question by:GREEBA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 13566899
dim frm as new frmCalculator
frm.showdialog
dim strResult = frm.textbox1.text

The better way to do this would be to add a public readonly Result property to your calculator that can be accessed from the parent form.
0
 
LVL 6

Expert Comment

by:ctm5
ID: 13571115
Or you could track which text box last had focus.

Private lastFocus as String

Private Sub FocusTextbox(sender as System.Object, e as System.EventArgs)

   lastFocus = sender.name

End Sub

Private Sub AddHandlers()
   AddHandler txtCalc1.Enter, AddressOf FocusTextbox
   AddHandler txtCalc2.Enter, AddressOf FocusTextbox
  ....etc.
End Sub

Call AddHandlers from the main program block. Then any time one of the textboxes is Entered, its name becomes the value of lastFocus. A Select statement after you finish with the calculator will tell you where to dump the result.

0
 

Author Comment

by:GREEBA
ID: 13576480
To ctm5

I've tried it out and it seems it will give me what I want. Could you tell me what you mean by your last sentence
"A select statement... tell you where to dump the result." I don't know what this means. I've increased the points
value for your help.

Thanks
0
 
LVL 6

Accepted Solution

by:
ctm5 earned 800 total points
ID: 13576562
So you have your calculated value and now you want to stick it in the right text box. So a select statement based on the value of lastFocus tells you where to go:

Select Case lastFocus
   Case "txtCalc1"
        txtCalc1.Text = myValue
   Case "txtCalc2"
        txtCalc2.Text = myValue
End Select

But in the meantime, I remembered that there is an even easier way to do this. If you Dim lastFocus as a TextBox rather than a string, you don't need the Select statement at all. You would also change FocusTextBox so it reads: lastFocus = sender. Then when you are ready to dump your calculated value into the appropriate textbox, you just need to add a statement like this: lastFocus.Text = myValue.

ctm5
0
 

Author Comment

by:GREEBA
ID: 13589707
The Dim lastFocus as textbox works brilliantly... many thanks
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question