Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Leaders
Posted

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.

Posted

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

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...