Solved

Modifying a caculator that came with VB

Posted on 2000-03-09
13
255 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
 
LVL 69

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now