VB6 Q:Function to pass textbox.text
I am trying to figure out how to use functions. I have 10 textboxes that will need to be checked for certain things.
I believe I can pass the text from each textbox to the function and then have text returned to the text property of that textbox that made the call via it's change event.
I don't know how to send the textbox's text like that. Do I use THIS ?
Code:
Private Sub TxtBxHrs1_Change()
If TxtBxHrs1.Text = "." Then
'TxtBxHrs1.Text = "0.00"
Call CallChngeTxt(Me.Textbox.text)
End If
End Sub
Code:
Function CallChngeTxt() As String
CallChngeTxt = "0.00"
End Function
Can someone show me how to use a function that will allow me to send the text from multiple text boxes? And then return back the edited text to those calling textboxes?
Re: VB6 Q:Function to pass textbox.text
Code:
Private Sub TxtBxHrs1_Change()
If TxtBxHrs1.Text = "." Then
Me.TxtBxHrs.Text = CallChngeTxt(Me.TxtBxHrs1.text)
End If
End Sub
Function CallChngeTxt() As String
CallChngeTxt = "0.00"
End Function
For multiple textboxes use this function
Code:
Function CallChngeTxt() As String
CallChngeTxt = "0.00"
End Function
Private Sub TxtBxHrs1_Change()
If TxtBxHrs1.Text = "." Then
TxtBxHrs1.Text = CallChngeTxt(Me.TxtBxHrs1)
End If
End Sub
Private Sub TxtBxMin1_Change()
If TxtBxMin1.Text = "." Then
TxtBxMin1.Text = CallChngeTxt(Me.TxtBxMin1)
End If
End Sub
Private Sub TxtBxSec1_Change()
If TxtBxSec1.Text = "." Then
TxtBxSec1.Text = CallChngeTxt(Me.TxtBxSec1)
End If
End Sub
OR, this way
Code:
Private Sub CallChngeTxt(TB As Textbox)
TB.Text = "0.00"
End Sub
Private Sub TxtBxHrs1_Change()
If TxtBxHrs1.Text = "." Then
CallChngeTxt(Me.TxtBxHrs1)
End If
End Sub
Private Sub TxtBxMin1_Change()
If TxtBxMin1.Text = "." Then
CallChngeTxt(Me.TxtBxMin1)
End If
End Sub
Private Sub TxtBxSec1_Change()
If TxtBxSec1.Text = "." Then
CallChngeTxt(Me.TxtBxSec1)
End If
End Sub
Re: VB6 Q:Function to pass textbox.text
Very neat. Pass the textbox itself as a textbox object.
Thanks for those examples. Does not seem to save too many lines of code for this exercise.
I don't know how to take this idea of checking the textboxes in a simpler way.
Would this be something you would use an array for?
I dunno, what would be your suggestion for 10 textboxes?
Thanks in advance.
EDIT:
Actually this came in real handy.
Quote:
Private Sub ChngeTxt(TB As Textbox)
TB.Text = "0.00"
End Sub
Once I started adding more calls to other procedures, I only had to edit the function and add the calls inside it instead of to each button.
Starting to realize it's value now.
Thanks again!