Strings won't concatenate

Strings won't concatenate

Anonymous
Not applicable
643 Views
12 Replies
Message 1 of 13

Strings won't concatenate

Anonymous
Not applicable
This is driving me nuts. I have two string variables. I can display them
in message boxes individually, but when I try to concatenate them, I get
only the first string. I have jumped through all kinds of hoops trying to
figure out why, and I'm stumped. I thought maybe someone here had seen this
before.

Here is my code. I have noted the problem area.

Option Explicit
Option Compare Text
Sub UnBloat()

Dim files As Variant
Dim ComDlg As CommonDialog

Set ComDlg = New CommonDialog
With ComDlg
.DialogTitle = "Select files: "
.DefaultExt = "dvb"
.Filter = "VBA Projects|*.dvb"
.Flags = OFN_EXPLORER Or OFN_ALLOWMULTISELECT Or OFN_HIDEREADONLY
.InitDir = "T:\Acad2000\VBA"
If .ShowOpen Then
files = .ParseFileNames
Else
GoTo NoFilesSelected
End If
End With

Dim objIDE As Object
Dim i As Integer
Dim strFileName As String
Dim strBuildFile As String
Dim ProjLoaded
Dim objProj As Variant
Dim objFileSys As Object
Dim strFldrName As String
Dim objComp As Variant
Dim objRef As Variant


Set objIDE = Application.VBE
For i = LBound(files) To UBound(files)
strFileName = files(i)
ProjLoaded = False
For Each objProj In objIDE.vbprojects
strBuildFile = StrConv(objProj.buildfilename, vbUpperCase)
strBuildFile = Replace(strBuildFile, "\\FILESERVER\PROJECTS",
"T:")
strBuildFile = Replace(strBuildFile, "\\FILESERVER\CHUCK$",
"Z:")
strBuildFile = Replace(strBuildFile, ".DLL", ".DVB")
strFileName = StrConv(strFileName, vbUpperCase)
If strBuildFile = strFileName Then
ProjLoaded = True
Exit For
End If
Next
If ProjLoaded = False Then
LoadDVB strFileName
Set objProj = objIDE.vbprojects(objIDE.vbprojects.Count)
End If
MsgBox "Project: " & objProj.Name
strFileName = files(i)

'THE FOLLOWING STRING VARIABLE APPEARS TO BE THE SOURCE OF THE PROBLEM.
'IF I SET IT TO AN EXPLICIT VALUE, IT CONCATENATES PROPERLY.
strFldrName = Replace(strFileName, ".DVB", "")

MsgBox "FileName: " & strFileName
' Set objFileSys = CreateObject("Scripting.FileSystemObject")
' objFileSys.createfolder strFldrName
For Each objComp In objProj.vbcomponents

'THE SELECT CASE STRUCTURE BELOW IS WHERE I AM TRYING TO CONCATENATE THE
STRINGS.
Select Case objComp.Type
Case 1
MsgBox "Component: " & objComp.Name
MsgBox "Export to: " & strFldrName & "\" & objComp.Name
& ".bas"
Case 2
MsgBox "Component: " & objComp.Name
MsgBox "Export to: " & strFldrName & "\" & objComp.Name
& ".cls"
Case 3
MsgBox "Component: " & objComp.Name
MsgBox "Export to: " & strFldrName & "\" & objComp.Name
& ".frm"
End Select

Next
For Each objRef In objProj.references
MsgBox "Reference: " & objRef.Name & " - " & objRef.fullpath
Next
Next i
Set objIDE = Nothing
Set objProj = Nothing
Set objFileSys = Nothing
Set objComp = Nothing
Set objRef = Nothing

NoFilesSelected:
Set ComDlg = Nothing

End Sub


Thanks in advance.

--
Chuck Gabriel
Coggin Carrara, Inc.
0 Likes
644 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable
Sorry about the word wrap. I'll try to do better next time. I promise.
0 Likes
Message 3 of 13

