Results 1 to 3 of 3

Thread: VB6 Q:Function to pass textbox.text

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    7

    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?

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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
    Last edited by jmsrickland; May 16th, 2012 at 06:01 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    7

    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.

    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!
    Last edited by Foolios; May 16th, 2012 at 09:44 PM. Reason: learned something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width