Results 1 to 6 of 6

Thread: Why doesn't this work?

  1. #1

    Thread Starter
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472
    Private Sub Form_Load()
    Dim stCurDir As String
    Dim stIniFile As String

    stIniFile = App.Path & "\list.ini"

    'make sure the file exists
    If Dir$(stIniFile) <> "" Then
    Open stIniFile For Input As #1

    Line Input #1, stCurDir

    If Trim$(stCurDir) <> "" Then
    If Dir$(stCurDir, vbDirectory) <> "" Then
    ChDir (stCurDir)
    End If
    End If

    Close #1
    End If
    End Sub

    It wont open the .ini to get the set directory...
    Why?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Have you checked the value of stIniFile to make sure it's looking in the right place?

    App.Path points to the location from which your project was launched, so if you opened your project from within VB, then the App.Path would point to your VB location, i.e. "C:\Program Files\Microsoft Visual Studio\VB98"

  3. #3

    Thread Starter
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472
    nope...in the right place...it just wont read the .ini file...is there another way to do it?

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Have you traced the code to see what is happening? I copied your code and placed a list.ini file in the app.path and while I don't know what your list.ini file looks like, by tracing I was able see that the ini file is read.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You could always handle using else in your code whenever you use if to avoid errors:
    Code:
    Private Sub Form_Load()
    Dim stCurDir As String
    Dim stIniFile As String
        
        stIniFile = App.Path & "\list.ini"
        
        'make sure the file exists
        If Dir$(stIniFile) <> "" Then
            Open stIniFile For Input As #1
        
            Line Input #1, stCurDir
        
            If Trim$(stCurDir) <> "" Then
                If Dir$(stCurDir, vbDirectory) <> "" Then
                    ChDir (stCurDir)
                Else
                    MsgBox "Stored Directory " & stCurDir & "not found"
                End If
            Else
                MsgBox "INIFILE empty"
            End If
        
            Close #1
        Else
            MsgBox "INIFILE " & stIniFile & " not found"
        End If
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472
    I fixed it...

    (If your free please check out my post titled Lawrence Jesterton)

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