Anonymous
Not applicable
Are you sure the source of the problem is you? Take a look at the
filename being returned by the CommonDialog class *before* you attempt
to use it for anything else and ensure that it does not include any
trailing NULL characters.

--
http://www.acadx.com
0 Likes
Message 4 of 13

Anonymous
Not applicable
Hi Frank,

Thanks for the tip. I hate to be lame, but how would I go about checking
for
those trailing NULL characters and then removing them?

Chuck


"Frank Oquendo" wrote in message
news:F451CA4012D1E8168FD2031DC653801A@in.WebX.maYIadrTaRb...
> Are you sure the source of the problem is you? Take a look at the
> filename being returned by the CommonDialog class *before* you attempt
> to use it for anything else and ensure that it does not include any
> trailing NULL characters.
>
> --
> http://www.acadx.com
>
>
0 Likes
Message 5 of 13

Anonymous
Not applicable
So much for my attempt at doing better with the word wrap 😛


"Chuck Gabriel" wrote in message
news:549088121BEE2C2669872F9D1B7B53C2@in.WebX.maYIadrTaRb...
> Hi Frank,
>
> Thanks for the tip. I hate to be lame, but how would I go about checking
> for
> those trailing NULL characters and then removing them?
>
> Chuck
0 Likes
Message 6 of 13

Anonymous
Not applicable
Put a breakpoint in your code where you try to concatenate the
filename. You can either drag and drop the filename variable into the
watch window or just hover your cursor it in the code. A well-formed
string will look like this:

"test.dwg"

One with trailing nulls will have a lot of space or other garbage on
the end of the string. As for fixing it, I believe this is a problem
in the CommonDialog class itself. I fixed it once but never got around
to posting the fix and now I've lost it. Let me know what you find and
we'll work on the solution together so no one else will have to go
through this.

--
http://www.acadx.com


"Chuck Gabriel" wrote in message
news:549088121BEE2C2669872F9D1B7B53C2@in.WebX.maYIadrTaRb...
> Hi Frank,
>
> Thanks for the tip. I hate to be lame, but how would I go about
checking
> for
> those trailing NULL characters and then removing them?
>
> Chuck
0 Likes
Message 7 of 13

Anonymous
Not applicable
What about using the Left function to trim ".dvb" from the file name, rather
then using the Replace function. You can search for ".DVB" or "." from the
right with InStrRev to get the position, then use Left to truncate the
string.

Glen


