BlueOysterCult Posted November 23, 2003 Posted November 23, 2003 Hello All I was able to get a FileOPenDialog to work but when I pick a file I get an error that lands on Me.Cursor - I don't know why I have it there. I think I picked it accidently but now I don't want it?) any ideas what I need to put there? here's my code Dim openFileDialog1 As New OpenFileDialog openFileDialog1.InitialDirectory = "C:\Documents and Settings\Rob\School\CIS 172\cdCollection\bin\" openFileDialog1.Filter = "CD files (*.CDS)|*.CDS|All files (*.*)|*.*" ' Display an OpenFileDialog so the user can select a file. openFileDialog1.Filter = "CD Files|*.cds" openFileDialog1.Title = "Select a Cd File" ' Show the Dialog. If openFileDialog1.ShowDialog() = DialogResult.OK Then If openFileDialog1.FileName <> "" Then Me.Cursor = New Cursor(openFileDialog1.OpenFile()) End If End If Thanks Rob Quote
Leaders dynamic_sysop Posted November 23, 2003 Leaders Posted November 23, 2003 should this line....Me.Cursor = New Cursor(openFileDialog1.OpenFile()) be changed to ending with openFileDialog1.Filename ? , also don't cursors have a .CUR extension? Quote
BlueOysterCult Posted November 23, 2003 Author Posted November 23, 2003 I am having the only able to pick CDS files do I change Cursor to CDS? Should I just take that line out? cute kids btw R Quote
Leaders dynamic_sysop Posted November 23, 2003 Leaders Posted November 23, 2003 are you trying to change the Cursor , to one thats inside the same folder as the CDS? maybe you could set the filter to CDS and CUR. or if you know the name of the cursor in the folder ( ie: it matches the CDS's name , but ends with .CUR ) you could try replacing the extension in the Filename string. Quote
BlueOysterCult Posted November 23, 2003 Author Posted November 23, 2003 I guess I am not understanding what the cursor is or what it does. I commented out the line and it didn't blow up. But now I am trying to read in an array - a do until EOF in there -which I am not getting to work R Quote
Administrators PlausiblyDamp Posted November 23, 2003 Administrators Posted November 23, 2003 Cursor is just the mouse pointer on screen (Arrow, hand etc.) I think you may be mistaking it for a database cursor. How are you reading in the file - if you are using a System.IO.StreamReader you shouldn't need to be checking for EOF anyway. Post some code and see if we can help. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
BlueOysterCult Posted November 23, 2003 Author Posted November 23, 2003 Thanks The idea here is that I need to have the user open a file from a list of files (Cds - for cd collections) and then once clicked it displays the first file from that collection here is the cose from the Module Region "Global Variables" ' For Cd data from file Public gstrArtist As String, gstrTitle As String, gshtYear As Short, gstrCategory As String ' For file number and file name Public gintCdFileNum As Integer = -999 ' -999 means "no file is open" Public gstrCdFileName As String = "CdCollection.cds" Public CdArray() As CdType #End Region #Region "Utility Procedures (non-UI)" Public Sub OpenFile() ' Get an available file number, store it in the global variable, and open the file. gintCdFileNum = FreeFile() FileOpen(gintCdFileNum, gstrCdFileName, OpenMode.Input) End Sub Public Sub GetNextRecord() ' Get the next record, but only if we aren't already at the end of the file If Not EOF(gintCdFileNum) Then Input(gintCdFileNum, gstrArtist) Input(gintCdFileNum, gstrTitle) Input(gintCdFileNum, gshtYear) Input(gintCdFileNum, gstrCategory) End If End Sub Public Sub CloseFile() ' Close the file and set the file number to an invalid value (so we aren't ' tempted to try to use it again) If gintCdFileNum <> -999 Then FileClose(gintCdFileNum) gintCdFileNum = -999 End If End Sub Public Sub MoveToStartOfFile() ' Close and open the file--easiest way to get the pointer back to the start! CloseFile() OpenFile() End Sub Structure CdType Dim Artist As String Dim Title As String Dim Year As Short Dim Category As String End Structure #End Region End Module and here is the code for the UI Private Sub ToggleUIItems() ' Switch items to opposite enabling from present state. This happens when we move ' back and forth from a state of a file being open to a file not being open. ' Note that the File Exit command is always available, so we don't toggle it. ' Also note that we are toggling the Previous items, even though they aren't ' implemented in the first version. ' File menu mnuFileOpen.Enabled = Not mnuFileOpen.Enabled mnuFileClose.Enabled = Not mnuFileClose.Enabled ' Action menu mnuActionNext.Enabled = Not mnuActionNext.Enabled mnuActionPrevious.Enabled = Not mnuActionPrevious.Enabled mnuActionGoToStart.Enabled = Not mnuActionGoToStart.Enabled mnuActionFind.Enabled = Not mnuActionFind.Enabled ' Buttons btnNext.Enabled = Not btnNext.Enabled btnPrevious.Enabled = Not btnPrevious.Enabled End Sub Private Sub SetFormCaption(ByVal strFileName As String) ' Set form caption, if provided. If empty, set to default name. If strFileName = "" Then Me.Text = "CD Collection" Else Me.Text = strFileName & " - CD Collection" End If End Sub Private Sub UpdateFormData() ' Set form data based on globals txtArtist.Text = gstrArtist txtTitle.Text = gstrTitle txtYear.Text = gshtYear.ToString txtCategory.Text = gstrCategory End Sub Private Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles mnuFileOpen.Click Dim openFileDialog1 As New OpenFileDialog Dim LineofText As String openFileDialog1.InitialDirectory = "C:\Documents and Settings\Rob\School\CIS 172\cdCollection\bin\" openFileDialog1.Filter = "CD files (*.CDS)|*.CDS|All files (*.*)|*.*" ' Display an OpenFileDialog so the user can select a file. openFileDialog1.Filter = "CD Files|*.cds" openFileDialog1.Title = "Select a Cd File" ' Show the Dialog. If openFileDialog1.ShowDialog() = DialogResult.OK Then If openFileDialog1.FileName <> "" Then Do Until EOF(1) Loop 'Me.Cursor = New Cursor(openFileDialog1.OpenFile()) End If End If 'If openFileDialog1.FileName <> "" Then ' Try ' Do Until EOF(1) ' LineofText = CdArray() ' Loop ' Catch ' MsgBox("Error opening file") ' End Try 'End If openFileDialog1.FilterIndex = 2 openFileDialog1.RestoreDirectory = True ToggleUIItems() SetFormCaption(gstrArtist) 'GetNextRecord() UpdateFormData() End Sub Private Sub mnuFileClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles mnuFileClose.Click ToggleUIItems() SetFormCaption("") 'CloseFile() ' Blank out the global CD data & update the UI gstrArtist = "" gstrTitle = "" gshtYear = 0 gstrCategory = "" UpdateFormData() End Sub Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click 'CloseFile() End End Sub Private Sub mnuActionFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles mnuActionFind.Click MessageBox.Show("Not yet implemented", "Work in Progress", MessageBoxButtons.OK, _ MessageBoxIcon.Information) End Sub Private Sub MoveNext(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles mnuActionNext.Click, btnNext.Click 'GetNextRecord() UpdateFormData() End Sub Private Sub MovePrevious(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles mnuActionPrevious.Click, btnPrevious.Click MessageBox.Show("Not yet implemented", "Work in Progress", MessageBoxButtons.OK, _ MessageBoxIcon.Information) End Sub Private Sub mnuActionGoToStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuActionGoToStart.Click 'MoveToStartOfFile() 'GetNextRecord() UpdateFormData() End Sub End Class Do I still need to EOF the file - how do I get it to display the first collection? THanks a bunch Rob Quote
Administrators PlausiblyDamp Posted November 23, 2003 Administrators Posted November 23, 2003 You should have a look at the System.IO namespace, the newer .Net file handling stuff is in there. Classes to start looking at in this case are: System.IO.File System.IO.FileStream System.IO.StreamReader Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
BlueOysterCult Posted November 23, 2003 Author Posted November 23, 2003 MY teacher is not keen on the StreamReader idea. We should be using the FileOPen stuff - Quote
*Experts* mutant Posted November 23, 2003 *Experts* Posted November 23, 2003 If your teacher teaches you .NET and tells you to use old VB6 methods then don't listen to him/her :). Quote
BlueOysterCult Posted November 23, 2003 Author Posted November 23, 2003 I did though.. do the streamreader thing and had it go to a msgBox so I can see if it could read the file and it did work R Quote
BlueOysterCult Posted November 23, 2003 Author Posted November 23, 2003 PArt of the assignmnet is to have a dialog "open File" box pop up to choose from a list of files... can it be done with StreamReader? R Quote
Administrators PlausiblyDamp Posted November 23, 2003 Administrators Posted November 23, 2003 The file open dialog will just give you a file name, that will work just fine with System.IO.File.OpenText() As Mutant says though - if your teacher tells you to avoid streamreaders and then says use the FileOpen way instead I would seriously doubt his .Net knowledge. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
BlueOysterCult Posted November 24, 2003 Author Posted November 24, 2003 Thanks for the reply Actually he is THE best teacher I have ever had and I have been doing this stuff (VB UNIX SQL etc ) for a while now. I will try the Open.Text etc Thanks Rob Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.