Solved

Modifying a caculator that came with VB

Posted on 2000-03-09
13
264 Views
Last Modified: 2010-05-02
I am using the sample application calculator that came with VB6.0.

Anyways... In that app, there is one textbox (named Readout)that displays all the numbers being clicked on.  I would like to add another textbox (Readout2).  Then when a number is clicked on, it should be displayed on whichever textbox(Readout or Readout2) that has(had) the focus.


Thanks for your insights...

0
Comment
Question by:ptran2000
[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
  • 6
  • 6
13 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 2603005
Why not use 2 grouped OptionButton controls to direct the output to the 2 textboxes, depending which option is selected?
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 125 total points
ID: 2603036
Simple example:

Option Explicit

Dim t As TextBox

Private Sub Command1_Click()
    Static i As Long
    i = i + 1
    t.Text = CStr(i)
End Sub

Private Sub Form_Load()
    Option1.Value = True
    Set t = Readout1
End Sub

Private Sub Option1_Click()
    Set t = Readout1
End Sub

Private Sub Option2_Click()
    Set t = Readout2
End Sub

Private Sub Readout1_Click()
    Option1.Value = True
End Sub

Private Sub Readout2_Click()
    Option2.Value = True
End Sub
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2603044
Actually,
Readout1_GotFocus(), not Click, works better.
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2604572
Can't you use Screen.ActiveControl?
0
 

Author Comment

by:ptran2000
ID: 2605500
Thanks,  That worked!
However,

if i type in "15" in Readout
and then click on readout 2 and type
in 3, it displays in readout2 as "153" instead of 3.

How do I (reset variables?) to make it display 3 when I move to Readout2 (or even Readout3).

thanks
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2605604
I would have to see your code in order to answer that.  
Is there a string buffer variable which holds the input?  If there is, you need to clear it each time focus shifts from one textbox to another.
0
 

Author Comment

by:ptran2000
ID: 2606176
This is what I have....

Option Explicit
Dim txtX As TextBox

Private Sub btnNumbers_Click(Index As Integer)
Static i As Long
i = i & btnNumbers(Index).Caption
txtX.Text = i
End Sub

Private Sub txtNewAlarm_GotFocus()
Set txtX = txtNewRun 'This is readout
End Sub

Private Sub txtNewLevel_GotFocus()
Set txtX = txtNewRun 'This is readout2
End Sub


Thanks

0
 
LVL 32

Expert Comment

by:Erick37
ID: 2606322
Assuming that there are 2 textboxes, and we want to accumulate the captions of each command button to the currently selected textbox use:

Option Explicit
Dim txtX As TextBox

Private Sub btnNumbers_Click(Index As Integer)
txtX.Text = txtX.Text & btnNumbers(Index).Caption
End Sub

Private Sub Form_Load()
Set txtX = txtNewRun1
End Sub

Private Sub txtNewRun1_GotFocus()
Set txtX = txtNewRun1 'This is readout
End Sub

Private Sub txtNewRun2_GotFocus()
Set txtX = txtNewRun2 'This is readout2
End Sub
0
 

Author Comment

by:ptran2000
ID: 2606326
Ooops.  mistake, last 2 Sub should be..

Private Sub txtNewAlarm_GotFocus()
Set txtX = txtNewAlarm 'This is readout
End Sub


Private Sub txtNewLevel_GotFocus()
Set txtX = txtNewLevel 'This is readout2
End Sub

thanks.
0
 

Author Comment

by:ptran2000
ID: 2606335
Ooops.  mistake, last 2 Sub should be..

Private Sub txtNewAlarm_GotFocus()
Set txtX = txtNewAlarm 'This is readout
End Sub


Private Sub txtNewLevel_GotFocus()
Set txtX = txtNewLevel 'This is readout2
End Sub

thanks.
0
 

Author Comment

by:ptran2000
ID: 2606343
Nevermind the my last post.  Your last post made it work thanks so much...
0
 

Author Comment

by:ptran2000
ID: 2606761
Nevermind the my last post.  Your last post made it work thanks so much...
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2606864
You're welcome.
:)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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