Solved

Modifying a caculator that came with VB

Posted on 2000-03-09
13
257 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
  • 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 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…
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…

810 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