Solved

Modifying a caculator that came with VB

Posted on 2000-03-09
13
260 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

730 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