converting an object variable (name of a file) into a string variable 
Author Message
 converting an object variable (name of a file) into a string variable

Is there anyway of converting an object variable (the name of a file) into a
string variable. I have tried to use CStr(varFile) but that doesn't seem to
work.

The sub below uses a command button that refers to a textbox
Me.txtFirstLetter. The user enters the first letter of a patients last name
and all the files with names of patients whose last name begin with this
letter are to appear in the listbox Me.lstFileList

Private Sub cmdBuildList_Click
     Dim varFile As Variant
    Me.lstFileList.Clear
    With Application.FileSearch
        .NewSearch
        .LookIn = Application.ActiveDocument.Path
        .FileType = msoFileTypeAllFiles
        .SearchSubFolders = False
        .Execute
    End With

'GetName Function takes the file name and parses it so that the
    'new name looks like "LastName,FirstName"

    For Each varFile In _
        Application.FileSearch.FoundFiles
        If Left(GetName(CStr(varFile)), 1) = Me.txtFirstLetter Then
            Me.lstFileList.AddItem Mid(varFile, _
            Len(Application.ActiveDocument.Path) + 2)
        End If
    Next varFile

End Sub

Is there an easier way to do this?
thanks in advance, Barth



Wed, 14 May 2003 03:00:00 GMT  
 converting an object variable (name of a file) into a string variable
Hi Barth,

This would be my strategy on this one:
Presuming Word 97
Populate the listbox with names (I see the function is working ;-))
and sort the listbox using the WordBasic.SortArray method.
Teach users to type in the first lettre in the listbox
and the listbox itself will do the work for you.

If Word2K, different ballgame:
AFAIK, will not support Wordbasic.
If you're interested in a sort array function that
euquals the WordBasic.SortArray method, repost.

Success,
Perry



Quote:
> Is there anyway of converting an object variable (the name of a file) into
a
> string variable. I have tried to use CStr(varFile) but that doesn't seem
to
> work.

> The sub below uses a command button that refers to a textbox
> Me.txtFirstLetter. The user enters the first letter of a patients last
name
> and all the files with names of patients whose last name begin with this
> letter are to appear in the listbox Me.lstFileList

> Private Sub cmdBuildList_Click
>      Dim varFile As Variant
>     Me.lstFileList.Clear
>     With Application.FileSearch
>         .NewSearch
>         .LookIn = Application.ActiveDocument.Path
>         .FileType = msoFileTypeAllFiles
>         .SearchSubFolders = False
>         .Execute
>     End With

> 'GetName Function takes the file name and parses it so that the
>     'new name looks like "LastName,FirstName"

>     For Each varFile In _
>         Application.FileSearch.FoundFiles
>         If Left(GetName(CStr(varFile)), 1) = Me.txtFirstLetter Then
>             Me.lstFileList.AddItem Mid(varFile, _
>             Len(Application.ActiveDocument.Path) + 2)
>         End If
>     Next varFile

> End Sub

> Is there an easier way to do this?
> thanks in advance, Barth



Thu, 15 May 2003 03:00:00 GMT  
 converting an object variable (name of a file) into a string variable
Hi Barth,

Try replacing

     For Each varFile In _
         Application.FileSearch.FoundFiles
         If Left(GetName(CStr(varFile)), 1) = Me.txtFirstLetter Then
             Me.lstFileList.AddItem Mid(varFile, _
             Len(Application.ActiveDocument.Path) + 2)
         End If
     Next varFile

with:

    For Each varFile In _
        Application.FileSearch.FoundFiles
        If Left(Mid(varFile, Len(Application.ActiveDocument.Path) + 2) =
Me.textFirstLetter Then
             Me.lstFileList.AddItem Mid(varFile,
Len(Application.ActiveDocument.Path) + 2)
        End If
    Next varFile

Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.

Hope this helps,
Doug Robbins - Word MVP

Quote:
> Is there anyway of converting an object variable (the name of a file) into
a
> string variable. I have tried to use CStr(varFile) but that doesn't seem
to
> work.

> The sub below uses a command button that refers to a textbox
> Me.txtFirstLetter. The user enters the first letter of a patients last
name
> and all the files with names of patients whose last name begin with this
> letter are to appear in the listbox Me.lstFileList

> Private Sub cmdBuildList_Click
>      Dim varFile As Variant
>     Me.lstFileList.Clear
>     With Application.FileSearch
>         .NewSearch
>         .LookIn = Application.ActiveDocument.Path
>         .FileType = msoFileTypeAllFiles
>         .SearchSubFolders = False
>         .Execute
>     End With

> 'GetName Function takes the file name and parses it so that the
>     'new name looks like "LastName,FirstName"

>     For Each varFile In _
>         Application.FileSearch.FoundFiles
>         If Left(GetName(CStr(varFile)), 1) = Me.txtFirstLetter Then
>             Me.lstFileList.AddItem Mid(varFile, _
>             Len(Application.ActiveDocument.Path) + 2)
>         End If
>     Next varFile

> End Sub

> Is there an easier way to do this?
> thanks in advance, Barth



Thu, 15 May 2003 03:00:00 GMT  
 converting an object variable (name of a file) into a string variable
Hi Barth and Perry,

Quote:
> If Word2K, different ballgame:
> AFAIK, will not support Wordbasic.

This is not true. Word 2000 still supports the WordBasic object.

Hope this helps,
regards,
Astrid

For direct access to all Microsoft newsgroups:



Thu, 15 May 2003 03:00:00 GMT  
 converting an object variable (name of a file) into a string variable
Aloha Astrid,

You *are* right !!
I don't use calls to the WordBasic object (anymore) ... eventhough
there are instances where properties/methods come in handy.

Perry



Quote:
> Hi Barth and Perry,

> > If Word2K, different ballgame:
> > AFAIK, will not support Wordbasic.

> This is not true. Word 2000 still supports the WordBasic object.

> Hope this helps,
> regards,
> Astrid

> For direct access to all Microsoft newsgroups:




Fri, 16 May 2003 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. how do i convert a string variable to a control variable

2. The value of a variable (String type) is the name of a variable

3. building a string into a variable then text variable as a control name

4. ?Convert string literal to variable name

5. How do I convert a string into a variable name

6. Converting a String to a Variable Name

7. How to convert object type variable to string

8. String Variable as file name

9. Need value of object where object name is variable

10. How do I use contents of variable as field name(db!rst!variable)

11. Variable Name to Variable value.

12. Cannot assign a variable declared as a string to a variable declared as data type

 

 
Powered by phpBB® Forum Software