Attribute VB_Name = "modSharedFunctions"
Option Explicit

' Shared Constants
Public Const cFormatOneDec = "#,###,##0.0"
Public Const cFormatNoDec = "#,###,##0"

Public Function InLayoutMode(pMxDoc As IMxDocument) As Boolean
    InLayoutMode = IsArcMapButtonChecked("{6570248A-A258-11D1-8740-0000F8751720}", pMxDoc)
End Function

Public Function IsArcMapButtonChecked(sKey As String, pMxDoc As IMxDocument) As Boolean
    Dim pUID As New UID
    Dim pDocument As IDocument
    Dim pCommandBars As ICommandBars
    Dim pCommandItem As ICommandItem
    Dim pCommand As ICommand
    ' Init
    On Error GoTo ErrorHandler
    IsArcMapButtonChecked = False
    ' Invoke the ArcMap button
    pUID = sKey
    Set pDocument = pMxDoc
    Set pCommandBars = pDocument.CommandBars
    Set pCommandItem = pCommandBars.Find(pUID, True, False)
    Set pCommand = pCommandItem
    If pCommand.Checked Then
        IsArcMapButtonChecked = True
    End If
ErrorHandler:
End Function

Public Function Read_File(sFilename As String) As Collection
    Dim pFileSysObj As New FileSystemObject
    Dim pFile As File
    Dim pTextStream As TextStream
    Dim sLine As String
    Dim sDir As String
    Dim bTryAgain As Boolean
    
    ' Open the file as a text stream
    sDir = pFileSysObj.GetAbsolutePathName(sFilename)
    On Error GoTo eh
    Set pFile = pFileSysObj.GetFile(sFilename)
    On Error GoTo 0
    Set Read_File = New Collection
    Set pTextStream = pFile.OpenAsTextStream(ForReading)
    ' Loop through getting all lines
    Do While (pTextStream.AtEndOfStream <> True)
        sLine = pTextStream.ReadLine
        Read_File.Add sLine
    Loop
    pTextStream.Close
    
    Exit Function
eh:
    If Not bTryAgain Then
        bTryAgain = True
        sFilename = sDir
        Resume
    End If
    MsgBox "Error: Could not locate the " & sDir & " file." & vbCrLf _
        & "Unable to add text descriptions." & vbCrLf & vbCrLf & _
        "Error Message : " & Err.Description, vbInformation, "Read INI File"
    Set Read_File = Nothing
End Function

