Private Sub Command1_Click() Dim path As String = "C:\test.INI" ' NOT WORKING If IO.File.Exists("C:\test.INI") Then Dim companyFile As IO.TextWriter companyFile = IO.File.AppendText(path) companyFile.WriteLine (( Address.Text)) ' Takes address and writes to file companyFile.WriteLine (( Name.Text)) ' Takes name and writes to file companyFile.WriteLine (( Number.Text)) ' Takes number and writes to file companyFile.Flush() ' NOT WORKING companyFile.Close() ' NOT WORKING End If End Sub
2 Replies - 2462 Views - Last Post: 03 July 2012 - 07:50 AM
#1
Command Button worked in VB 2010, now I need it to work in VB6
Posted 02 July 2012 - 01:09 PM
I am taking a button command from Vb2010 and I have to use it in a VB6 program... What I have is below...Can someone tell me why this doesn't work in VB6? The program takes fields from the user and enters them into a text.INI file...
Replies To: Command Button worked in VB 2010, now I need it to work in VB6
#2
Re: Command Button worked in VB 2010, now I need it to work in VB6
Posted 02 July 2012 - 02:28 PM
You can't declare a string like that in VB6, you can do either of the following:
In regards to the file handling, there is no IO.TextWriter assembly, so have a look into the FileSystemObject.
Dim strPath as String strPath = "C:\test.INI" or if it's fixed, you could declare as a constant Const cstPath = "C:\test.INI"
In regards to the file handling, there is no IO.TextWriter assembly, so have a look into the FileSystemObject.
This post has been edited by maj3091: 02 July 2012 - 02:28 PM
#3
Re: Command Button worked in VB 2010, now I need it to work in VB6
Posted 03 July 2012 - 07:50 AM
few things:
1) usually its bad idea to hardwire a file address in a program, it could make the program not work well or usually crash.
if the file is in the folder where the program is you can use:
2) to know if a file exist or not you need to use VB6 Dir$ function.
example to know if a file exist or not and display proper message:
3) you can use FileSystemObject (FSO) or you could open a file in other ways if you'd like.
you should do some research about opening file for: Input, Output, Appened, Rendom and Binary.
4) for INI files you might want to use completaly different functions that allow even easier writing/reading ini
i hope i helped a bit
1) usually its bad idea to hardwire a file address in a program, it could make the program not work well or usually crash.
if the file is in the folder where the program is you can use:
strPath=App.Path\ & "FileName"while FileName is of course the file's name and it has to be placed inside the " ".
2) to know if a file exist or not you need to use VB6 Dir$ function.
example to know if a file exist or not and display proper message:
If Dir$(Full file path) <> "" then MsgBox "File Exist" Else MsgBox "File Dont Exist!" End If
3) you can use FileSystemObject (FSO) or you could open a file in other ways if you'd like.
you should do some research about opening file for: Input, Output, Appened, Rendom and Binary.
4) for INI files you might want to use completaly different functions that allow even easier writing/reading ini
i hope i helped a bit

Page 1 of 1