Results 1 to 11 of 11

Thread: New open and save problem [Resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Location
    Can't say sorry :)
    Posts
    79

    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:
    1. Option Strict On
    2. Option Explicit On
    3. Public Class Chaoseditor
    4.     Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
    5.         Dim theButton As Long
    6.         theButton = MsgBox("Do you wish to exit?", MsgBoxStyle.YesNo)
    7.         If theButton = vbYes Then
    8.             End
    9.         Else
    10.  
    11.         End If
    12.     End Sub
    13.  
    14.     Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
    15.         Opn.Filter = "GDP Game Developement Project (*.gdp)|*.gdp|All files (*.*)|*.*" ' Open Game Dev Project (No workie)
    16.         Opn.FilterIndex = 1
    17.         Opn.ShowDialog()
    18.     End Sub
    19.  
    20.     Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
    21.         Dim SV As SaveFileDialog
    22.         SV.Filter = "GDP Game Developement Project (*.gdp)|*.gdp*" ' save as Game Dev Project (no workie)
    23.         Sv.FilterIndex = 1
    24.         SV.ShowDialog()
    25.  
    26.     End Sub
    27.  
    28.     Private Sub NewToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem4.Click
    29.         CCE.Show() ' Show Chaos Code editor
    30.     End Sub
    31. 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:
    1. Public Class CCE
    2.  
    3.     Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.Click
    4.  
    5.     End Sub
    6.  
    7.     Private Sub CompileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CompileToolStripMenuItem.Click
    8.  
    9.     End Sub
    10.  
    11.     Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
    12.         Dim dlg1 As New CCE
    13.         dlg1.ShowDialog() ' Pressed new show's new form
    14.  
    15.     End Sub
    16.     Function Color(ByVal source As String) As Double
    17.         'If Replace(source, " ", "") Then End ' If source "" or " " then end it
    18.         Dim rtb As RichTextBox ' name rtb as a RichText Box type
    19.         ' Dim Codearray() As String ' It's the array of text
    20.         ' Dim currentline As String ' The currentline of Text
    21.         ' Dim Line As Integer ' Dunno why I can't use somthing smaller ...
    22.         ' Dim I As Byte 'Smallest thing
    23.         ' Codearray = Split(source, vbCrLf) ' split Code array from source at Center Left
    24.         ' For I = LBound(Codearray) To UBound(Codearray) From lower case to uppercase
    25.         'currentline = Codearray(I) ' Code array for line
    26.         ' Line = LTrim(Replace(Replace(currentline, " ", ""), vbTab, "")) ' add auto tab
    27.         ' Select Case Left() ' the left case
    28.         ' Case "//" ' comments
    29.         'rtb.Text = currentline ' trb on current line
    30.         ' rtb.SelectedText = Len(currentline) ' select text
    31.         'End Select
    32.         'Next
    33.         'rtb.SelectionFont = New Font(rtb.SelectionFont, FontStyle.Bold)' make her bold!
    34.     End Function
    35.     Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RTB2.TextChanged
    36.  
    37.     End Sub
    38.  
    39.     Private Sub EditorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditorToolStripMenuItem.Click
    40.         Me.Hide()
    41.     End Sub
    42.  
    43.     Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
    44.         Dim Fn As String ' call this as string
    45.  
    46.         OFD2.Filter = "Chaos Code Program (*.ccp)|*.ccp" ' make type .ccp
    47.         OFD2.FilterIndex = 1 ' use .ccp
    48.         Fn = OFD2.ShowDialog() ' show the Open dialog
    49.         If Fn = "" Then Exit Sub ' if the text is nothing then exit (no workie)
    50.  
    51.         If Fn <> "" Then ' if it doesn't equel nothing then open file, also no workie
    52.             ' OFD2.OpenFile() ' No workie
    53.         End If
    54.     End Sub
    55.  
    56. End Class

    I'm stumped
    Last edited by Word2; Aug 1st, 2004 at 08:45 PM.



  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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:
    1. 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:
    1. Dim myString As String
    2.         myString = OpenFileDialog1.ShowDialog()
    3.         MessageBox.Show(myString)
    Notice the result if you click ok or cancel.

    If you want the file name choosen, use
    VB Code:
    1. MessageBox.Show(OpenFileDialog1.FileName)

    I guess the second problem is this?
    VB Code:
    1. If Fn <> "" Then ' if it doesn't equel nothing then open file, also no workie
    2.             ' OFD2.OpenFile() ' No workie
    3.         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?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Location
    Can't say sorry :)
    Posts
    79
    Thanks for so far. The last thing. I intended to have it open and display in the RitchTextBox.



  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    ok - what have you tried so far?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Location
    Can't say sorry :)
    Posts
    79
    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.



  6. #6
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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:
    1. 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:
    1. 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.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Location
    Can't say sorry :)
    Posts
    79
    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).



  8. #8
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Location
    Can't say sorry :)
    Posts
    79
    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.



  10. #10
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    hmmm. This code works for me just fine to save the rtf
    VB Code:
    1. RichTextBox1.SaveFile("c:\temp\test.rtf")

    and then, I can load the rtf control with
    VB Code:
    1. OpenFileDialog1.ShowDialog()
    2. 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.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Location
    Can't say sorry :)
    Posts
    79
    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
  •  



Click Here to Expand Forum to Full Width