"Chuck Gabriel" wrote in message
news:33CE13B416A42694DF91C12731849CE9@in.WebX.maYIadrTaRb...
> This is driving me nuts. I have two string variables. I can display them
> in message boxes individually, but when I try to concatenate them, I get
> only the first string. I have jumped through all kinds of hoops trying to
> figure out why, and I'm stumped. I thought maybe someone here had seen
this
> before.
>
> Here is my code. I have noted the problem area.
>
> Option Explicit
> Option Compare Text
> Sub UnBloat()
>
> Dim files As Variant
> Dim ComDlg As CommonDialog
>
> Set ComDlg = New CommonDialog
> With ComDlg
> .DialogTitle = "Select files: "
> .DefaultExt = "dvb"
> .Filter = "VBA Projects|*.dvb"
> .Flags = OFN_EXPLORER Or OFN_ALLOWMULTISELECT Or OFN_HIDEREADONLY
> .InitDir = "T:\Acad2000\VBA"
> If .ShowOpen Then
> files = .ParseFileNames
> Else
> GoTo NoFilesSelected
> End If
> End With
>
> Dim objIDE As Object
> Dim i As Integer
> Dim strFileName As String
> Dim strBuildFile As String
> Dim ProjLoaded
> Dim objProj As Variant
> Dim objFileSys As Object
> Dim strFldrName As String
> Dim objComp As Variant
> Dim objRef As Variant
>
>
> Set objIDE = Application.VBE
> For i = LBound(files) To UBound(files)
> strFileName = files(i)
> ProjLoaded = False
> For Each objProj In objIDE.vbprojects
> strBuildFile = StrConv(objProj.buildfilename, vbUpperCase)
> strBuildFile = Replace(strBuildFile, "\\FILESERVER\PROJECTS",
> "T:")
> strBuildFile = Replace(strBuildFile, "\\FILESERVER\CHUCK$",
> "Z:")
> strBuildFile = Replace(strBuildFile, ".DLL", ".DVB")
> strFileName = StrConv(strFileName, vbUpperCase)
> If strBuildFile = strFileName Then
> ProjLoaded = True
> Exit For
> End If
> Next
> If ProjLoaded = False Then
> LoadDVB strFileName
> Set objProj = objIDE.vbprojects(objIDE.vbprojects.Count)
> End If
> MsgBox "Project: " & objProj.Name
> strFileName = files(i)
>
> 'THE FOLLOWING STRING VARIABLE APPEARS TO BE THE SOURCE OF THE PROBLEM.
> 'IF I SET IT TO AN EXPLICIT VALUE, IT CONCATENATES PROPERLY.
> strFldrName = Replace(strFileName, ".DVB", "")
>
> MsgBox "FileName: " & strFileName
> ' Set objFileSys = CreateObject("Scripting.FileSystemObject")
> ' objFileSys.createfolder strFldrName
> For Each objComp In objProj.vbcomponents
>
> 'THE SELECT CASE STRUCTURE BELOW IS WHERE I AM TRYING TO CONCATENATE THE
> STRINGS.
> Select Case objComp.Type
> Case 1
> MsgBox "Component: " & objComp.Name
> MsgBox "Export to: " & strFldrName & "\" &
objComp.Name
> & ".bas"
> Case 2
> MsgBox "Component: " & objComp.Name
> MsgBox "Export to: " & strFldrName & "\" &
objComp.Name
> & ".cls"
> Case 3
> MsgBox "Component: " & objComp.Name
> MsgBox "Export to: " & strFldrName & "\" &
objComp.Name
> & ".frm"
> End Select
>
> Next
> For Each objRef In objProj.references
> MsgBox "Reference: " & objRef.Name & " - " & objRef.fullpath
> Next
> Next i
> Set objIDE = Nothing
> Set objProj = Nothing
> Set objFileSys = Nothing
> Set objComp = Nothing
> Set objRef = Nothing
>
> NoFilesSelected:
> Set ComDlg = Nothing
>
> End Sub
>
>
> Thanks in advance.
>
> --
> Chuck Gabriel
> Coggin Carrara, Inc.
>
>
0 Likes
Message 8 of 13

Anonymous
Not applicable
I put a breakpoint in at the following line:

MsgBox "FileName: " & strFileName

Then I added a watch to the variable strfilename.

This is the value I got.

"D:\Backup\ACAD2000\VBA\CommonDialog.dvb"

Does that make any sense?

Chuck


----- Original Message -----
From: "Frank Oquendo"
Newsgroups: autodesk.autocad.customization.vba
Sent: Monday, June 11, 2001 4:37 PM
Subject: Re: Strings won't concatenate


> Put a breakpoint in your code where you try to concatenate the
> filename. You can either drag and drop the filename variable into the
> watch window or just hover your cursor it in the code. A well-formed
> string will look like this:
>
> "test.dwg"
>
> One with trailing nulls will have a lot of space or other garbage on
> the end of the string. As for fixing it, I believe this is a problem
> in the CommonDialog class itself. I fixed it once but never got around
> to posting the fix and now I've lost it. Let me know what you find and
> we'll work on the solution together so no one else will have to go
> through this.
>
> --
> http://www.acadx.com
0 Likes
Message 9 of 13

Anonymous
Not applicable
Chuck -

It isn't what you are doing that is causing word wrap. Unfortunately the
web view side of the newsgroups does not carry across with the carriage
returns or paragraph breaks. It is a known problem on the list for a
fix.

The newsgroup reader side does show your code correctly indented and
wrapped.

The two URLs for VBA are:

The VBA newsgroup for NTTP newsgroup readers can be found at
news://discussion.autodesk.com/autodesk.autocad.customization.vba.

