borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (get the computername or IP Address)Next Topic (Search Engine?) New Topic New Poll Post Reply
AndreaVB Forum : VB General : saving a file Solved Topic
Poster Message
tupadjia
Level: Protégé

Registered: 26-09-2006
Posts: 5

icon saving a file

Can anyone give me a code for when a button is clicked, ie, File, Save As, the files saves to your desired location
I've been reasearching and researching and nothing

05-10-2006 at 11:22 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: saving a file

Hello. 'Saving a file' is not an operation. What do you mean to do with your click? Writing the contents of a variable/an array/a picturebox/a control/an entire form/a recordset/whatever else of yours into an existing file? And in what format? Create a new file with the above contents? Provide user the feature to choose the location in which the new file have to be created? Simply copying an existing file in another location? Create a periodical backup of a file? Create an empty file?

In poor words: what are you exactly intending to do?

____________________________
Real Programmer can count up to 1024 on his fingers

06-10-2006 at 06:49 AM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: saving a file

Just like was said... if you want to save a file, you have to manually write every byte/word to a blank file.

Which means you have to open the filename for writing... print the stuff to the file, and close it.

____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

06-10-2006 at 08:06 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
tupadjia
Level: Protégé

Registered: 26-09-2006
Posts: 5
icon Re: saving a file

what i basically want to do is, when some results appear in the List Box, I want the user to be able to save those results in, lets say, .txt or .rtf file.
how do I do that?

07-10-2006 at 07:42 AM
View Profile Send Email to User Show All Posts | Quote Reply
sinner
Level: Protégé

Registered: 07-10-2006
Posts: 4
icon Re: saving a file

Do you mean something like this:

To save the File:
Private Sub Command1_Click()
Dim ff As Integer, i As Integer
Dim ln As String

    'to save it

    ff = FreeFile 'that is your file number
        Open "C:\test.txt" For Output As #ff 'opening the file (even if it does not exist yet) for writing - output
            'write each list item with the loop
                Print #ff, Text1.Text
          
        Close #ff 'dont forget to close the file

End Sub


To read the File:
Private Sub Command2_Click()
Dim ff As Integer
Dim ln As String
    'to read it
    ff = FreeFile
    List1.Clear

        Open "c:\test.txt" For Input As #ff 'open it for reading - input
            Do Until EOF(ff)  'read until the end of file
                Line Input #ff, ln 'input each line
                    List1.AddItem ln 'add it to the list
            Loop
        Close #ff
End Sub


Hope it helps you a bit  

08-10-2006 at 08:11 AM
View Profile Send Email to User Show All Posts | Quote Reply
sinner
Level: Protégé

Registered: 07-10-2006
Posts: 4
icon Re: saving a file

Or you can use the common dialog control to save it like this:

Module:
---------
Public Function SaveText(Text As String, FileName As String) As Boolean

Dim sTemp As String
    sTemp = Text
    Open FileName For Append As #1  'Opening the file to SaveText
        Print #1, sTemp             'Printing  the text to the file
    Close #1                        'Closing
Exit Function
End Function


Next add A Textbox and a Command button on to your Form. And add the CommonDialog Control on to your Form set the name to cdlg

Add this code on to the Form:
---------------------------------
Private Sub Command1_Click()
    cdlg.ShowSave
    SaveText Text1, cdlg.FileName & ".txt"
End Sub


Is this what you mean

08-10-2006 at 08:35 AM
View Profile Send Email to User Show All Posts | Quote Reply
tupadjia
Level: Protégé

Registered: 26-09-2006
Posts: 5
icon Re: saving a file

thats exactly what i mean, thanks very much!

10-10-2006 at 05:18 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : saving a file Solved Topic
Previous Topic (get the computername or IP Address)Next Topic (Search Engine?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder