Results 1 to 6 of 6

Thread: VB Program on a non-English speaking computer

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    29

    VB Program on a non-English speaking computer

    I'm having severe problems getting a app to run on a customer's computer in Chili. This brings up a problem I had never thought of before. I have written a VB 6 app that at one point accesses a file whose path is "C:/Users/Public/".
    But on my customer's computer, the path is something like "C:/Usarios/Accesso de Publico/". Something in the installation program (which I did not write) translated and installed the files in the right location, but now my program apparently cannot find them. (BTW, the program runs fine on my computer and every other English-speaking computer that I know of.)

    How, or what, does the translation when an app, written in English, is installed on a non-English-speaking computer? And do you think it would do any good if this customer made a special folder/path with the specific name: "C:/Users/Public/"?

    Any and all helpful suggestions thoroughly appreciated.

    HalW

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: VB Program on a non-English speaking computer

    You could use the special folder which would use the folder on that computer no matter what it is named or if your exe is there you could use app.path

    Yes if they created a folder structure with that naming it should work. i.e. C:\Users\Public

    Also you should know that you should never hard code a path into an application, this will almost always come back to bite you if you distribute the app.
    Last edited by DataMiser; Feb 5th, 2013 at 07:35 PM.

  3. #3
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: VB Program on a non-English speaking computer

    use API to retrieve system folder instead of fixed path.

  4. #4
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: VB Program on a non-English speaking computer

    i would try this way
    Code:
    Environ("PUBLIC")
    this would be used to make sure it is same path on every computer. there are other ways like app.path as DataMiser said

  5. #5
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: VB Program on a non-English speaking computer

    This might work.

    vb Code:
    1. Option Explicit
    2. '
    3. Private Const CSIDL_DESKTOP                     As Long = &H0
    4. Private Const CSIDL_INTERNET                    As Long = &H1
    5. Private Const CSIDL_PROGRAMS                    As Long = &H2
    6. Private Const CSIDL_CONTROLS                    As Long = &H3
    7. Private Const CSIDL_PRINTERS                    As Long = &H4
    8. Private Const CSIDL_PERSONAL                    As Long = &H5
    9. Private Const CSIDL_FAVORITES                   As Long = &H6
    10. Private Const CSIDL_STARTUP                     As Long = &H7
    11. Private Const CSIDL_RECENT                      As Long = &H8
    12. Private Const CSIDL_SENDTO                      As Long = &H9
    13. Private Const CSIDL_BITBUCKET                   As Long = &HA
    14. Private Const CSIDL_STARTMENU                   As Long = &HB
    15. Private Const CSIDL_MYDOCUMENTS                 As Long = &HC
    16. Private Const CSIDL_MYMUSIC                     As Long = &HD
    17. Private Const CSIDL_MYVIDEO                     As Long = &HE
    18. Private Const CSIDL_DESKTOPDIRECTORY            As Long = &H10
    19. Private Const CSIDL_DRIVES                      As Long = &H11
    20. Private Const CSIDL_NETWORK                     As Long = &H12
    21. Private Const CSIDL_NETHOOD                     As Long = &H13
    22. Private Const CSIDL_FONTS                       As Long = &H14
    23. Private Const CSIDL_TEMPLATES                   As Long = &H15
    24. Private Const CSIDL_COMMON_STARTMENU            As Long = &H16
    25. Private Const CSIDL_COMMON_PROGRAMS             As Long = &H17
    26. Private Const CSIDL_COMMON_STARTUP              As Long = &H18
    27. Private Const CSIDL_COMMON_DESKTOPDIRECTORY     As Long = &H19
    28. Private Const CSIDL_APPDATA                     As Long = &H1A
    29. Private Const CSIDL_PRINTHOOD                   As Long = &H1B
    30. Private Const CSIDL_LOCAL_APPDATA               As Long = &H1C
    31. Private Const CSIDL_ALTSTARTUP                  As Long = &H1D
    32. Private Const CSIDL_COMMON_ALTSTARTUP           As Long = &H1E
    33. '
    34. Private Const CSIDL_COMMON_FAVORITES            As Long = &H1F
    35. Private Const CSIDL_INTERNET_CACHE              As Long = &H20
    36. Private Const CSIDL_COOKIES                     As Long = &H21
    37. Private Const CSIDL_HISTORY                     As Long = &H22
    38. Private Const CSIDL_COMMON_APPDATA              As Long = &H23
    39. Private Const CSIDL_WINDOWS                     As Long = &H24
    40. Private Const CSIDL_SYSTEM                      As Long = &H25
    41. Private Const CSIDL_PROGRAM_FILES               As Long = &H26
    42. Private Const CSIDL_MYPICTURES                  As Long = &H27
    43. Private Const CSIDL_PROFILE                     As Long = &H28
    44. Private Const CSIDL_PROGRAM_FILES_COMMON        As Long = &H2B
    45. Private Const CSIDL_COMMON_TEMPLATES            As Long = &H2D
    46. Private Const CSIDL_COMMON_DOCUMENTS            As Long = &H2E
    47. Private Const CSIDL_COMMON_ADMINTOOLS           As Long = &H2F
    48. Private Const CSIDL_ADMINTOOLS                  As Long = &H30
    49. Private Const CSIDL_CONNECTIONS                 As Long = &H31
    50. Private Const CSIDL_COMMON_MUSIC                As Long = &H35
    51. Private Const CSIDL_COMMON_PICTURES             As Long = &H36
    52. Private Const CSIDL_COMMON_VIDEO                As Long = &H37
    53. Private Const CSIDL_RESOURCES                   As Long = &H38
    54. Private Const CSIDL_RESOURCES_LOCALIZED         As Long = &H39
    55. Private Const CSIDL_COMMON_OEM_LINKS            As Long = &H3A
    56. Private Const CSIDL_CDBURN_AREA                 As Long = &H3B
    57. Private Const CSIDL_COMPUTERSNEARME             As Long = &H3D
    58. '
    59. Public Enum SpecialFolders
    60.     '
    61.     Desktop = CSIDL_DESKTOP
    62.     Internet = CSIDL_INTERNET
    63.     Programs = CSIDL_PROGRAMS
    64.     Controls = CSIDL_CONTROLS
    65.     Printers = CSIDL_PRINTERS
    66.     Personal = CSIDL_PERSONAL
    67.     Favorites = CSIDL_FAVORITES
    68.     Startup = CSIDL_STARTUP
    69.     Recent = CSIDL_RECENT
    70.     SendTo = CSIDL_SENDTO
    71.     BitBucket = CSIDL_BITBUCKET
    72.     StartMenu = CSIDL_STARTMENU
    73.     MyDocuments = CSIDL_MYDOCUMENTS
    74.     MyMusic = CSIDL_MYMUSIC
    75.     MyVideo = CSIDL_MYVIDEO
    76.     DesktopDirectory = CSIDL_DESKTOPDIRECTORY
    77.     Drives = CSIDL_DRIVES
    78.     Network = CSIDL_NETWORK
    79.     NetHood = CSIDL_NETHOOD
    80.     Fonts = CSIDL_FONTS
    81.     Templates = CSIDL_TEMPLATES
    82.     Common_StartMenu = CSIDL_COMMON_STARTMENU
    83.     Common_Programs = CSIDL_COMMON_PROGRAMS
    84.     Common_Startup = CSIDL_COMMON_STARTUP
    85.     Common_DesktopDirectory = CSIDL_COMMON_DESKTOPDIRECTORY
    86.     AppData = CSIDL_APPDATA
    87.     PrintHood = CSIDL_PRINTHOOD
    88.     Local_AppData = CSIDL_LOCAL_APPDATA
    89.     AltStartup = CSIDL_ALTSTARTUP
    90.     Common_AltStartup = CSIDL_COMMON_ALTSTARTUP
    91.     '
    92.     Common_Favorites = CSIDL_COMMON_FAVORITES
    93.     Internet_Cache = CSIDL_INTERNET_CACHE
    94.     Cookies = CSIDL_COOKIES
    95.     History = CSIDL_HISTORY
    96.     Common_ApPData = CSIDL_COMMON_APPDATA
    97.     Windows = CSIDL_WINDOWS
    98.     System = CSIDL_SYSTEM
    99.     Program_Files = CSIDL_PROGRAM_FILES
    100.     MyPictures = CSIDL_MYPICTURES
    101.     Profile = CSIDL_PROFILE
    102.     Program_Files_Common = CSIDL_PROGRAM_FILES_COMMON
    103.     Common_Program_Files = CSIDL_PROGRAM_FILES_COMMON
    104.     Common_Templates = CSIDL_COMMON_TEMPLATES
    105.     Common_Documents = CSIDL_COMMON_DOCUMENTS
    106.     Common_AdminTools = CSIDL_COMMON_ADMINTOOLS
    107.     AdminTools = CSIDL_ADMINTOOLS
    108.     Connections = CSIDL_CONNECTIONS
    109.     Common_Music = CSIDL_COMMON_MUSIC
    110.     Common_Pictures = CSIDL_COMMON_PICTURES
    111.     Common_Video = CSIDL_COMMON_VIDEO
    112.     Resources = CSIDL_RESOURCES
    113.     Resources_Localized = CSIDL_RESOURCES_LOCALIZED
    114.     Common_OEM_Links = CSIDL_COMMON_OEM_LINKS
    115.     CDBurn_Area = CSIDL_CDBURN_AREA
    116.     ComputersNearMe = CSIDL_COMPUTERSNEARME
    117.     '
    118. End Enum
    119. '
    120. Private Type SHITEMID
    121.     cb As Long
    122.     abID As Byte
    123. End Type
    124. '
    125. Private Type ITEMIDLIST
    126.     mkid As SHITEMID
    127. End Type
    128.  
    129. Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
    130. Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
    131. '
    132.  
    133. Public Function GetSpecialfolder(CSIDL As Long) As String
    134.     '
    135.     Dim r As Long
    136.     Dim IDL As ITEMIDLIST
    137.     Dim strPath As String
    138.     '
    139.     Const NOERROR = 0
    140.     'Const MAX_LENGTH = 260
    141.     '
    142.     r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
    143.     If r = NOERROR Then
    144.         strPath = Space$(512)
    145.         r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal strPath)
    146.         GetSpecialfolder = Left$(strPath, InStr(strPath, Chr$(0)) - 1)
    147.     End If
    148.     '
    149. End Function

    Usage example:

    vb Code:
    1. Dim DPath As String
    2. DPath = GetSpecialfolder(SpecialFolders.Local_AppData)
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: VB Program on a non-English speaking computer

    There is no CSIDL constant for the Public folder. Relying on environment variables is also subject to localization but worse yet they're easily spoofed or otherwise set to arbitrary values.

    You need to call SHGetKnownFolderPath() to obtain this path.

    Note that this is like many other new special folder paths (and API calls) that were introduced in the modern (post-XP) era.

    You can find the constants required (which are GUIDs) at KNOWNFOLDERID or in your Windows SDK include file KnownFolders.h starting with version 6.0 of the SDK.
    Attached Files Attached Files

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