Results 1 to 4 of 4

Thread: Problem with compiling SaveAs code

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Location
    Binghamton, New York
    Posts
    11

    Question Problem with compiling SaveAs code

    I am trying to write the code for the Save As function in my program.
    I can get the SaveDialogBox up, and if the filename exists, that part works OK, and if you hit Cancel, that works OK.
    But the code won't compile because it sees FileMode and FileAccess as undeclared.
    Also the FileNotFoundException doesn't seem to be part of this set, and is not recognized. What am I missing?

    Anyone know?
    If not, does anyone have any canned code to execute the SaveAs DialogBox?





    Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click
    Dim fileChooser As SaveFileDialog = New SaveFileDialog
    Dim result As DialogResult = filechooser.ShowDialog
    Dim fileName As String
    Dim output As FileStream


    fileChooser.CheckFileExists = False
    If result = DialogResult.Cancel Then
    Return
    End If
    fileName = fileChooser.FileName
    If (fileName = "" OrElse fileName = Nothing) Then
    MessageBox.Show("Invalid File Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

    Else
    Try
    output = New FileStream(fileName, FileMode.OpenorCreate, FileAccess.Write)

    Catch fileException As FileNotFoundException

    MessageBox.Show("File Not Found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
    End If
    End Sub

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    try importing System.IO
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Location
    Binghamton, New York
    Posts
    11

    still get compile errors

    When I added the Imports System.IO, I noticed that one of the exceptions went away - concerning the FileNotFoundException, which previously was not recognized. However,the exception I can't get past is this which occurs on this line of code :

    output = New FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)

    The exception that is raised when trying to compile is "Too many arguments for Public Sub New()"


    The following is what is in Public Sub New()

    Imports System.IO
    Imports System.Windows.Forms
    Class Form1

    Inherits System.Windows.Forms.Form
    #Region " Windows Form Designer generated code "

    Public Sub New()
    'MyBase.New()
    Me.SaveFileDialog1.Filter = "Text Files|*.txt|RTF files|*.rtf|All files|*.*"
    Me.SaveFileDialog1.InitialDirectory = "C:/Documents and Settings/Owner/My Documents"
    Me.OpenFileDialog1.Filter = "Text Files|*.txt|RTF files|*.rtf|All files|*.*"
    Me.OpenFileDialog1.InitialDirectory = "C:/Documents and Settings/Owner/My Documents"

    'Add any initialization after the InitializeComponent() call

    End Sub


    What is wrong?

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: still get compile errors

    Originally posted by jtenright
    When I added the Imports System.IO, I noticed that one of the exceptions went away - concerning the FileNotFoundException, which previously was not recognized. However,the exception I can't get past is this which occurs on this line of code :

    output = New FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)

    The exception that is raised when trying to compile is "Too many arguments for Public Sub New()"


    The following is what is in Public Sub New()

    Imports System.IO
    Imports System.Windows.Forms
    Class Form1

    Inherits System.Windows.Forms.Form
    #Region " Windows Form Designer generated code "

    Public Sub New()
    'MyBase.New()
    Me.SaveFileDialog1.Filter = "Text Files|*.txt|RTF files|*.rtf|All files|*.*"
    Me.SaveFileDialog1.InitialDirectory = "C:/Documents and Settings/Owner/My Documents"
    Me.OpenFileDialog1.Filter = "Text Files|*.txt|RTF files|*.rtf|All files|*.*"
    Me.OpenFileDialog1.InitialDirectory = "C:/Documents and Settings/Owner/My Documents"

    'Add any initialization after the InitializeComponent() call

    End Sub


    What is wrong?
    I dotn know the reason for error but what you have in sub new is pretty bad fist of all uncomment the mybase.new, second add teh InitializeComponent function after it... otherwise your controls wont show up

    hmm that line of code should be working fine and I dont think sub new should be raising any errors. more code maybe?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width