4 Replies - 1633 Views - Last Post: 15 June 2011 - 12:11 AM Rate Topic: -----

#1 MysteriousKiddo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-June 11

How do i create a text file in vb6?

Posted 14 June 2011 - 11:32 AM

Hey currently i just started using file manipulation today and i find it very fun.
So anyway this is my code:
Option Explicit
Dim Filename As String
Dim Channel_number As Integer

Private Sub cmdClear_Click()
Text1.Text = " "
End Sub

Private Sub cmdCreate_Click()
Filename = InputBox("Please enter a filename")
    Open Filename For Output As #1
    Print #1, Text1.Text
    Close #1
End Sub

Private Sub cmdExit_Click()
'END PROGRAM
    Dim response As String
    response = MsgBox("Are you sure you want to exit this program", vbYesNo)
    If response = vbYes Then
        End
    End If
    If response = vbNo Then
    MsgBox "Carry On"
    End If
End Sub

'*******************************************************
'Program for file manipulation using windows interface *
'                                                      *
'Re-created by me in 14/06/2011                        *
'*******************************************************
Private Sub cmdLoad_Click()
'Using the OPEN dialogue box
    CommonDialog1.Filter = "All files (*.*) |*.*|Text_files(*.txt)|*.txtlVB_Text_files(*.frx)|*.frx"
    CommonDialog1.ShowOpen
    Filename = CommonDialog1.Filename
    Open Filename For Input As #1
    Text1.Text = Input$(LOF(1), 1)
    Close #1
End Sub

Private Sub cmdSave_Click()
'Using SAVE AS dialogue box
    CommonDialog1.Filter = "All files (*.*) |*.*|Text_filed(*.txt)"
    CommonDialog1.ShowSave
    Filename = CommonDialog1.Filename
    Open Filename For Output As #1
    Print #1, Text1.Text
    Close #1
End Sub
As you can currently see i am doing Private Sub cmdCreate_Click()
Filename = InputBox("Please enter a filename")
    Open Filename For Output As #1
    Print #1, Text1.Text
    Close #1
End Sub 


to open a file but i find this very bad since they need to type the directory is there anyway i can make it open the windows interface to create it? or possibly make it a default to c:\ or something like that

Thanks

This post has been edited by macosxnerd101: 14 June 2011 - 11:33 AM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: How do i create a text file in vb6?

#2 MysteriousKiddo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-June 11

Re: How do i create a text file in vb6?

Posted 14 June 2011 - 11:52 AM

so nobody im guessing
Was This Post Helpful? 0
  • +
  • -

#3 Rhymer  Icon User is offline

  • D.I.C Regular

Reputation: 23
  • View blog
  • Posts: 282
  • Joined: 21-April 09

Re: How do i create a text file in vb6?

Posted 14 June 2011 - 12:06 PM

I usually make a variable Pth$ to hold app.path & "/" then when you open the file use pth & filename. That way it will be in the same folder as your program.
Two things:
You will want to filter the name the user types to make sure it is a 'file name friendly' string.
However if you pass it to the open dialog I think it will warn you if there are disallowed characters.
You will also want to add some error checking for open failure.

Was This Post Helpful? 0
  • +
  • -

#4 MysteriousKiddo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-June 11

Re: How do i create a text file in vb6?

Posted 14 June 2011 - 01:49 PM

View PostRhymer, on 14 June 2011 - 12:06 PM, said:

I usually make a variable Pth$ to hold app.path & "/" then when you open the file use pth & filename. That way it will be in the same folder as your program.
Two things:
You will want to filter the name the user types to make sure it is a 'file name friendly' string.
However if you pass it to the open dialog I think it will warn you if there are disallowed characters.
You will also want to add some error checking for open failure.

I know how it says that you wont do my homework or do the code, but this isnt homework and i dont understand a word you just said :L
Was This Post Helpful? 0
  • +
  • -

#5 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,776
  • Joined: 26-March 09

Re: How do i create a text file in vb6?

Posted 15 June 2011 - 12:11 AM

As a starting point, have a search on CommonDialog control on the forum or in google.

This is what is used to open up the standard windows dialog to allow the user to browse to a folder.

It's a useful control and doesn't just handle file open/save.

It should allow you to do what you need and is quite simple to use.

Have a go and if you have any questions, just post the code you've done and the issues you have and we'll be happy to assist.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1