Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    53
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Question Real quick VB code needed

    hello coding forums right now im trying to add in file extensions to a modifed open dialog box so it saves which works perfect but i need help with putting in file extensions like html, css, java. those sorts of thing so could anyone help me with it.

    also here is the code im using for the save dialog

    Code:
    Dim ofd As New SaveFileDialog()
            If ofd.ShowDialog() = DialogResult.OK Then
                RichTextBox1.Text = System.IO.File.ReadAllText(ofd.FileName)
            End If
    also this is in VB

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,752
    Thanks
    41
    Thanked 191 Times in 190 Posts
    what? I have no clue what you are trying to do- are you trying to write html/css/javascript in the dialog box and then do something with it?
    if that is the case then this link should get you on the track of manipulating text within a "box" the next step would be to convert it all to a string parse out the extension and then save it using the file class accordingly- but again I do not know what you are trying to do exactly.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    53
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by alykins View Post
    what? I have no clue what you are trying to do- are you trying to write html/css/javascript in the dialog box and then do something with it?
    if that is the case then this link should get you on the track of manipulating text within a "box" the next step would be to convert it all to a string parse out the extension and then save it using the file class accordingly- but again I do not know what you are trying to do exactly.
    im trying to make it where when they save it it saves as a html, css, or php, etc file like notepad++ where you type the file extension and it saves it like that. its hard for me to explain.

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Are you asking how to define the list of file extensions available in the Files of Type field dropdown in the Save Dialog box?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    53
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Spookster View Post
    Are you asking how to define the list of file extensions available in the Files of Type field dropdown in the Save Dialog box?
    yeah i guess.

    though when i save it while im running the debugger i get an error message though this happens when i try to find it and when i click on it, it says missing shortcut(this is a whole other problem though)

    Also when i save it as .html thats what i get ^

    though it saves it as an html file. sorry if you do not understand what im saying.

  • #6
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,752
    Thanks
    41
    Thanked 191 Times in 190 Posts
    ok so first step- where are the contents of the file being taken from? is this an upload control? are they typing in all the contents? I am so confused as to what/how you are trying to do- moreover what exactly you are trying to do- have you looked at the .net File class? ref ... can you post the code you have so we can try to figure out what you're trying to do

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #7
    New Coder
    Join Date
    Jan 2012
    Posts
    53
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by alykins View Post
    ok so first step- where are the contents of the file being taken from? is this an upload control? are they typing in all the contents? I am so confused as to what/how you are trying to do- moreover what exactly you are trying to do- have you looked at the .net File class? ref ... can you post the code you have so we can try to figure out what you're trying to do
    well here is my code though i do not get what your saying in the first 3/4th of it.

    Form1 (code/text writer)

    Code:
    Public Class Form1
    
        Private Property Extensions As Object
    
        Private Sub OpenToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OpenToolStripMenuItem.Click
            Dim ofd As New OpenFileDialog()
            If ofd.ShowDialog() = DialogResult.OK Then
                Dim filePath As String = ofd.FileName
                'do whatever the hell you want with it 
            End If
    
        End Sub
    
        
        Private Sub RichTextBox1_TextChanged(sender As System.Object, e As System.EventArgs)
    
        End Sub
    
        Private Sub Button1_Click_1(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Form2.Show()
            Form2.WebBrowser1.DocumentText = Me.RichTextBox1.Text
        End Sub
    
        Private Sub RichTextBox1_TextChanged_1(sender As System.Object, e As System.EventArgs) Handles RichTextBox1.TextChanged
            Form2.WebBrowser1.DocumentText = Me.RichTextBox1.Text
        End Sub
    
        Private Sub SaveToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SaveToolStripMenuItem.Click
    
        End Sub
    
        Private Sub NewFileToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles NewFileToolStripMenuItem.Click
            Dim ofd As New OpenFileDialog()
            If ofd.ShowDialog() = DialogResult.OK Then
                RichTextBox1.Text = System.IO.File.ReadAllText(ofd.FileName)
            End If
        End Sub
    
        Private Sub SaveAsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
            Dim ofd As New SaveFileDialog()
            If ofd.ShowDialog() = DialogResult.OK Then
                RichTextBox1.Text = System.IO.File.ReadAllText(ofd.FileName)
            End If
        End Sub
    End Class
    Form2 (code/text Viewer)

    Code:
    Public Class Form2
    
        Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    
        End Sub
    End Class

  • #8
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,752
    Thanks
    41
    Thanked 191 Times in 190 Posts
    I am still insanely confused as to what exactly your problem is- are you getting an error message? you said you have the save part correct but then you say you need help with the file extension... when opening you get to pick the file... ?! and the first post code you provided is for opening a file- is that what you are having issues with?
    here is some example code (granted it is C# it is an easy transition- get this part working and then get more "advanced")- a screen shot of the result is attached as well- it demos opening: .txt .htm .html .xml
    Code:
      private void button1_Click(object sender, EventArgs e)
            {
                OpenFileDialog openme = new OpenFileDialog();
                for (int i = 0; i < 4; i++)
                {
                    using (openme)
                    {
                        if (openme.ShowDialog() == DialogResult.OK)
                        {
                            string filename = openme.FileName;
                            switch (i)
                            {
                                case 0:
                                    label1.Text = filename;
                                    richTextBox1.Text = System.IO.File.ReadAllText(openme.FileName);
                                    break;
                                case 1:
                                    label2.Text = filename;
                                    richTextBox2.Text = System.IO.File.ReadAllText(openme.FileName);
                                    break;
                                case 2:
                                    label3.Text = filename;
                                    richTextBox3.Text = System.IO.File.ReadAllText(openme.FileName);
                                    break;
                                case 3:
                                    label4.Text = filename;
                                    richTextBox4.Text = System.IO.File.ReadAllText(openme.FileName);
                                    break;
                            }
                        }
                    }
                }
            }
    also look @ these references
    FileDialog
    DefaultExt

    aside from that I am stumped as to what exactly your question is- can you elaborate what it is you are having issues with?
    Attached Thumbnails Attached Thumbnails Real quick VB code needed-demo.png  

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #9
    New Coder
    Join Date
    Jan 2012
    Posts
    53
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by alykins View Post
    I am still insanely confused as to what exactly your problem is- are you getting an error message? you said you have the save part correct but then you say you need help with the file extension... when opening you get to pick the file... ?! and the first post code you provided is for opening a file- is that what you are having issues with?
    here is some example code (granted it is C# it is an easy transition- get this part working and then get more "advanced")- a screen shot of the result is attached as well- it demos opening: .txt .htm .html .xml
    Code:
      private void button1_Click(object sender, EventArgs e)
            {
                OpenFileDialog openme = new OpenFileDialog();
                for (int i = 0; i < 4; i++)
                {
                    using (openme)
                    {
                        if (openme.ShowDialog() == DialogResult.OK)
                        {
                            string filename = openme.FileName;
                            switch (i)
                            {
                                case 0:
                                    label1.Text = filename;
                                    richTextBox1.Text = System.IO.File.ReadAllText(openme.FileName);
                                    break;
                                case 1:
                                    label2.Text = filename;
                                    richTextBox2.Text = System.IO.File.ReadAllText(openme.FileName);
                                    break;
                                case 2:
                                    label3.Text = filename;
                                    richTextBox3.Text = System.IO.File.ReadAllText(openme.FileName);
                                    break;
                                case 3:
                                    label4.Text = filename;
                                    richTextBox4.Text = System.IO.File.ReadAllText(openme.FileName);
                                    break;
                            }
                        }
                    }
                }
            }
    also look @ these references
    FileDialog
    DefaultExt

    aside from that I am stumped as to what exactly your question is- can you elaborate what it is you are having issues with?
    well im not sure either now but i decided to just get rid of it and decided to make my program a simple html viewer.


  •  

    Posting Permissions

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