Results 1 to 3 of 3

Thread: Going from VB 2010 to VB6..why isn't this working?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    9

    Going from VB 2010 to VB6..why isn't this working?

    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" ' PROBLEM

    If IO.File.Exists("C:\test.INI") Then
    Dim companyFile As IO.TextWriter
    companyFile = IO.File.AppendText(path)
    companyFile.WriteLine (( Address.Text)) ' writes address to file
    companyFile.WriteLine (( Name.Text)) ' writes name to file
    companyFile.WriteLine (( Number.Text)) ' writes number to file
    companyFile.Flush() 'PROBLEM
    companyFile.Close() 'PROBLEM
    End If
    End Sub

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    21

    Re: Going from VB 2010 to VB6..why isn't this working?

    You can't initialize on the same line as declaration in VB6, you'd needa do:

    Code:
    Dim sPath as String
    sPath = "yourString"
    In regards to the rest, you need to look up syntax and what's available in VB6, it's not gonna have everything the newer language had.

  3. #3
    Addicted Member
    Join Date
    Sep 2009
    Posts
    190

    Re: Going from VB 2010 to VB6..why isn't this working?

    Code:
    Private Sub Form_Load()
    
        Dim path As String
        path = "C:\test.INI"
        Dim ff As Integer
        ff = FreeFile
        
        If FExist(path) Then
            Open path For Append As #ff
        Else
            Open path For Output As #ff
        End If
    
        Print #ff, Address.Text
        Print #ff, txtName.Text
        Print #ff, Number.Text
        Close #ff
    
    End Sub
    
    Public Function FExist(ffile As String) As Boolean
           FExist = False
           Const Attributes = vbDirectory Or vbVolume
           On Error Resume Next
           FExist = (GetAttr(ffile) And Attributes) = 0
           On Error GoTo 0
    End Function
    Now file don't have to exists. It will be created.
    Second time, and after that will be appended.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width