Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-13-2020, 02:04 AM
John 4 John 4 is offline Windows 10 Office 2013
Advanced Beginner
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default Trimming doesn’t show any difference in the ‘Watches’ value

Using the Trim function under certain circumstances doesn’t show any difference in the ‘Watches’ value or Immediate window.



Here’s an example sentence that can be copied into a document to show what I mean:
A MAN AND ANOTHER IN THE HOUSE ARE GOING TO THE TOWN.

And here’s a macro to use with it:
Code:
Sub Macro13()
    For Each wrd In ActiveDocument.Words
      Select Case Trim(wrd)
        Case "A", "AND", "OF", "IN", "IS", "TO", "THE"
          wrd.Case = wdLowerCase
      End Select
    Next wrd
End Sub
Trimming doesn't show any difference in the ‘Watches’ list value of “wrd”, nor by using Debug.Print to the Immediate Window (i.e. the selected word still shows as having a trailing space: “A ” instead of “A”, and “THE ” instead of “THE”); but it (using the Trim function) certainly makes a difference because otherwise the relevant words aren't selected / modified / lowercased. That is, if you change the line, “Select Case Trim(wrd)”, to “Select Case wrd”, then the macro does nothing, even though the value of “wrd” in the ‘Watches’ list is exactly the same in both versions (i.e. with or without ‘Trim’ being used).

It seems that “wrd” is being trimmed but it isn’t showing in the Watch list or Immediate window, which appears unusual to me. More than likely this has to do with “wrd” being listed as type “Variant/Object/Range”, whereas the Trim function (as far as I know) is only for use with strings; but I still don’t understand why, or even how, it’s being trimmed but not trimmed (as it seems) at the same time. Anyone?
Reply With Quote
  #2  
Old 11-13-2020, 03:57 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This is VBA we are talking about here. Perhaps other programming languages change the value of a variable just by asking for a characteristic of that variable's value but it doesn't happen in VBA.

The value of the variable 'wrd' is not being changed by your line
Select Case Trim(wrd)

If you want to change the value of the text in wrd then you need to tell it to change
eg
wrd = Trim(wrd)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 11-13-2020, 05:29 AM
John 4 John 4 is offline Windows 10 Office 2013
Advanced Beginner
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default

Thanks Andrew for your prompt reply.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between 16:9 Widescreen and 16:9 On-Screen Show? presenterrick PowerPoint 3 06-22-2018 08:19 AM
OneDrive version doesn't show up on desktop derohanes Excel 0 06-04-2018 10:15 AM
New Master doesn't show up in my layout options LadyBug679 PowerPoint 0 02-17-2017 10:44 AM
24 hour task calendar doesn't show a day?? benl Project 3 12-31-2015 02:55 PM
trimming excess image data in Word document gib65 Word 2 12-13-2011 07:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:14 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft