Loading a Form

shaught

Member
Joined
Oct 27, 2008
Messages
7
Programming Experience
Beginner
I'm new to VB.net and I'm trying to load a form. Here is my code and the error I'm receiving.

Dim frmSetup1 As New frmSetup
frmSetup1.Show()

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Thanks for your help.
 
The code you've posted is correct for instantiating and showing a form. You're getting a File Permission error, which means in the form's Load or Shown event you're trying to access a file that you dont have access to and you're not using proper error handling (try-catch)
 
I added a Try Catch. This is the ex.tostring:
"System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Windows.Forms.FileDialog.set_FileName(String value)
at Program1.frmSetup.InitializeComponent()
at Program1.frmSetup..ctor()
at Program1.frmMain.SetupToolStripMenuItem_Click(Object sender, EventArgs e)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
The Zone of the assembly that failed was:
Intranet"
 
System.Windows.Forms.FileDialog.set_FileName(Strin g value)
at Program1.frmSetup.InitializeComponent()
at Program1.frmSetup..ctor()
at Program1.frmMain.SetupToolStripMenuItem_Click(Obje ct sender, EventArgs e)

This may be your problem. The FileDialog i would assume is either an open or save dialog of some sort, which can be persnickety at times, especially with hard coded (in the designer properties) values.

Check a few things on your File Dialog: InitialDirectory, And it appears you are setting the FileName property so check the CheckFileExists and CheckPathExists properties.

if either of these conflict when it tries to create the Dialog an exception will be raised. When in doubt I have always found it preferable to handle all dialog initializations programmatically, thus you can do the:
VB.NET:
If IO.Directory.Exists(sPath) then 
   FileDialog.InitialDirectory = sPath
else : DoMyError()
end if

if IO.File.Exists(sFile) then
  FileDialog.FileName = sFile
else : DoMyError()
end if

That way you can handle the error for exactly what it is.
 
Hey Jaeden,

This project has 2 forms and I commented out the code in the form I'm calling. This is all the code I have in the form doing the calling. Any ideas?

Private Sub SetupToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SetupToolStripMenuItem.Click
Try
Dim frmSetup1 As New frmSetup
frmSetup1.Show()
Catch ex As Exception ' Catch the error.
MsgBox(ex.ToString) ' Show friendly error message.
End Try

End Sub
 
It's not in the form. It would be in the Designer Properties.

Why not provide description of frmSetup1 because that is were the error is occuring. Provide:
  • Controls (Visual and NonVisual, ie: textbox & OpenFileDialog)
  • Non-Default Values of some of the controls on that form

the Error exists Between the frmSetup1.Show() and the frmSetup1_Load Event Handler. It is somewhere in the InitializeComponents() of the frmSetup1.designer.vb file, which means that a property is set wrong causing the exception.
 
The code that I sent earlier is all the code in the frmMain.vb. There is no code in my frmSetup.vb. In my frmMain I added a menustrip and in the click event I added the code above. I added some buttons on frmMain, but no code yet. Let me know what else you need.


