Click here to Skip to main content
15,915,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am not sure what I am doing wrong, but here it goes.

Recently I downloaded a trial version of a control called Active Query Builder. I looked at one project called GeneralDemo.vbproj and started looking at its structure.

It contained a nice visual basic program to start the application, so I reused it.
VB
'Nice Start up routine from Active Query Builder
Imports System.Threading
Imports System.Windows.Forms

Friend NotInheritable Class Start
    Private Sub New()
        
    End Sub
    ''' <summary>
    ''' The main entry point for the application.
    ''' </summary>
    <STAThread> _
    Friend Shared Sub Main()
        ' Catch unhandled exceptions for debugging purposes
        AddHandler AppDomain.CurrentDomain.UnhandledException, _
            AddressOf CurrentDomain_UnhandledException
        AddHandler Application.ThreadException, _
            AddressOf Thread_UnhandledException

        Application.EnableVisualStyles()
        Application.SetCompatibleTextRenderingDefault(False)
        'The following is were we start the application
        Application.Run(New AccessConnectionForm())
    End Sub

    Private Shared Sub CurrentDomain_UnhandledException(sender As Object, _
                                                        e As UnhandledExceptionEventArgs)
        Dim exception As Exception = TryCast(e.ExceptionObject, Exception)
        If exception IsNot Nothing Then
            Dim exceptionDialog As New ThreadExceptionDialog(exception)
            If exceptionDialog.ShowDialog() = DialogResult.Abort Then
                Application.[Exit]()
            End If
        End If
    End Sub

    Private Shared Sub Thread_UnhandledException(sender As Object, _
                                                 e As ThreadExceptionEventArgs)
        If e.Exception IsNot Nothing Then
            Dim exceptionDialog As New ThreadExceptionDialog(e.Exception)

            If exceptionDialog.ShowDialog() = DialogResult.Abort Then
                Application.[Exit]()
            End If
        End If
    End Sub
End Class

The demo program also contained different connection forms for different database systems. For fun, I wanted to place an image to show me to which database I was trying to connect. So I placed a picture box on the form and I TRIED to load the .PNG file into the picture box.
VB
Imports System.Data.OleDb
Imports System.Windows.Forms

Partial Public Class AccessConnectionForm
    Inherits Form
    Public strAppPAth As String = Application.StartupPath
    Public ConnectionString As String = ""

    Public Sub New()
        InitializeComponent()
        picDB.Image = Image.FromFile(strAppPAth & "MS-Access.png")
    End Sub

    Private Sub btnConnect_Click(sender As Object, _
                                 e As EventArgs) Handles btnConnect.Click
        ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0"
        ConnectionString += ";Data Source=" & txtDB.Text
        ConnectionString += ";User Id=" & txtDB.Text
        ConnectionString += ";Password="

        If txtDB.Text.Length > 0 Then
            ConnectionString += txtDB.Text & ";"
        End If

        ' check the connection

        Using connection As New OleDbConnection(ConnectionString)
            Me.Cursor = Cursors.WaitCursor

            Try
                connection.Open()
            Catch ex As System.Exception
                MessageBox.Show(ex.Message, "Connection Failure.")
                Me.DialogResult = DialogResult.None
            Finally
                Me.Cursor = Cursors.[Default]
            End Try
        End Using
    End Sub

    Private Sub btnBrowse_Click(sender As Object, _
                                e As EventArgs) Handles btnBrowse.Click
        If openFileDialog1.ShowDialog() = DialogResult.OK Then
            txtDB.Text = openFileDialog1.FileName
        End If
    End Sub
End Class


I get an error at the strAppPath variable. I am trying to make the program executable from anywhere and it does not recognize the Resources folder where I am currently storing the image.

What I have tried:

The only thing I added was:
VB
Public strAppPath As String = Application.StartupPath

At the top of the Access Connection form. and -
VB
picDB.Image = Image.FromFile(strAppPAth & "MS-Access.png")

In the Public Sub New procedure when the form is started.

Can some one point out what I did wrong?

Thank you,
Posted
Updated 19-Jul-17 11:40am

Look at the path you create in

picDB.Image = Image.FromFile(strAppPAth & "MS-Access.png")

Does strAppPAth have the correct slashes?
Use System.IO.Path.Combine(string, string) to combine the path to the filename. Combine() will properly fix the slashes.
 
Share this answer
 
I have figured out what I did wrong.

1. Right click on the name of your solution in solution explorer and click on Properties.

2. Click on the Resources Tab and add the resources your solution requires.

3. In the form where you need the Resource, in may case a picture box add the following code.
PictureBox1.Image = My.Resources.<Image Name>


Knew it had to be something simple, but my coding skills have atrophied from lack of use.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900