Solved

Dim strFileList as string()

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 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

15 Experts available now in Live!

Get 1:1 Help Now