Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB6 TRIM all textbox in form

Posted on 2013-06-24
14
Medium Priority
?
445 Views
Last Modified: 2013-06-25
Hello all

I normally use this code to TRIM a textbox
Text1.text = TRIM(Text1.text)

Open in new window


I would like to know how i can TRIM all testbox in my form in one single code instead of multiple code under all textbox separatly.

Is that possible?

How can i do that?

Thanks again for your help
0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39273394
Dim ctl As Control

For Each ctl In Controls
    If TypeOf ctl is Textbox Then
        Trim(ctl)
    End If
Next

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39273417
Hi MartinLiss

When i use that code, i still have a space in textbox. Look in State field

space
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39273424
I don't see a space (is it at the end?) but I believe you. Can you attach your workbook?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 11

Author Comment

by:Wilder1626
ID: 39273432
Since i copy from excel and past it into a MSHFlexgrid, i wonder if i should TRIM it when i past into the grid instead of the textbox.

Can i trim all  cell in the MSHFlexgrid?

Paste function
    Dim sText As String
    Dim nFixedRows As Long
    Dim nFixedCols As Long
    Dim nRows As Long
    Dim nCols As Long

    nFixedRows = 1
    nFixedCols = 1

    sText = Clipboard.GetText

    nRows = UBound(Split(sText, vbCr)) + 1

    'Dim vRows As Variant
    'vRows = Split(sText, vbCr)
    'nCols = UBound(Split(vRows(0), vbTab)) + 1
    nCols = UBound(Split(Split(sText, vbCr)(0), vbTab)) + 1
    'Debug.Print nCols

    With MSHFlexGrid1
        .FixedRows = nFixedRows
        .FixedCols = nFixedCols

        .Rows = .FixedRows + nRows
        .Cols = .FixedCols + nCols
        .Row = .FixedRows
        .Col = .FixedCols  '(or whatever value you like)

        .RowSel = .Rows - 1
        .ColSel = .Cols - 1

        .Clip = Replace(sText, vbLf, "")
    End With

Open in new window

0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39273464
Okay so it may not be a space that you need to remove. The first thing to try is to replace vblf in the Clip statement with vbcrlf (or do both)
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39273487
Ok, i have tried : .Clip = Replace(sText, vbcrlf , ""), but i still have the same space in the State field.

So strange
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39273495
If you copy all excel cell in yellow from the excel file and use the past function in the project in attachment, one of the cell will show in the Text1. You will see the empty space at the end.

Text1.text= Trim(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2))
excel-file-to-copy.zip
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39273512
Assuming that the space is at the end of the textbox, please put this someplace in your code  (substituting the name of your textbox) where it will execute. What does it tell you?
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39273516
I have  a Compile error: Expected Sub, Function, or Property when i use:
substituting Text1

Open in new window

0
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 39273718
I'm sorry. I left out a very important line in my request.

Assuming that the space is at the end of the textbox, please put the following  someplace in your code  (substituting the name of your textbox) where it will execute. What does it tell you?

MsgBox Asc(Right(Text1, 1))

so perhaps in some command button code if the name of the textbox is MyTextBoxName you would put

MsgBox Asc(Right(MyTextBoxName, 1))
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39274293
Hi

It give me the result : 160
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39274307
So let me try this then:

Text1.Text = Replace(Text1.Text, Chr(160), "")
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39274441
Many thanks again for your help.

Now it works and it remove the empty spaces.

I will trim and replace char(160) also.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39274757
You're welcome and I'm glad I was able to help.

Select the 'About Me' tab in my profile and you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2013
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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

618 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