VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Replace text in All text boxes contained in frames, form, and/or pictureboxes

by KRYO_11 (20 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

I noticed an article recently posted about this. I am posting this because it is a much more efficient way to do it. Simple code so I am not expecting votes, but if you like it please feel free :)

Inputs
'Example usage: 'TextBoxMod Me, 0, "Kryo" 'Would make ALL textboxe' text say "Kryo"
API Declarations
'Enum declared to make using following sub easier
Public Enum What2Clear
[Clear All Textbox's] = 0
[Clear Textbox's Contained In Frames] = 1
[Clear Textbox's Contained In Picturebox's] = 2
[Clear Textbox's Contained In Form] = 3
End Enum

Rate Replace text in All text boxes contained in frames, form, and/or pictureboxes

Public Sub TextBoxMod(WhichForm As Form, CommandLine As What2Clear, Optional ReplaceWith As String = Empty)
  For Each Control In WhichForm 'Search's through given form
    If CommandLine = [Clear All Textbox's] Then
      If TypeOf Control Is TextBox Then Control.Text = ReplaceWith
      'Look for ALL textboxes
    ElseIf CommandLine = [Clear Textbox's Contained In Form] Then
      'Look for textboxes in Form ONLY
      If TypeOf Control Is TextBox And TypeOf Control.Container Is Form Then Control.Text = ReplaceWith
    ElseIf CommandLine = [Clear Textbox's Contained In Frames] Then
      'Look for textboxes in Frmaes ONLY
      If TypeOf Control Is TextBox And TypeOf Control.Container Is Frame Then Control.Text = ReplaceWith
    ElseIf CommandLine = [Clear Textbox's Contained In Picturebox's] Then
      'Look for textboxes in Pictureboxes ONLY
      If TypeOf Control Is TextBox And TypeOf Control.Container Is PictureBox Then Control.Text = ReplaceWith
    End If
  Next
End Sub

Download this snippet    Add to My Saved Code

Replace text in All text boxes contained in frames, form, and/or pictureboxes Comments

No comments have been posted about Replace text in All text boxes contained in frames, form, and/or pictureboxes. Why not be the first to post a comment about Replace text in All text boxes contained in frames, form, and/or pictureboxes.

Post your comment

Subject:
Message:
0/1000 characters