Solved

Dim strFileList as string()

Posted on 2009-04-10
3
434 Views
Last Modified: 2013-12-25
What does it mean when you dimension a variable as a string followed by ()?  Does this create an array?  How would you convert it back to a simple string?  Here's the code I'm using.  I have not run it yet.  I've never used string() and would like to know what type of variable it creates.
Protected Function DeleteExistingBackup(ByVal strBackupPath As String) As Boolean
 

        Dim strFileList As String()

        Dim strFileName As String
 
 

        If Directory.Exists(strBackupPath) = True Then
 

            strFileList = Directory.GetFiles(strBackupPath, "*.bak")
 

            For Each strFileName In strFileList

                File.Delete(strFileName)
 

            Next
 

            Return True
 

        Else 'Directory does not exist

            Return False

        End If
 

    End Function

Open in new window

0
Comment
Question by:TimSledge
3 Comments
 
LVL 13

Accepted Solution

by:
rettiseert earned 150 total points
ID: 24119945
Hi
Dim strFileList As String()
defines an array of strings, but it doesn't create anything yet. The actual array is created in memory somewhere inside Directory.GetFiles(strBackupPath, "*.bak") and its reference is returned to strFileList.

Basically when you use Dim VarName as TypeName() you are defining an array named VarName of TypeName objects, but the size of the array is not known yet. You will be able to define the size of the array later using a Redim statement. For example:

        Dim x As String()   'Defines an array of strings named x.
        Dim ElementsCount As Integer

        ElementsCount = 1 + 1         'Calculate the number of elements that will be in the array.


        ReDim x(0 To ElementsCount - 1)  'The array x defined earlier is created, with 2 elements (indexes 0 and 1)
0
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 50 total points
ID: 24119952
Yes, its an array. You can declare like that or like this:
Dim strFileList () As String
 
0
 
LVL 4

Author Comment

by:TimSledge
ID: 24120099
Thanks to both of you for your answers.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now