News, tips, advice, support for Windows, Office, PCs & more. Tech help. No bull. We're community supported by donations from our Plus Members, and proud of it
Home icon Home icon Home icon Email icon RSS icon
  • VB – app runs from C drive but not network

    Posted on WSDiana Comment on the AskWoody Lounge

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

    Viewing 1 reply thread
    • Author
      • #351914 Reply
        AskWoody Lounger

        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

      • #510562 Reply
        AskWoody Lounger

        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,

        • #510662 Reply
          AskWoody Lounger

          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), _

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

          ‘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 Reply
            AskWoody Lounger

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

    Viewing 1 reply thread

    Please follow the -Lounge Rules- no personal attacks, no swearing, and politics/religion are relegated to the Rants forum.

    Reply To: VB – app runs from C drive but not network

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