3 Replies - 4142 Views - Last Post: 07 May 2008 - 07:18 AM Rate Topic: -----

#1 lajjw  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-November 07

How can I pass a structure variable my code is not allowing me to use

Post icon  Posted 07 May 2008 - 01:27 AM

Public Class DJPlayList
    ' Class Level Private variables
    'structure definition
    Structure Songs
        Public strSongName As String
        Public strSongCatagory As String
        Public decSongLength As Decimal
    End Structure

    'declare an empty array 
    Public invSongItems() As Songs
    Private Sub DJPlaylist(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' The DJPlaylist load event reads the song text file and
        ' fills the ComboBox object with the song items

        ' Initialize an instance of the StreamReader object and 
        ' declare variables
        Dim objReader As IO.StreamReader
        Dim strLocationAndNameOfFile As String = "e:\songs.txt"
        Dim intCount As Integer = 0
        Dim intFill As Integer
        Dim strFileErrorMessage As String = _
            "The file is not available. Restart when the file is available."

        ' Verify the file exists
        If IO.File.Exists(strLocationAndNameOfFile) Then
            objReader = IO.File.OpenText(strLocationAndNameOfFile)

            ' Read the file line by line until the file is completed
            Do While objReader.Peek <> -1
                'redimension array to count items and fill the structure
                ReDim Preserve invSongItems(intCount)
                'use the with construct to avoid having to type invInventoryitems(intCount)
                'infront of each variable member
                With invSongItems(intCount)
                    .strSongName = objReader.ReadLine()
                    .strSongCatagory = objReader.ReadLine()
                    .decSongLength = Convert.ToDecimal(objReader.ReadLine())
                End With
                'increase loop counter 
                intCount += 1
            Loop

            objReader.Close()

            ' The ComboBox object is filled with the Inventory IDs
            For intFill = 0 To (invSongItems.Length - 1)
                Me.cboSonggenre.Items.Add(invSongItems(intFill).strSongCatagory)
            Next
        Else
            MessageBox.Show(strFileErrorMessage, "Error")
            Me.Close()
        End If

    End Sub
    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayPlayList.Click

        Dim intTime As Integer
        Dim intCount As Integer
        Dim intSeconds As Integer
        Dim intTempTime As Integer
        Dim intLength As Integer  'length of array
        Dim decLength As Decimal
        Dim strGendre As String
        Dim strOutPut As String
        'clear the list box
        Me.lstPlayList.Items.Clear()

        'do we have a number int the textbox
        If (IsNumeric(Me.txtPlaylistTime.Text)) Then
            'read length from textbox
            decLength = Convert.ToDecimal(Me.txtPlaylistTime.Text)

            'convert length to seconds
            intSeconds = convertToSeconds(decLength)

            'if no item selected list all songs to time length
            If Me.cboSonggenre.SelectedIndex = -1 Then
                'while still time and more items in array
                While intTime < intSeconds And intCount < intLength

                    intTempTime = convertToSeconds(decSongLength(intCount))
                    If intSeconds >= intTempTime + intTime Then
                        intTime += intTempTime
                        strOutPut = intCount.ToString + ".    " + strSongName(intCount) + "     " + decSongLength(intCount).ToString
                        Me.lstPlayList.Items.Add(strOutPut)
                    End If

                    intCount += 1
                End While
            Else
                strGendre = Me.cboSonggenre.SelectedItem
                While intTime < intSeconds And intCount < intLength

                    If strGendre = strSongCatagory(intCount).ToUpper Then
                        intTempTime = convertToSeconds(decSongLength(intCount))
                        If intSeconds >= intTempTime + intTime Then
                            intTime += intTempTime
                            strOutPut = intCount.ToString + ".    " + strSongName(intCount) + "     " + decSongLength(intCount).ToString
                            Me.lstPlayList.Items.Add(strOutPut)
                        End If
                    End If

                    intCount += 1
                End While
            End If
        Else
            MessageBox.Show("Please enter the length of program", "Data Entry Error")
        End If
    End Sub
    Private Function convertToSeconds(ByVal decLength As Decimal) As Integer
        Dim intLength As Integer
        Dim intMinutes As Integer
        Dim intSeconds As Integer

        intMinutes = decLength
        intSeconds = (decLength * 100) Mod 100
        intLength = intSeconds + intMinutes * 60

        Return intLength
    End Function
    Private Sub mnuDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDisplay.Click
        Dim frmSecond As New displaySongList
        Me.Hide()
        frmSecond.Show()
    End Sub
    Private Function MinToSeconds(ByVal strTime As String) As Integer

        Dim intMinutes As Integer
        Dim intSeconds As Integer
        Dim intConvertedTime As Integer
        Dim decTime As Decimal

        decTime = Convert.ToDecimal(strTime)
        intSeconds = Convert.ToInt32(decTime * 100) Mod 100
        intMinutes = Convert.ToInt32(decTime)

        intConvertedTime = intMinutes * 60 + intSeconds
        Return intConvertedTime
    End Function

    Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClear.Click
        Me.txtPlaylistTime.Clear()
        Me.cboSonggenre.SelectedIndex = -1
        Me.lstPlayList.Items.Clear()

    End Sub

    Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnueXit.Click
        Me.Close()
    End Sub


End Class



EDIT: Code blocks added, please use them in the future => :code:

This post has been edited by PsychoCoder: 07 May 2008 - 07:18 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How can I pass a structure variable my code is not allowing me to use

#2 anand_the_great  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 15-April 08

Re: How can I pass a structure variable my code is not allowing me to use

Posted 07 May 2008 - 01:37 AM

Hello.

Dude would you please be specific.
We would appreciate if could quote your code.

Thanks.
Anand.
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5314
  • View blog
  • Posts: 27,220
  • Joined: 10-May 07

Re: How can I pass a structure variable my code is not allowing me to use

Posted 07 May 2008 - 01:39 AM

Quote

How can I pass a structure variable my code is not allowing me to use

By not allowing ... do you mean you are getting an error? What happens when you try to pass a structure variable?

Also, for future reference:
:code:
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How can I pass a structure variable my code is not allowing me to use

Posted 07 May 2008 - 07:18 AM

1) Post your question in the body of your post, not the title or description.
2) This is VB.NET so Im moving it there :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1