3 Replies - 438 Views - Last Post: 19 December 2013 - 06:53 PM Rate Topic: -----

#1 cooljunk  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 14-November 13

Loading a picturebox from resources with 2 forms

Posted 17 December 2013 - 04:55 PM

Hello,
I am writing a zodiac program where the user enters their name, chooses a birth month, a birth day and the program will display the zodiac sign and clicks a button to see more.( This is all on form 1) On the second form, there is a welcome user message and a picturebox that I want to display their sign. I've downloaded all my images into the resources but can't get the picture to change per what the users sign is. I had it working and then changed a few hundred things and now I can't get it to work!! Any suggestions would help.
Here is my code:
Imports System.IO

Public Class frmZodiacMain
    Const strFILENAME As String = "ZodiacList.txt"
    Structure ZodiacData
        Dim firstName As String     ' To hold the first name
        Dim birthMonth As String  ' To hold the birth Month
        Dim birthDay As String   ' To hold the birthDay
        Dim zodiacSign As String        ' To hold the Zodiac Sign
    End Structure
    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CmbDay.SelectedIndexChanged

    End Sub

    Private Sub BtnClickToForm2_Click(sender As Object, e As EventArgs) Handles BtnClickToForm2.Click

        Dim frmTraits As New ZodiacTraits
        'frmTraits.ShowDialog()
        Timer1.Start()
        frmTraits.Show()
        frmTraits.LblZodiacTraits.Text = "Welcome " & TxtName.Text & " you are a " & LblZodiacResult.Text &
       " here is your info!"
        ' place the images into the resources 

        If Me.LblZodiacResult.Text = "Pisces" Then
            frmTraits.PictureBox1.Image = ZodiacFinal1.My.Resources.Resources.ugly_pisces_but_with_everything

        ElseIf Me.LblZodiacResult.Text = "Aries" Then
            frmTraits.PictureBox1.Image = ZodiacFinal1.My.Resources.Resources.Aries_with_stone__number__descript

        ElseIf Me.LblZodiacResult.Text = "Taurus" Then
            frmTraits.PictureBox1.Image = ZodiacFinal1.My.Resources.Resources.ugly_taurua

        ElseIf Me.LblZodiacResult.Text = "Gemini" Then
            frmTraits.PictureBox1.Image = ZodiacFinal1.My.Resources.Resources.ugly_gemini

        ElseIf Me.LblZodiacResult.Text = "Cancer" Then
            frmTraits.PictureBox1.Image = ZodiacFinal1.My.Resources.Resources.ugly_cancer

        ElseIf Me.LblZodiacResult.Text = "Leo" Then
            frmTraits.PictureBox1.Image = ZodiacFinal1.My.Resources.Resources.ugly_leo

        ElseIf Me.LblZodiacResult.Text = "Virgo" Then
            frmTraits.PictureBox1.Image = ZodiacFinal1.My.Resources.Resources.ugly_virgo_but_with_everything

        ElseIf Me.LblZodiacResult.Text = "Libra" Then
            frmTraits.PictureBox1.Image = ZodiacFinal1.My.Resources.Resources.ugly_libra

        ElseIf Me.LblZodiacResult.Text = "Scorpio" Then
            frmTraits.PictureBox1.Image = ZodiacFinal1.My.Resources.Resources.ugly_scorpio

        ElseIf Me.LblZodiacResult.Text = "Sagittarius" Then
            frmTraits.PictureBox1.Image = ZodiacFinal1.My.Resources.Resources.ugly_sagitarius

        ElseIf Me.LblZodiacResult.Text = "Capricorn" Then
            frmTraits.PictureBox1.Image = ZodiacFinal1.My.Resources.Resources.ugly_capricorn

            ' ElseIf Me.LblZodiacResult.Text = "Aquarius" Then
            ' frmTraits.PictureBox1.Image = ZodiacFinal1.My.Resources.Resources.ugly_aquarius

        End If


    End Sub





    Private Sub BtnExit_Click(sender As Object, e As EventArgs) Handles BtnExit.Click
        Me.Close()
    End Sub

    Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles BtnClear.Click

        LblZodiacResult.Text = ""
        CmbDay.Text = ""
        CmbMonth.Text = ""
        TxtName.Text = ""

        ' Reset the focus.
        TxtName.Focus()

    End Sub

    Private Sub mnuFileSave_Click(sender As Object, e As EventArgs) Handles mnuFileSave.Click
        Dim Zodiac As New ZodiacData

        Zodiac.firstName = TxtName.Text
        Zodiac.birthMonth = CmbMonth.Text
        Zodiac.birthDay = CmbDay.Text
        Zodiac.zodiacSign = LblZodiacResult.Text

        'write the record.
        WriteRecordToFile(Zodiac)

    End Sub

    Private Sub mnuFileSearch_Click(sender As Object, e As EventArgs) Handles mnuFileSearch.Click

        ' Search for a Zodiac File by name.
        Dim strName As String = InputBox("Enter the name of the Zodiac File.", "Search")
        FindRecord(strName.Trim())

    End Sub

    Sub WriteRecordToFile(ByRef Zodiac As ZodiacData)

        ' Save the record to the file.
        Dim ZodiacFile As System.IO.StreamWriter

        If File.Exists(strFILENAME) Then
            ' Open the file.
            ZodiacFile = File.AppendText(strFILENAME)
        Else
            ' The file does not exist, so create it.
            ZodiacFile = File.CreateText(strFILENAME)
        End If
        Try
            ' Write the record.
            ZodiacFile.WriteLine(Zodiac.firstName)
            ZodiacFile.WriteLine(Zodiac.birthMonth)
            ZodiacFile.WriteLine(Zodiac.birthDay)
            ZodiacFile.WriteLine(Zodiac.zodiacSign)

            ' Close the file.
            ZodiacFile.Close()
        Catch
            MessageBox.Show("The file cannot be created")
        End Try

    End Sub

    ' The FindRecord procecure searches the file for the video name.

    Sub FindRecord(ByVal strName As String)

        ' Search for a record in the file.
        Dim Zodiac As New ZodiacData
        Dim blnFound As Boolean = False
        Dim ZodiacFile As StreamReader

        If File.Exists(strFILENAME) Then
            ' Open the file.
            ZodiacFile = File.OpenText(strFILENAME)

            ' Search the records.
            Do Until ZodiacFile.EndOfStream Or blnFound

                ' Read the next record.
                Zodiac.firstName = ZodiacFile.ReadLine
                Zodiac.birthMonth = ZodiacFile.ReadLine
                Zodiac.birthDay = ZodiacFile.ReadLine
                Zodiac.zodiacSign = ZodiacFile.ReadLine

                'Is it the one?
                If strName.ToUpper = Zodiac.firstName.ToUpper Then
                    blnFound = True
                End If
            Loop

            ' Close the file.
            ZodiacFile.Close()

            If blnFound Then

                ' The name was found.
                TxtName.Text = Zodiac.firstName
                CmbMonth.Text = Zodiac.birthMonth
                CmbDay.Text = Zodiac.birthDay
                LblZodiacResult.Text = Zodiac.zodiacSign
            Else
                ' The name was not found
                MessageBox.Show(strName & " was not found.", "Record Not Found")
            End If
        Else
            ' Error opening file.
            MessageBox.Show("Cannot open file.", "Error")
        End If

    End Sub
    Public Function identifyzodiac()

        ' function used in identifying the zodiac on selected day and month

        If CmbMonth.Text = "February" And CmbDay.Text >= 19 Or CmbMonth.Text = "March" And CmbDay.Text <= 20 Then
            LblZodiacResult.Text = "PISCES"

        ElseIf CmbMonth.Text = "March" And CmbDay.Text >= 21 Or CmbMonth.Text = "April" And CmbDay.Text <= 19 Then
            LblZodiacResult.Text = "ARIES"

        ElseIf CmbMonth.Text = "April" And CmbDay.Text >= 20 Or CmbMonth.Text = "May" And CmbDay.Text <= 20 Then
            LblZodiacResult.Text = "TAURUS"

        ElseIf CmbMonth.Text = "May" And CmbDay.Text >= 21 Or CmbMonth.Text = "June" And CmbDay.Text <= 20 Then
            LblZodiacResult.Text = "GEMINI"

        ElseIf CmbMonth.Text = "June" And CmbDay.Text >= 21 Or CmbMonth.Text = "July" And CmbDay.Text <= 22 Then
            LblZodiacResult.Text = "CANCER"

        ElseIf CmbMonth.Text = "July" And CmbDay.Text >= 23 Or CmbMonth.Text = "August" And CmbDay.Text <= 22 Then
            LblZodiacResult.Text = "LEO"

        ElseIf CmbMonth.Text = "August" And CmbDay.Text >= 23 Or CmbMonth.Text = "September" And CmbDay.Text <= 22 Then
            LblZodiacResult.Text = "VIRGO"

        ElseIf CmbMonth.Text = "September" And CmbDay.Text >= 23 Or CmbMonth.Text = "October" And CmbDay.Text <= 22 Then
            LblZodiacResult.Text = "LIBRA"

        ElseIf CmbMonth.Text = "October" And CmbDay.Text >= 23 Or CmbMonth.Text = "November" And CmbDay.Text <= 21 Then
            LblZodiacResult.Text = "SCORPIO"

        ElseIf CmbMonth.Text = "November" And CmbDay.Text >= 22 Or CmbMonth.Text = "December" And CmbDay.Text <= 21 Then
            LblZodiacResult.Text = "SAGITTARIUS"

        ElseIf CmbMonth.Text = "December" And CmbDay.Text >= 22 Or CmbMonth.Text = "January" And CmbDay.Text <= 19 Then
            LblZodiacResult.Text = "CAPRICORN"

        ElseIf CmbMonth.Text = "January" And CmbDay.Text >= 20 Or CmbMonth.Text = "February" And CmbDay.Text <= 18 Then
            LblZodiacResult.Text = "AQUARIUS"
        End If

    End Function


    Private Sub CmbDay_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CmbDay.SelectedIndexChanged

        Call identifyzodiac() 'calling identifyzodiac function
    End Sub


End Class


the first form is called form1 and the second is called frmTraits. Ideas???

This post has been edited by Atli: 17 December 2013 - 05:19 PM
Reason for edit:: Use [code] tags when posting code.


Is This A Good Question/Topic? 0
  • +

Replies To: Loading a picturebox from resources with 2 forms

#2 poncianux  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 05-January 11

Re: Loading a picturebox from resources with 2 forms

Posted 19 December 2013 - 05:42 PM

Try this:

My.Resources.ugly_taurua


instead:

ZodiacFinal1.My.Resources.Resources.ugly_taurua

Was This Post Helpful? 0
  • +
  • -

#3 cooljunk  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 14-November 13

Re: Loading a picturebox from resources with 2 forms

Posted 19 December 2013 - 06:42 PM

Thanks for your reply. I tried it and it didn't work.
Was This Post Helpful? 0
  • +
  • -

#4 poncianux  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 05-January 11

Re: Loading a picturebox from resources with 2 forms

Posted 19 December 2013 - 06:53 PM

Is it throwing any exception?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1