Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

Modifying a caculator that came with VB

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
ptran2000
Asked:
ptran2000
  • 6
  • 6
1 Solution
 
Erick37Commented:
Why not use 2 grouped OptionButton controls to direct the output to the 2 textboxes, depending which option is selected?
0
 
Erick37Commented:
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
 
Erick37Commented:
Actually,
Readout1_GotFocus(), not Click, works better.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Éric MoreauSenior .Net ConsultantCommented:
Can't you use Screen.ActiveControl?
0
 
ptran2000Author Commented:
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
 
Erick37Commented:
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
 
ptran2000Author Commented:
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
 
Erick37Commented:
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
 
ptran2000Author Commented:
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
 
ptran2000Author Commented:
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
 
ptran2000Author Commented:
Nevermind the my last post.  Your last post made it work thanks so much...
0
 
ptran2000Author Commented:
Nevermind the my last post.  Your last post made it work thanks so much...
0
 
Erick37Commented:
You're welcome.
:)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now