2 Replies - 1109 Views - Last Post: 03 July 2012 - 07:50 AM Rate Topic: -----

#1 Mr_Bateman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-July 12

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...


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



Is This A Good Question/Topic? 0
  • +

Replies To: Command Button worked in VB 2010, now I need it to work in VB6

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

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:

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

Was This Post Helpful? 0
  • +
  • -

#3 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

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:
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 :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1