You may also access the VBA discussion group via the HTTP web-based
forums at http://discussion.autodesk.com/WebX?14@@.ee77f0d.
--
Anne Brown
Manager, Moderator
Autodesk Product Support discussion groups
Discussion Q&A: http://www.autodesk.com/discussion

Chuck Gabriel wrote:
>
> So much for my attempt at doing better with the word wrap 😛
0 Likes
Message 10 of 13

Anonymous
Not applicable
Yes, that makes sense. It's not the correct result but it makes
sense. The fault is indeed in the CommonDialog class. I took a look
and found that the ShowOpen and ShowSave methods weere not stripping
all the nulls out of the strings.

I fixed it and attached it to this message. I'll post the updated copy
to my site tonight. Thanks for helping me with this one.

--
http://www.acadx.com


"Chuck Gabriel" wrote in message
news:D7C296F1C363D8E3DCC7961295FFE07F@in.WebX.maYIadrTaRb...
> I put a breakpoint in at the following line:
>
> MsgBox "FileName: " & strFileName
>
> Then I added a watch to the variable strfilename.
>
> This is the value I got.
>
> "D:\Backup\ACAD2000\VBA\CommonDialog.dvb"
>
> Does that make any sense?
>
> Chuck
0 Likes
Message 11 of 13

Anonymous
Not applicable
Chuck

Private Function strTrimNull(strVal As String) As String
Dim intPos As Integer
intPos = InStr(1, strVal, vbNullChar)
Select Case intPos
Case Is > 1
strTrimNull = Left$(strVal, intPos - 1)
Case 0
strTrimNull = strVal
Case 1
strTrimNull = vbNullString
End Select
End Function

Hope this is some help.

Ian

On Mon, 11 Jun 2001 16:30:02 -0700, "Chuck Gabriel"
wrote:

>I put a breakpoint in at the following line:
>
> MsgBox "FileName: " & strFileName
>
>Then I added a watch to the variable strfilename.
>
>This is the value I got.
>
> "D:\Backup\ACAD2000\VBA\CommonDialog.dvb
"
>
>Does that make any sense?
>
>Chuck
>
>
>----- Original Message -----
>From: "Frank Oquendo"
>Newsgroups: autodesk.autocad.customization.vba
>Sent: Monday, June 11, 2001 4:37 PM
>Subject: Re: Strings won't concatenate
>
>
>> Put a breakpoint in your code where you try to concatenate the
>> filename. You can either drag and drop the filename variable into the
>> watch window or just hover your cursor it in the code. A well-formed
>> string will look like this:
>>
>> "test.dwg"
>>
>> One with trailing nulls will have a lot of space or other garbage on
>> the end of the string. As for fixing it, I believe this is a problem
>> in the CommonDialog class itself. I fixed it once but never got around
>> to posting the fix and now I've lost it. Let me know what you find and
>> we'll work on the solution together so no one else will have to go
>> through this.
>>
>> --
>> http://www.acadx.com
>
>
0 Likes
Message 12 of 13

Anonymous
Not applicable
Thank me? THANK YOU!! I use CommonDialog.cls all over the place.
It is invaluable.

Thanks again Frank.

"Frank Oquendo" wrote in message
news:13A86ECDA2193FC3255F7DC4B08FEE06@in.WebX.maYIadrTaRb...
> Yes, that makes sense. It's not the correct result but it makes
> sense. The fault is indeed in the CommonDialog class. I took a look
> and found that the ShowOpen and ShowSave methods weere not stripping
> all the nulls out of the strings.
>
> I fixed it and attached it to this message. I'll post the updated copy
> to my site tonight. Thanks for helping me with this one.
>
> --
> http://www.acadx.com
0 Likes
Message 13 of 13

Anonymous
Not applicable
Many thanks to all who responded.

Consider the problem solved.

I went with Frank's solution, since it involved basically no work on my part, but I have
added the other ideas to my rapidly growing library of code stolen from other people.

Thanks again.
0 Likes