|
-
Aug 1st, 2004, 03:24 PM
#1
Thread Starter
Lively Member
New open and save problem [Resolved]
For a very weird reason, I can't save, nor open. It won't let me specify what to open and pops up a error whenever I try to.
This is my main program. It won't load or save.
VB Code:
Option Strict On
Option Explicit On
Public Class Chaoseditor
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Dim theButton As Long
theButton = MsgBox("Do you wish to exit?", MsgBoxStyle.YesNo)
If theButton = vbYes Then
End
Else
End If
End Sub
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Opn.Filter = "GDP Game Developement Project (*.gdp)|*.gdp|All files (*.*)|*.*" ' Open Game Dev Project (No workie)
Opn.FilterIndex = 1
Opn.ShowDialog()
End Sub
Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
Dim SV As SaveFileDialog
SV.Filter = "GDP Game Developement Project (*.gdp)|*.gdp*" ' save as Game Dev Project (no workie)
Sv.FilterIndex = 1
SV.ShowDialog()
End Sub
Private Sub NewToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem4.Click
CCE.Show() ' Show Chaos Code editor
End Sub
End Class
This one pops up a error when I press Open, and then cancel. It points to the commented command when I do.
VB Code:
Public Class CCE
Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.Click
End Sub
Private Sub CompileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CompileToolStripMenuItem.Click
End Sub
Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
Dim dlg1 As New CCE
dlg1.ShowDialog() ' Pressed new show's new form
End Sub
Function Color(ByVal source As String) As Double
'If Replace(source, " ", "") Then End ' If source "" or " " then end it
Dim rtb As RichTextBox ' name rtb as a RichText Box type
' Dim Codearray() As String ' It's the array of text
' Dim currentline As String ' The currentline of Text
' Dim Line As Integer ' Dunno why I can't use somthing smaller ...
' Dim I As Byte 'Smallest thing
' Codearray = Split(source, vbCrLf) ' split Code array from source at Center Left
' For I = LBound(Codearray) To UBound(Codearray) From lower case to uppercase
'currentline = Codearray(I) ' Code array for line
' Line = LTrim(Replace(Replace(currentline, " ", ""), vbTab, "")) ' add auto tab
' Select Case Left() ' the left case
' Case "//" ' comments
'rtb.Text = currentline ' trb on current line
' rtb.SelectedText = Len(currentline) ' select text
'End Select
'Next
'rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Bold)' make her bold!
End Function
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RTB2.TextChanged
End Sub
Private Sub EditorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditorToolStripMenuItem.Click
Me.Hide()
End Sub
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Dim Fn As String ' call this as string
OFD2.Filter = "Chaos Code Program (*.ccp)|*.ccp" ' make type .ccp
OFD2.FilterIndex = 1 ' use .ccp
Fn = OFD2.ShowDialog() ' show the Open dialog
If Fn = "" Then Exit Sub ' if the text is nothing then exit (no workie)
If Fn <> "" Then ' if it doesn't equel nothing then open file, also no workie
' OFD2.OpenFile() ' No workie
End If
End Sub
End Class
I'm stumped
Last edited by Word2; Aug 1st, 2004 at 08:45 PM.
-
Aug 1st, 2004, 04:21 PM
#2
Frenzied Member
You've got a couple things going on here. For one, it looks like you're expecting to receive a file name from this:
VB Code:
Fn = OFD2.ShowDialog() ' show the Open dialog
You really recieve a DialogResult, which VB is automatically turning into a string and putting in your Fn variable. Run this code and you'll see what I mean:
VB Code:
Dim myString As String
myString = OpenFileDialog1.ShowDialog()
MessageBox.Show(myString)
Notice the result if you click ok or cancel.
If you want the file name choosen, use
VB Code:
MessageBox.Show(OpenFileDialog1.FileName)
I guess the second problem is this?
VB Code:
If Fn <> "" Then ' if it doesn't equel nothing then open file, also no workie
' OFD2.OpenFile() ' No workie
End If
I assume you realize that your OpenFile method is commented out. Calling OpenFile will return a stream. Is that what you mean to do? Or do you wish to "open" the file, like in a text editor or some other app?
-
Aug 1st, 2004, 04:52 PM
#3
Thread Starter
Lively Member
Thanks for so far. The last thing. I intended to have it open and display in the RitchTextBox.
-
Aug 1st, 2004, 05:15 PM
#4
Frenzied Member
ok - what have you tried so far?
-
Aug 1st, 2004, 05:33 PM
#5
Thread Starter
Lively Member
Absolutly nothing, as I don't know how. You guessed right if you thought I was a beginner at VB. I also don't know how to save the text in a RTF box and open a file and display it in a RTF box. IF you can help me with that I would be thankfull.
-
Aug 1st, 2004, 07:35 PM
#6
Frenzied Member
umm, I'm not sure either, but I tried I tried by looking at the members of RichTextBox and going from there. I'm no expert either, this is my first time trying something like this.
One would think that the LoadFile and SaveFile method would do the trick. I just tried the LoadFile method, but ran into trouble. I created a .rtf file from Word (Office 2003), then tried to load like this
VB Code:
RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.RichText)
But I get an Argument Exception, additional information says "Invalid File Format".
I could load my .rtf file with
VB Code:
RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
But then my rtf control will filled with binary stuff, and not the formatted rtf.
So, I have no idea what I'm doing wrong. I did not try saving, then loading my rtf control, just tried to load an rtf saved from Word.
Not even sure if this helps, but what the heck.
-
Aug 1st, 2004, 07:38 PM
#7
Thread Starter
Lively Member
I'll fiddle around with it. If you could keep a open mind and eye out for somthing that might work.
I would be very greatfull (and will be when this is fineshed).
-
Aug 1st, 2004, 07:46 PM
#8
Frenzied Member
If you figure it out, post it. Maybe I'm doing something wrong, because it throws that exception. But I copied the code from MSDN (at least I think) and it throws an exception, at least from my rtf created by Word 2003.
If I had time, I would search this forum, then google. Can't be the first person trying to do the same thing. As I'm tracking down this nasty bug I happened to write, focused on that right now
-
Aug 1st, 2004, 07:58 PM
#9
Thread Starter
Lively Member
Ok, it doesn't throw me a error with RichText at the end.
My only problem is it doesn't put the text in the RichTextBox. I will look around though.
-
Aug 1st, 2004, 08:14 PM
#10
Frenzied Member
hmmm. This code works for me just fine to save the rtf
VB Code:
RichTextBox1.SaveFile("c:\temp\test.rtf")
and then, I can load the rtf control with
VB Code:
OpenFileDialog1.ShowDialog()
RichTextBox1.LoadFile(OpenFileDialog1.FileName)
The load file completely replaces the contents of the rtf. Even tried it with word again, and it seems to work fine. Not sure what I did the first time around, but now I cannot generate that exception.
-
Aug 1st, 2004, 08:45 PM
#11
Thread Starter
Lively Member
Thanks alot. It works. Perfectly, I just had to modify it abit!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|