*********************************************
Here is the text in the frmSetup.Designer.vb
*********************************************
VB.NET:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmSetup
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.btn_BrowseDB = New System.Windows.Forms.Button
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.btn_BrowseProject = New System.Windows.Forms.Button
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.btn_BrowsePrevWB = New System.Windows.Forms.Button
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.Label5 = New System.Windows.Forms.Label
        Me.btn_BrowseCurWB = New System.Windows.Forms.Button
        Me.TextBox4 = New System.Windows.Forms.TextBox
        Me.Label6 = New System.Windows.Forms.Label
        Me.btn_BrowseArchive = New System.Windows.Forms.Button
        Me.TextBox5 = New System.Windows.Forms.TextBox
        Me.Button6 = New System.Windows.Forms.Button
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.FromArgb(CType(CType(118, Byte), Integer), CType(CType(146, Byte), Integer), CType(CType(125, Byte), Integer))
        Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Label1.Font = New System.Drawing.Font("Arial", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(-1, 9)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(567, 24)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Aries GreenLight Update"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'TextBox1
        '
        Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox1.Location = New System.Drawing.Point(205, 68)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(243, 20)
        Me.TextBox1.TabIndex = 2
        '
        'btn_BrowseDB
        '
        Me.btn_BrowseDB.BackgroundImage = Global.Program1.My.Resources.Resources.My_Documents
        Me.btn_BrowseDB.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom
        Me.btn_BrowseDB.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(CType(CType(204, Byte), Integer), CType(CType(210, Byte), Integer), CType(CType(207, Byte), Integer))
        Me.btn_BrowseDB.Location = New System.Drawing.Point(160, 68)
        Me.btn_BrowseDB.Name = "btn_BrowseDB"
        Me.btn_BrowseDB.Size = New System.Drawing.Size(39, 20)
        Me.btn_BrowseDB.TabIndex = 4
        Me.btn_BrowseDB.UseVisualStyleBackColor = True
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(83, 72)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(71, 16)
        Me.Label2.TabIndex = 5
        Me.Label2.Text = "Database:"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.Location = New System.Drawing.Point(69, 113)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(85, 16)
        Me.Label3.TabIndex = 8
        Me.Label3.Text = "Project File:"
        '
        'btn_BrowseProject
        '
        Me.btn_BrowseProject.BackgroundImage = Global.Program1.My.Resources.Resources.My_Documents
        Me.btn_BrowseProject.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom
        Me.btn_BrowseProject.Location = New System.Drawing.Point(160, 109)
        Me.btn_BrowseProject.Name = "btn_BrowseProject"
        Me.btn_BrowseProject.Size = New System.Drawing.Size(39, 20)
        Me.btn_BrowseProject.TabIndex = 7
        Me.btn_BrowseProject.UseVisualStyleBackColor = True
        '
        'TextBox2
        '
        Me.TextBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox2.Location = New System.Drawing.Point(205, 109)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(243, 20)
        Me.TextBox2.TabIndex = 6
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.Location = New System.Drawing.Point(19, 154)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(135, 16)
        Me.Label4.TabIndex = 11
        Me.Label4.Text = "Previous Workbook:"
        '
        'btn_BrowsePrevWB
        '
        Me.btn_BrowsePrevWB.BackgroundImage = Global.Program1.My.Resources.Resources.My_Documents
        Me.btn_BrowsePrevWB.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom
        Me.btn_BrowsePrevWB.Location = New System.Drawing.Point(160, 150)
        Me.btn_BrowsePrevWB.Name = "btn_BrowsePrevWB"
        Me.btn_BrowsePrevWB.Size = New System.Drawing.Size(39, 20)
        Me.btn_BrowsePrevWB.TabIndex = 10
        Me.btn_BrowsePrevWB.UseVisualStyleBackColor = True
        '
        'TextBox3
        '
        Me.TextBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox3.Location = New System.Drawing.Point(205, 150)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(243, 20)
        Me.TextBox3.TabIndex = 9
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.Location = New System.Drawing.Point(27, 190)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(127, 16)
        Me.Label5.TabIndex = 14
        Me.Label5.Text = "Current Workbook:"
        '
        'btn_BrowseCurWB
        '
        Me.btn_BrowseCurWB.BackgroundImage = Global.Program1.My.Resources.Resources.My_Documents
        Me.btn_BrowseCurWB.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom
        Me.btn_BrowseCurWB.Location = New System.Drawing.Point(160, 186)
        Me.btn_BrowseCurWB.Name = "btn_BrowseCurWB"
        Me.btn_BrowseCurWB.Size = New System.Drawing.Size(39, 20)
        Me.btn_BrowseCurWB.TabIndex = 13
        Me.btn_BrowseCurWB.UseVisualStyleBackColor = True
        '
        'TextBox4
        '
        Me.TextBox4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox4.Location = New System.Drawing.Point(205, 186)
        Me.TextBox4.Name = "TextBox4"
        Me.TextBox4.Size = New System.Drawing.Size(243, 20)
        Me.TextBox4.TabIndex = 12
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label6.Location = New System.Drawing.Point(35, 233)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(119, 16)
        Me.Label6.TabIndex = 17
        Me.Label6.Text = "Archive Location:"
        '
        'btn_BrowseArchive
        '
        Me.btn_BrowseArchive.BackgroundImage = Global.Program1.My.Resources.Resources.My_Documents
        Me.btn_BrowseArchive.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom
        Me.btn_BrowseArchive.Location = New System.Drawing.Point(160, 229)
        Me.btn_BrowseArchive.Name = "btn_BrowseArchive"
        Me.btn_BrowseArchive.Size = New System.Drawing.Size(39, 20)
        Me.btn_BrowseArchive.TabIndex = 16
        Me.btn_BrowseArchive.UseVisualStyleBackColor = True
        '
        'TextBox5
        '
        Me.TextBox5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox5.Location = New System.Drawing.Point(205, 229)
        Me.TextBox5.Name = "TextBox5"
        Me.TextBox5.Size = New System.Drawing.Size(243, 20)
        Me.TextBox5.TabIndex = 15
        '
        'Button6
        '
        Me.Button6.Location = New System.Drawing.Point(239, 285)
        Me.Button6.Name = "Button6"
        Me.Button6.Size = New System.Drawing.Size(67, 28)
        Me.Button6.TabIndex = 18
        Me.Button6.Text = "Close"
        Me.Button6.UseVisualStyleBackColor = True
        '
        'OpenFileDialog1
        '
        Me.OpenFileDialog1.FileName = "OpenFileDialog1"
        '
        'Setup
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.BackColor = System.Drawing.Color.FromArgb(CType(CType(169, Byte), Integer), CType(CType(180, Byte), Integer), CType(CType(175, Byte), Integer))
        Me.ClientSize = New System.Drawing.Size(566, 338)
        Me.Controls.Add(Me.Button6)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.btn_BrowseArchive)
        Me.Controls.Add(Me.TextBox5)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.btn_BrowseCurWB)
        Me.Controls.Add(Me.TextBox4)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.btn_BrowsePrevWB)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.btn_BrowseProject)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.btn_BrowseDB)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label1)
        Me.Name = "Setup"
        Me.Text = "Setup"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents btn_BrowseDB As System.Windows.Forms.Button
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents btn_BrowseProject As System.Windows.Forms.Button
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents btn_BrowsePrevWB As System.Windows.Forms.Button
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents btn_BrowseCurWB As System.Windows.Forms.Button
    Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents btn_BrowseArchive As System.Windows.Forms.Button
    Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
    Friend WithEvents Button6 As System.Windows.Forms.Button
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
End Class
****************************************************
Here is the code in the frmMain.designer.vb
****************************************************
VB.NET:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmMain
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Button1 = New System.Windows.Forms.Button
        Me.Label3 = New System.Windows.Forms.Label
        Me.Button2 = New System.Windows.Forms.Button
        Me.Label4 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.Label7 = New System.Windows.Forms.Label
        Me.Button3 = New System.Windows.Forms.Button
        Me.MenuStrip1 = New System.Windows.Forms.MenuStrip
        Me.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem
        Me.SetupToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
        Me.MenuStrip1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.FromArgb(CType(CType(118, Byte), Integer), CType(CType(146, Byte), Integer), CType(CType(125, Byte), Integer))
        Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Label1.Font = New System.Drawing.Font("Arial", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(0, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(666, 24)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Aries GreenLight Update"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'Button1
        '
        Me.Button1.BackgroundImage = Global.Program1.My.Resources.Resources.Admin_min
        Me.Button1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom
        Me.Button1.Location = New System.Drawing.Point(37, 130)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(54, 39)
        Me.Button1.TabIndex = 3
        Me.Button1.UseVisualStyleBackColor = True
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(115, 143)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(117, 13)
        Me.Label3.TabIndex = 4
        Me.Label3.Text = "Read GreenLight Data."
        '
        'Button2
        '
        Me.Button2.BackgroundImage = Global.Program1.My.Resources.Resources.Admin_min
        Me.Button2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom
        Me.Button2.Location = New System.Drawing.Point(37, 190)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(54, 39)
        Me.Button2.TabIndex = 5
        Me.Button2.UseVisualStyleBackColor = True
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(115, 203)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(98, 13)
        Me.Label4.TabIndex = 6
        Me.Label4.Tag = ""
        Me.Label4.Text = "Update well codes."
        '
        'TextBox1
        '
        Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox1.Location = New System.Drawing.Point(118, 230)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(46, 20)
        Me.TextBox1.TabIndex = 7
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(170, 233)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(215, 13)
        Me.Label5.TabIndex = 8
        Me.Label5.Text = "Number of missing well codes in MS Project."
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(170, 259)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(256, 13)
        Me.Label6.TabIndex = 10
        Me.Label6.Text = "Number of missing well codes in the GL spreadsheet."
        '
        'TextBox2
        '
        Me.TextBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox2.Location = New System.Drawing.Point(118, 256)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(46, 20)
        Me.TextBox2.TabIndex = 9
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.Location = New System.Drawing.Point(115, 304)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(132, 13)
        Me.Label7.TabIndex = 12
        Me.Label7.Text = "View GreenLight changes."
        '
        'Button3
        '
        Me.Button3.BackgroundImage = Global.Program1.My.Resources.Resources.Admin_min
        Me.Button3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom
        Me.Button3.Location = New System.Drawing.Point(37, 291)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(54, 39)
        Me.Button3.TabIndex = 11
        Me.Button3.UseVisualStyleBackColor = True
        '
        'MenuStrip1
        '
        Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripMenuItem1, Me.SetupToolStripMenuItem})
        Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
        Me.MenuStrip1.Name = "MenuStrip1"
        Me.MenuStrip1.Size = New System.Drawing.Size(672, 24)
        Me.MenuStrip1.TabIndex = 13
        Me.MenuStrip1.Text = "MenuStrip1"
        '
        'ToolStripMenuItem1
        '
        Me.ToolStripMenuItem1.Name = "ToolStripMenuItem1"
        Me.ToolStripMenuItem1.Size = New System.Drawing.Size(59, 20)
        Me.ToolStripMenuItem1.Text = "Program"
        '
        'SetupToolStripMenuItem
        '
        Me.SetupToolStripMenuItem.Name = "SetupToolStripMenuItem"
        Me.SetupToolStripMenuItem.Size = New System.Drawing.Size(47, 20)
        Me.SetupToolStripMenuItem.Text = "Setup"
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.BackColor = System.Drawing.Color.FromArgb(CType(CType(169, Byte), Integer), CType(CType(180, Byte), Integer), CType(CType(175, Byte), Integer))
        Me.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center
        Me.ClientSize = New System.Drawing.Size(672, 678)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.MenuStrip1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MainMenuStrip = Me.MenuStrip1
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.MenuStrip1.ResumeLayout(False)
        Me.MenuStrip1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
    Friend WithEvents ToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents SetupToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem

End Class
Steve
 
If you're form does indeed have no code in it (which there are at least 2 lines of code, which isn't posted) then the only thing i can suggest is to remove the OpenFileDialog1 control from your form and try your code then.
 
Hey JuggaloBrotha,

I believe the line of code you're talking about is commented out. Anyway, removing the control fixed the error. Thanks! I had planned to use the setup form to allow the user to browse and select different databases. What do I need to do to get the OpenFileDialog control to work correctly? I know just adding it to my form will give me trouble.

Steve
 
Just use it in code as needed, like in a button click or something:
VB.NET:
Dim ofd As New OpenFileDialog
With ofd
 'Set properties
End With
If ofd.ShowDialog(Me) <> DialogResult.Cancel Then
  'Code
End If
 
The basic principal of the openfiledialog as a non-visual component is the ability to have some standardized setting. however, it is only necessary when one does a lot of file dialog openings and such. I usually drop them on the form but as JuggaloBrotha indicated it is superfluous really.

However, the nature of the error you were receiving was due to the "FileName" setting. The Default Setting of the OpenFileDialog has this:
VB.NET:
CheckFileExists = True

What is, is that basically, sometimes the refresh doesn't exactly occur on the fly as it should so when you:
VB.NET:
if OpenDlg.ShowDialog = DialogResult.OK then
  DoSomething(OpenDlg.Filename)
endif
you don't need to add in a : If IO.File.Exists(OpenDlg\.FileName) then because the OpenDlg does it for you.

However, the down side is when you try to set the FileName property of the OpenDlg to a file that does not exist such as the depicted line
shaught said:
VB.NET:
'OpenFileDialog1
        '
        Me.OpenFileDialog1.FileName = "OpenFileDialog1"
It raises an exception, and that exception was happening during the form creation. I've had that problem before too, with the other facets of the OpenFileDialog:
VB.NET:
CheckPathExists = True
InitialDirectory = "BadFormatedPath"

In order to by pass a lot of these issues you can do as JuggaloBrotha suggested, or, if you'd prefer to keep the dialog as a component on the form, initialize it's values during the Form Load, which is my preferred method, as I can directly set the InitialDirectory to a Saver User Setting, as well as all the file filters and such whether they be constant strings or stored in the Application.Settings or my own preferences object, etc.

Hope this helps.
 
I didn't know that about OFD's either, then again I never put dialog's on my actual forms either, I create them as needed in the Button's or MenuStripItems as needed.
 
Back
Top