Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,459 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,826 people online right now. Registration is fast and FREE... Join Now!




Specify Textbox for variable output

 
Reply to this topicStart new topic

Specify Textbox for variable output, Specify Textbox for variable output

jchutch2
6 Aug, 2008 - 06:13 AM
Post #1

New D.I.C Head
*

Joined: 6 Aug, 2008
Posts: 3

I know this is probably the simplest of questions, but as I'm learning this completely on my own, I know I may miss a few gimmes. Basically, for my own practice, I'm creating a calculator. Simple, I'm sure. I've created M+, M-, and MR buttons for memory recall. The calculator has 3 text boxes. Top/First & Middle/Second for entering the numbers. The third is the Sum field which is at the bottom.

As it is, I have the MR outputting only to a specific field (Second). I want to figure out how to output the variable to whichever of the First or Second textboxes the cursor is in.

The logic I want to use is pretty basic:

CODE
if focus is on textbox1, output dRecall to textbox1
elseif focus is on textbox2, output dRecall to textbox2
else output dRecall to textbox2.


Here is the code as it sits.
CODE
Private Sub uiMemRecall_Click()
txtSecond.Text = dRecall
End Sub


John
User is offlineProfile CardPM
+Quote Post

MrWobbles
RE: Specify Textbox For Variable Output
6 Aug, 2008 - 06:51 AM
Post #2

D.I.C Head
**

Joined: 11 Apr, 2008
Posts: 83



Thanked: 2 times
My Contributions
use Focus() to test if the text box has the focus...

so something like...

CODE

If textBox1.Focus() = True Then
   textBox1.Text = dRecall
Else If textBox2.Focus() = True Then
   textBox2.Text = dRecall
End If

User is offlineProfile CardPM
+Quote Post

jchutch2
RE: Specify Textbox For Variable Output
6 Aug, 2008 - 07:09 AM
Post #3

New D.I.C Head
*

Joined: 6 Aug, 2008
Posts: 3

I'm getting the error:

Method or data member not found and it's highlighting the following code.

CODE
Private Sub uiMemRecall_Click()
If txtFirst.Focus() = True Then
    txtFirst.Text = dRecall
Else: txtSecond.Text = dRecall
End Sub


If it would just be easier to point me to a resource to do my own learning, that would be great, too. I tried to find answers on this specifically, but I wasn't successful.

This post has been edited by jchutch2: 6 Aug, 2008 - 07:10 AM
User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Specify Textbox For Variable Output
6 Aug, 2008 - 07:35 AM
Post #4

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
You're getting the error because VB 6 textboxes don't have that property. What I'd do in your situation is make an integer variable and in the "GotFocus" event of all the textboxes, have it set the variable to a number that represents them.

CODE
Dim intTextbox As Integer

Private Sub txtOne_GotFocus()

    intTextbox = 1

End Sub

Private Sub txtTwo_GotFocus()

    intTextbox = 2

End Sub

Private Sub txtThree_GotFocus()

    intTextbox = 3

End Sub


And in the button do this:
CODE
Private Sub Command1_Click()

    If intTextbox = 1 Then
        txtOne.Text = dRecall
    ElseIf intTextbox = 2 Then
        txtTwo.Text = dRecall
    ElseIf intTextbox = 3 Then
        txtThree.Text = dRecall
    End If

End Sub


Of course, if you haven't clicked any of the textboxes before you click the button, none of them will get dRecall, so you might wanna put in extra code for that particular situation unless it's what you want.
User is offlineProfile CardPM
+Quote Post

jchutch2
RE: Specify Textbox For Variable Output
6 Aug, 2008 - 08:05 AM
Post #5

New D.I.C Head
*

Joined: 6 Aug, 2008
Posts: 3

I actually initialize the variable with a value of "0" expressly for that reason, but I do appreciate it.

Thanks so much for your help! Just a warning, I may likely ask a lot of questions on here. I'm completely new to this. I'm actually a Perl guy. I've never touched VB in any manner. Another person I know has actually suggest I use VB .Net instead of VB6, so, I'll be upgrading now.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:01PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month