• VB – app runs from C drive but not network

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » VB – app runs from C drive but not network

    Author
    Topic
    #351914

    I’m a novice to VB.
    I have created an application that reads info from an ini file & displays in message box.

    I can run the app from my C drive.
    However when I place app on network & run from the network
    it doesnt pick up the ini file key.

    Do I need to specify path of ini file in my code?
    As I thought if ini file is with my app & I have specied the name will read from within that directory?

    ALso are there any other steps I should be doing?
    Much appeciated TIA
    Diana

    Viewing 0 reply threads
    Author
    Replies
    • #510562

      Hi Diana,

      How do you read the INI file?
      I use:
      x = System.PrivateProfileString(FilePath, “Section”, “key”)
      and I specify the full path of the file to make it work.

      The Help tells me the following, which indicates that it might be searching the Windows folder:

      expression.PrivateProfileString(Filename, Section, Key)

      Filename – Required String.
      The file name for the settings file. If there’s no path specified, the Windows folder (Windows) or the Preferences folder (Macintosh) is assumed. If you’re using Windows 95 or Windows NT to return a setting from the registry, Filename must be an empty string (“”).

      Hope this helps,
      Margaret

      • #510662

        Hi Margaret

        In VB – to read the ini file I have the following code.

        The code works when run on my c drive.
        However when testing on another users pc the path of the ini file is displayed instead of the value of the kye.
        When I change the code & insert full path of ini file – & run on other users pc – the path is displayed.

        Its like the code is not locating or reading the ini file key’s value.
        In VB I thought you didnt have to hard code the location of ini file if in same location as project.

        WhenI dont hard code path for ini file & test from my pc – it works – ie it reads the ini file value & displays.

        Private Sub Form_Load()

        Dim lngResult As Long
        Dim strFileName
        Dim strResult As String * 50
        Dim strHeading As String
        Dim strKey As String

        strFileName = “UserMsgBox.ini”
        strHeading = “GenericMessage”
        strKey = “MessageText”

        ‘call function to obtain information from ini file
        lngResult = GetPrivateProfileString(strHeading, _
        strKey, strFileName, strResult, Len(strResult), _
        strFileName)

        ‘if string length is 0 -an error has occurred or no text
        If lngResult = 0 Then
        lblMessage = (“Error! Could not find text message.”)

        Else
        ‘else display text found in ini file
        lblMessage = Trim(strResult)
        End If

        In the module I have declared the following functions:

        Option Explicit

        Declare Function WritePrivateProfileString _
        Lib “kernel32” Alias “WritePrivateProfileStringA” _
        (ByVal lpApplicationname As String, ByVal _
        lpKeyName As Any, ByVal lsString As Any, _
        ByVal lplFilename As String) As Long ‘

        Declare Function GetPrivateProfileString Lib _
        “kernel32” Alias “GetPrivateProfileStringA” _
        (ByVal lpApplicationname As String, ByVal _
        lpKeyName As String, ByVal lpDefault As _
        String, ByVal lpReturnedString As String, _
        ByVal nSize As Long, ByVal lpFileName As _
        String) As Long

        • #510690

          Have you used code to write the private profile string on the machine that doesn’t work and then tried running this code?

    Viewing 0 reply threads
    Reply To: VB – app runs from C drive but not network

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: