Solved

Dim strFileList as string()

Posted on 2009-04-10
3
437 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

815 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

12 Experts available now in Live!

Get 1:1 Help Now