Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 1st, 2011, 09:43 AM
Registered User
 
Join Date: May 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Display, and Double-Space an Existing Text File?

Hello everyone. I'm a novice, working on a very simple program in both VB 6 and VB 2008. Visual Basic 6 seems much easier to write code with, so I'm sticking with it for this project.

I have a form with eight text boxes that I input text into.

There is also a command button. The command button simply creates a text file, and stores the inputted text in that file. Here's the code I wrote for the command button:

Private Sub Generate_Click()
Dim info As String
info = "c:\Movies.txt"
Open info For Append As #1
Print #1, "Title: " & Title.Text
Print #1, "Director: " & Director.Text
Print #1, "Starring: " & Starring.Text
Print #1, "IMDB: " & IMDB.Text
Print #1, "Running Time: " & RunningTime.Text
Print #1, "Genre: " & Genre.Text
Print #1, "Subtitles: " & Subtitles.Text
Print #1, "Year of Release: " & Year.Text
Print #1, "Comments: " & CommentsText
Close #1
MsgBox "Your file has been created."
End Sub


So simple, even I can understand it. So far....

I want to do a few more things with this code, and am requesting help, if I may, please.

First of all, being a novice, I am not yet sure how to add code to the above that lets the file be opened and displayed. In VB 2008, the code to do this is:

Process.Start("c:\Movies.txt ")

Which I put in after the MsgBox line.

I do not know what to use for Visual Basic 6. Can anyone please tell me what to use?

Secondly: I want the file to be double-spaced. I know I could put
Print #1, ""

In between each line. However, just to learn programming a bit better, I'd like to know if it's possible to write code to double-space the file in one fell swoop, so to speak. Perhaps a FOR-NEXT loop that would automate the process, or some other procedure.

Is this possible? If so, what sort of commands should I use? Is it worth the effort, or would the Print #1, "" option just be easier?

The third thing I want to do is more complex, and I'll save this for another thread. But just to mention it...what I want to do is create a SAVE AS dialog box where the user can select the drive and folder where the file is to be stored, and give the file a name. Is this possible? Would I have to write entirely different code other than the Open File command?

Thank you very much for any assistance you care to give. J. Danniel (Please call me Jd.)
 
Old June 1st, 2011, 09:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Lightbulb

Hi there..

let go in order if we can...

Quote:
I want to do a few more things with this code, and am requesting help, if I may, please.

First of all, being a novice, I am not yet sure how to add code to the above that lets the file be opened and displayed. In VB 2008, the code to do this is:

Process.Start("c:\Movies.txt ")

Which I put in after the MsgBox line.

I do not know what to use for Visual Basic 6. Can anyone please tell me what to use?
Let's see.. When you do process.start on any file, is like double clicking on it... So it will open the correct process to handle it.. It's working because windows know how to open a txt..
To do the same trick on VB6, use shell()....

Quote:
Secondly: I want the file to be double-spaced. I know I could put
Print #1, ""
That's by far the best way... On .net you have a writeln on a stream, that write a line and add a new line/carriage return char at the end.. it's exactly the same...

Quote:
In between each line. However, just to learn programming a bit better, I'd like to know if it's possible to write code to double-space the file in one fell swoop, so to speak. Perhaps a FOR-NEXT loop that would automate the process, or some other procedure.

Is this possible? If so, what sort of commands should I use? Is it worth the effort, or would the Print #1, "" option just be easier?
Well.. a for and then what?? a select case to choose the line?? that's a no no what you can do, instead, is write a function that receive a file handle and a string, and write the string and a new empty line on the file... that way you will write only one time the new line... think about it...

Quote:
The third thing I want to do is more complex, and I'll save this for another thread. But just to mention it...what I want to do is create a SAVE AS dialog box where the user can select the drive and folder where the file is to be stored, and give the file a name. Is this possible? Would I have to write entirely different code other than the Open File command?
In .net the object you need is there, already code for you and ready to use.. in vb6, you have a folder navigator, a drive navigator to do that, but you have to manually do it....
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Double display of html:select option cesarv JSP Basics 6 July 20th, 2009 05:49 AM
How can i get rid off the double quote in a text myer75 VBScript 7 April 14th, 2009 07:11 PM
converting double to text in editbox rupali_mb Visual C++ 1 February 11th, 2007 12:14 PM
Space in a Text Box mcinar HTML Code Clinic 1 May 5th, 2005 01:07 AM
Adding SPACE before text dwrs XSLT 3 February 6th, 2004 09:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.