...

View Full Version : Real quick VB code needed



D34th Maker
01-16-2012, 10:36 PM
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


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

alykins
01-17-2012, 01:55 PM
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 (http://msdn.microsoft.com/en-us/library/ms533899(v=vs.85).aspx) 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.

D34th Maker
01-17-2012, 05:06 PM
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 (http://msdn.microsoft.com/en-us/library/ms533899(v=vs.85).aspx) 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.

Spookster
01-17-2012, 05:11 PM
Are you asking how to define the list of file extensions available in the Files of Type field dropdown in the Save Dialog box?

D34th Maker
01-17-2012, 05:26 PM
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.

alykins
01-17-2012, 06:10 PM
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 (http://msdn.microsoft.com/en-us/library/system.io.file.aspx) ... can you post the code you have so we can try to figure out what you're trying to do

D34th Maker
01-17-2012, 09:22 PM
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 (http://msdn.microsoft.com/en-us/library/system.io.file.aspx) ... 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)


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)


Public Class Form2

Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

End Sub
End Class

alykins
01-18-2012, 02:39 PM
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


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 (http://msdn.microsoft.com/en-us/library/8wk9scak.aspx)
DefaultExt (http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.defaultext.aspx)

aside from that I am stumped as to what exactly your question is- can you elaborate what it is you are having issues with?

D34th Maker
01-18-2012, 09:29 PM
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


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 (http://msdn.microsoft.com/en-us/library/8wk9scak.aspx)
DefaultExt (http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.defaultext.aspx)

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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum