******* GETINIFILE **********
//RETURNS: String which includes current path and filename of plus.ini
Function GetINIFile

   fINI = _app.inifile
   if FILE(fINI)
      return fINI
   else
      MsgBox("Cannot find INI file. Will not be able to populate the list of ADO Connections","Alert")
      return false
   endif

return


******* GETLISTOFCONNECTIONS ********
// RETURNS: false -- if no connections found or details are missing 
//				Two Dimentional Array -- if list of ADO datbases are found 
//											 -- col1 - ADO database name								
//											 -- col2 - File Name (if using .udl file - or Connection string)
//				null - if for some reason the end of the function is reached without returning anything
//
//PARAMETERS: take one parameter with the path and filename of the plus.ini file.
//				  HOwever, if this parameter is not passed it will find the current user's ini file anyway.

Function GetListOfConnections(fINI)

if type("fINI") <> "C" 
   fINI = _app.iniFile
endif
 
   fINIfile = new file()
   fINIfile.open(fINI,"R")
   do 
      cLine = fINIfile.gets()
      if trim(cLine) == "[Connections]"
         lFoundConnections = true
      else
         lFoundConnections = false
      endif
   until lFoundConnections or fINIfile.eof()

   if NOT lFoundConnections
      MsgBox("No ADOConnections were found in this file","Alert")
      return false
   else

      aConnections = new Array(1,2)
      n = 0
      //gET LIST OF CONNECTIONS
      do 
         nConnection = LEFT(cLine,AT("=",cLine)-1) //get number of connections in the list - will end up with the last number before the list of details for each ADOConnection
         cLine =fINIfile.gets()
         //get list of connections
         if LEFT(cLine,1) <> "["
            n++
            aConnections[n,1] = trim(RIGHT(cLine,LEN(cLine)-(AT("=",cLine))))
            aConnections.grow(1)
         endif
      until LEFT(cLine,1) == "[" OR fINIfile.eof()
      aConnections.resize(n,2)

      //TEST
//      for x = 1 to aConnections.size/2
//         ?"aConnections["+x+",1] = "+ aConnections[x,1]
//      endfor

      if fINIfile.eof()
         MsgBox("Missing ADOConnection details","Alert")
         return false
      else
         //GET CONNECTION DETAILS
         for x = 1 to n
            cLine = fINIfile.gets()
            if LEFT(cLine,1) <> "["
               //Get Connection string
               cConnectionString = ""
               do while NOT (LEFT(cLine,1) == "[") AND NOT fINIfile.eof() //until next ADO Database is found or file is at the end
                  cConnectionString += cLine+";"
                  cLine = fINIfile.gets()
               enddo  
               cConnectionString = LEFT(cConnectionString,RAT(";",cConnectionString)-1) //Take out last semi-colon
//               ?x+" connection string = '"+cConnectionString+"'"
               aConnections[x,2] = cConnectionString
            endif
         endfor  // iterate through 
      endif         

      return aConnections      

   endif
   
return null
