Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking if files exist on startup / label array

Status
Not open for further replies.

craigey

Technical User
Apr 18, 2002
510
GB
Hi Guys,

I have a program that relies heavily on various Dll files. I have tried telling my users that these dll files need to be in the same directory as the exe, but they still seem to forget this.

I have added the required filenames to an array & created a msgbox for each one that isn't found. I'd like to make this look neater by having a splashscreen / 2nd form that loads before the main form. This contains labels & pictureboxes.
The labels (label1, label2, label3 etc) should be populated from the filename array & the pictureboxes (picturebox1, picturebox2, etc) should be populated with a tick or X.png depending on if the file is found.

I was trying to use a Do while loop to update the apropriate label & picturebox, but this:
Code:
Me.label(i).Text = filename(i)
produces errors.

I have found an article regarding this, but I'm new to VB.net & must admit am a bit lost, when reading it!

I would apreciate any help.

Code:
 Private Sub CheckingFiles_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim opentaskID As Double
        Dim i As String
        Dim filename(5) As String
        Dim label(5) As String
        Dim path As String = Directory.GetCurrentDirectory()

        i = 0
        filename(0) = "SAFileMgr.dll"
        filename(1) = "Interop.ADODB.dll"
        filename(2) = "Interop.FILEMGRLib.dll"
        filename(3) = "Interop.MSDATASRC.dll"
        filename(4) = "Interop.StdFormat.dll"
        filename(5) = "Interop.stdole.dll"


        Do While i < 5
    '   Me.label(i).Text = filename(i)
            If File.Exists(path + "\" + filename(i)) = False Then

    Dim cross As Image = Image.FromFile(Path + "\x.png")
                Me.PictureBox1.Image = cross
                Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
                Me.PictureBox1.Refresh()
                Me.PictureBox1.Visible = True

                MsgBox(filename(i) + Chr(13) + "This File Needs To Be In:" + Chr(13) + path, MsgBoxStyle.Critical, "File Not Found")
                Application.Exit()
            End If
            i = i + 1
        Loop

        opentaskID = Shell("cmd /C regsvr32 SAFileMgr.dll /s", 0)
    End Sub
 
ok. I've sorted this with the help of this thread:


Code:
    Private Sub CheckingFiles_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim opentaskID As Double
        Dim missingfiles As String
        Dim i As String
        Dim filename(5) As String
        Dim label(5) As String
        Dim path As String = Directory.GetCurrentDirectory()
        Dim Labels(5) As Label
        Dim Pictures(5) As PictureBox
        i = 0
        filename(0) = "SAFileMgr.dll"
        filename(1) = "Interop.ADODB.dll"
        filename(2) = "Interop.FILEMGRLib.dll"
        filename(3) = "Interop.MSDATASRC.dll"
        filename(4) = "Interop.StdFormat.dll"
        filename(5) = "Interop.stdole.dll"
        Labels(0) = label1
        Labels(1) = Label2
        Labels(2) = Label3
        Labels(3) = Label4
        Labels(4) = Label5
        Labels(5) = label6
        Pictures(0) = PictureBox1
        Pictures(1) = PictureBox2
        Pictures(2) = PictureBox3
        Pictures(3) = PictureBox4
        Pictures(4) = PictureBox5
        Pictures(5) = PictureBox6
        Pictures(0).Visible = False
        Pictures(1).Visible = False
        Pictures(2).Visible = False
        Pictures(3).Visible = False
        Pictures(4).Visible = False
        Pictures(5).Visible = False

        missingfiles = ""


        Do While i < 5
            Labels(i).Text = filename(i)
            If File.Exists(path + "\" + filename(i)) = False Then

                Dim yesno As Image = Image.FromFile(path + "\x.png")
                Pictures(i).Image = yesno
                Pictures(i).SizeMode = PictureBoxSizeMode.StretchImage
                Pictures(i).Refresh()
                Pictures(i).Visible = True

                missingfiles = missingfiles + filename(i) + Chr(13)
                'MsgBox(filename(i) + Chr(13) + "This File Needs To Be In:" + Chr(13) + path, MsgBoxStyle.Critical, "File Not Found")
                '           Application.Exit()
            Else
                Dim yesno As Image = Image.FromFile(path + "\tick.png")
                Pictures(i).Image = yesno
                Pictures(i).SizeMode = PictureBoxSizeMode.StretchImage
                Pictures(i).Refresh()
                Pictures(i).Visible = True
            End If
            i = i + 1
        Loop

        If missingfiles = "" Then
            opentaskID = Shell("cmd /C regsvr32 SAFileMgr.dll /s", 0)
        Else
            MsgBox(missingfiles + "File(s) Needs To Be In:" + Chr(13) + path, MsgBoxStyle.Critical, "File Not Found")
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub
End Class

The only thing now is the msgbox with the list of files that are missing appears before the form with the ticks / crosses. I only want it to show when the user clicks continue.
At that point the ok button on the error message should quit the application.

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top