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.
Monday, April 07, 2008 9:04 AM