Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 86,467 VB.NET Programmers. There are 1,283 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a VB.NET Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

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

 
Reply to this topicStart new topic

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

lajjw
post 7 May, 2008 - 01:27 AM
Post #1


New D.I.C Head

*
Joined: 9 Nov, 2007
Posts: 1



vb

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.gif

This post has been edited by PsychoCoder: 7 May, 2008 - 07:18 AM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


anand_the_great
post 7 May, 2008 - 01:37 AM
Post #2


New D.I.C Head

*
Joined: 15 Apr, 2008
Posts: 27

Hello.

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

Thanks.
Anand.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

no2pencil
post 7 May, 2008 - 01:39 AM
Post #3


DIC K-mart

Group Icon
Joined: 10 May, 2007
Posts: 3,326

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.gif

User is online!Profile CardPM
Go to the top of the page
+Quote Post

PsychoCoder
post 7 May, 2008 - 07:18 AM
Post #4


ToCode || !ToCode

Group Icon
Joined: 26 Jul, 2007
Posts: 5,860

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 smile.gif
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 05:06PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month