?
Solved

Looping through form controls and updating their properties

Posted on 2006-04-05
3
Medium Priority
?
193 Views
Last Modified: 2010-04-23
Howdy Folks,

After a bit of searching I can't quite find a clear answer so thought I would ask the question (probably again, so apologies).

I have written a function that is intending to loop through the controls on a form to replace apostrophes with a safe version to aid with dynamic sql production (the sql bit isn't important, just context)

so here is the function:

    Public Sub TextBoxQuotes(ByVal Parent As Object)
        Dim c As Control
        For Each c In Parent.Controls
            If c.HasChildren Then
                TextBoxQuotes(c)
            Else
                If TypeOf (c) Is TextBox Then
                    c.Text.Replace(Chr(39), Chr(96)) 'replace ' with `
                End If
            End If
        Next
    End Sub

Tracing through a run, the function is entered into and will step in correctly but the replace doesn't seem to do anything. I assume this is some schoolboy error on my part! I have tried ByRef and ByVal to no change and have wondered if i am somehow creating an instance of the control instead of actually updating the original.

Can anyone see why the replace isn't doing anything?

Any help would be appreciated
0
Comment
Question by:LVGICT
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 16380317
The Replace method on a string actually returns a string rather than simply acting on the string itself. So you will need to change the line to:

     c.Text = c.Text.Replace(Chr(39), Chr(96))
0
 
LVL 43

Assisted Solution

by:TimCottee
TimCottee earned 500 total points
ID: 16380324
Hi LVGICT,

                    c.Text = c.Text.Replace(Chr(39), Chr(96)) 'replace ' with `

You are not assigning the result of the replace to anything.

Tim Cottee
0
 

Author Comment

by:LVGICT
ID: 16380544
AHAAA...

spot the fool (*raises hand*)

Many Thanks guys

not quite sure why i thought the replace would act on itself

Have split the points as you were within a miniute of each other so i feel its unfair to say one answered and the other didn't... hope that is ok
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

850 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