Geeks With Blogs

News View Matt Christian's profile on LinkedIn


Code.Blog Code Talk for the Game Developer
Hooray!  I have a GeeksWithBlogs blog!  Welcome to my blog which will focus on my ramblings and posts related to game and application development.  I'm just getting into my Exploring Technology class (boo!) but I should update later with some code snippets and such.

Update:  Well class isn't over but I'm bored so I'll post some code I figured out last night:

    let opSaveFile sender args =
        if (documentList.Item(lstProject.SelectedIndex).isNew = true) then
            let ofdDialog = new SaveFileDialog(Filter = "SCompiler Files (*.scpt)|*.scpt|All Types|*.*", Title = "Save Script As...") in
            if ofdDialog.ShowDialog() = DialogResult.OK then begin
                match ofdDialog.OpenFile() with
                | null -> txtLog.AppendText("File Save Failed")
                | stream ->
                    let r = new StreamWriter(stream) in
                    prevSelection <- lstProject.SelectedIndex;                   
                    r.Write(txtEditor.Text);
                    r.Close();
                    documentList.RemoveAt(lstProject.SelectedIndex);
                    documentList.Add({fullpath=ofdDialog.FileName; filename=ofdDialog.FileName.Remove(0, ofdDialog.FileName.LastIndexOf("\\") + 1); text=txtEditor.Text; isNew=false;});
                    lstProject.SelectedIndex <- documentList.Count - 1;
                    txtLog.AppendText("\nFile Saved: " + documentList.Item(lstProject.SelectedIndex).filename);
            end;
           
        else
            let r = new StreamWriter(documentList.Item(lstProject.SelectedIndex).fullpath) in
            r.Write(txtEditor.Text);
            r.Close();
            txtLog.AppendText("\nFile Saved: " + documentList.Item(lstProject.SelectedIndex).filename);
            lstProject.Refresh();;

Notice the begin and end bolded parts.  Without those the else wants to attach itself with that first if, sort of acting like a { } in C++ and C#.  Anyways, seems like something really simple but in F# you don't really use 'end if' style items so you need to block off your if sections with ( ) or begin end. Posted on Monday, April 7, 2008 9:04 AM | Back to top


Comments on this post: First Blog Post

# re: First Blog Post
Requesting Gravatar...
Welcome to the GWB community. Looking forward to what you've got to say!
Left by Jerod Crump on Apr 07, 2008 10:34 AM

Your comment:
 (will show your gravatar)


Copyright © Matthew Christian | Powered by: GeeksWithBlogs.net