Thread: VB6 Question
View Single Post
  #7   Spotlight this post!  
Unread 27-05-2004, 11:54
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
Re: VB6 Question

I would suggest you try using C# or VB.NET if you're just getting started with VB. The VS 6.0 tools won't be supported forever and you can do everything (and a lot more) with the .NET SDK.

Here is a sample class that has a method to save the information to a Word document. It only has two properties, Name and Bio. The Name will be written in 12pt Bold and the Bio in 10pt normal font. There is an overload that defaults to hiding and closing Word.

Code:
public class Person
{
	private string name;
	private string bio;

	public Person()
	{
		name = string.Empty;
		bio = string.Empty;
	}

	public Person(string n, string b)
	{
		name = n;
		bio = b;
	}

	public string Name
	{
		get { return this.name; }
		set { this.name = value; }
	}

	public string Bio
	{
		get { return this.bio; }
		set { this.bio = value; }
	}

	//overload of the ToWord method that does not display Word
	public void ToWord(string filename)
	{
		this.ToWord(filename, false);
	}

	//ToWord method writes the bio information to a new Word document.
	//the Show argument specifies whether we keep Word open.
	public void ToWord(string filename, bool show)
	{			
		//pointer to Word application
		Word.Application app = new Word.Application();

		//create a new document
		object opt = Missing.Value;
		Word.Document doc = app.Documents.Add(ref opt, ref opt, ref opt, ref opt);
		Word.Paragraph p;

		//add a new paragraph and write the person's name
		doc.Content.InsertParagraphAfter();			
		p = doc.Content.Paragraphs.Item(1);
		p.Range.Font.Name = "Verdana";
		p.Range.Font.Size = 12;
		p.Range.Font.Bold = 1;
		p.Range.Text = this.name;

		//add a new paragraph and write out the bio
		doc.Content.InsertParagraphAfter();
		p = doc.Content.Paragraphs.Item(2);
		p.Range.Font.Name = "Verdana";
		p.Range.Font.Size = 10;
		p.Range.Font.Bold = 0;
		p.Range.Text = this.bio;

		//save the document
		object file = filename;
		doc.SaveAs(ref file, ref opt, ref opt, ref opt, ref opt, 
				ref opt, ref opt, ref opt, ref opt, ref opt, ref opt, 
					ref opt, ref opt, ref opt, ref opt, ref opt);
			
		if (!show)
		{
			doc.Close(ref opt, ref opt, ref opt);
			app.Quit(ref opt, ref opt, ref opt);
		}
		else
		{
			app.Visible = true;
		}
	}
}

Last edited by seanwitte : 27-05-2004 at 23:18.