home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD1277212172000.psc / IniRead.bas < prev    next >
Encoding:
BASIC Source File  |  2000-12-09  |  9.9 KB  |  194 lines

  1. Attribute VB_Name = "IniRead"
  2. 'Variables stored in *.ini-file: Note that (only) FTPHostname is NOT optional!
  3. Public str_language As String   '[UserPrefs]:language=(optional)default "english" - can be set to anything specified in "lang.ini"
  4. Public str_Caption(5) As String 'THIS IS THE STRING-ARRAY HOLDING THE "TRANSLATIONS"
  5. Public str_Close As String      '[UserPrefs]:ExitClose=(optional)comma separated list of programs to close before shutdown
  6. Public AutoDown As Boolean      '[UserPrefs]:AutoShutdown=(optional)0 or not present=leave computer on; >0=shutdown computer on exit
  7. Public bol_UseNL As Boolean     '[UserPrefs]:Netlaunch=(optional)0 or not present=use build-in dial up (not recommended); >0=use Netlaunch
  8. Public NLpath As String         '[UserPrefs]:Netlaunch=(optional)path to NetLaunch-folder; if not present, Program MUST be located in NetLaunch-folder!
  9. Public strRes As String         '[UserPrefs]:ScreenRes=(optional)screen resolution used for connection;"800,600" (no quotes, default) works best with Desktop On Call
  10.                                             'read Help-file for more info about possible screen resolutions
  11. Public Server As String         '[UserPrefs]:Server=(optional)path to an application to be launched after connect
  12. Public str_port As String       '[UserPrefs]:LocalPort=(optional) port the server listens to; default=80
  13. Public bol_Optimize As Boolean  '[UserPrefs]:Optimize=(optional)0 or not present=don┤t optimize for slow connections; >0=turn wallpaper & font smoothing off
  14.  
  15. Public ISPname As String        '[Connection]:ISP=(optional)name of ISP to be used for connection; if not present, the system default one will be used
  16. Public FTPHostname As String    '[Connection]:FTPHostname=name of the ftp-host to connect to. Leading "ftp://" will be ignored.
  17. Public FTPUsername As String    '[Connection]:FTPUsername=(optional)username to logon with. If omitted, will be "anonymous" (for public ftp-account)
  18. Public FTPPassword As String    '[Connection]:FTPPassword=(optional)password to logon with. If omitted, will be "someone@home.com" (public ftps require "e-mail" adress for anonymous users).
  19. Public FTPTimeout As String     '[Connection]:FTPTimeout=(optional)max. time to connect to server; default 1min
  20. Public RemoteFile As String     '[Connection]:RemoteFile=(optional)file to create on the host. If omitted, will be "index.htm" (overwriting existing ones!!!).
  21. Public Filename As String       '??
  22. Public MaxRetries As Integer    '[Connection]:MaxRetries=(optional)number of retries to connect to host. If omitted, default is 20.
  23.  
  24. Public Interval As Integer      '[Timer]:Interval=(optional)timer interval in ms. The more, the less accurate. Default is 300ms.
  25. Public Timer(2) As String       '[Timer]:Timer1=(optional)countdown before dial-up. Format "h:m:s". Default 0:0:5 (5s).
  26.                                 '[Timer]:Timer2=(optional)countdown before shutdown. Default 0:5:0 (5min), meaning you have 5 minutes to logon to your computer.
  27.                                 '[Timer]:Timer3=(optional)"stay-alive-timer". Default 0:10:0 (10min), makes shure you┤re still connected by popping the prg up.
  28. 'Variables used internally for timing and program state
  29. Public Times(2, 2) As Integer   'Timer array, also tells you what the prg does at the moment.
  30. Public TimerState As Byte       'range 0,1,2. Selects timer from timer-array: Times(TimerState,Timer)
  31. Public ConnectRetries As Integer 'number of connection-attempts already done by the program.
  32.  
  33. Public BPP, OldBPP As Integer   'screen color depth
  34. Public ScrWidth, ScrHeight, OldWidth, OldHeight As Single 'screen resolution
  35. Public i, j As Integer             '"j" will only be used in "Parse_Times()"
  36. Dim str_Inifile As String       'to enable reading from lang.ini as well
  37.  
  38. Public Sub Get_ini_Values()
  39. '[UserPrefs]
  40. str_language = Read_ini("Iconnect.ini", "UserPrefs", "language")
  41. If str_language = "" Then
  42.     str_language = "english"
  43. End If
  44.  
  45. For i = 0 To 5
  46.     str_Caption(i) = Read_ini("language.ini", str_language, CStr(i))
  47. Next i
  48.  
  49. str_Close = Read_ini("Iconnect.ini", "UserPrefs", "ExitClose")
  50.  
  51. If Val(Read_ini("Iconnect.ini", "UserPrefs", "AutoShutdown")) > 0 Then
  52.     AutoDown = True
  53. Else
  54.     AutoDown = False
  55. End If
  56.  
  57. If Val(Read_ini("Iconnect.ini", "UserPrefs", "UseNetLaunch")) > 0 Then
  58.     bol_UseNL = True
  59.     If Read_ini("Iconnect.ini", "UserPrefs", "Netlaunch") <> "" Then
  60.         NLpath = Read_ini("Iconnect.ini", "UserPrefs", "Netlaunch")
  61.         If Right(NLpath, 1) = "\" Then
  62.             NLpath = NLpath & "launch.exe"
  63.         Else
  64.             NLpath = NLpath & "\launch.exe"
  65.         End If
  66.     Else
  67.     NLpath = App.Path & "\launch.exe"
  68.     End If
  69. Else
  70.     bol_UseNL = False
  71. End If
  72.  
  73. strRes = Read_ini("Iconnect.ini", "UserPrefs", "ScreenRes")
  74. If strRes <> "" Then
  75.     Call Parse_strRes
  76. Else
  77.     ScrWidth = OldWidth
  78.     ScrHeight = OldHeight
  79.     BPP = OldBPP
  80. End If
  81.  
  82. Server = Read_ini("Iconnect.ini", "UserPrefs", "Server")
  83.  
  84. str_port = Read_ini("Iconnect.ini", "UserPrefs", "LocalPort")
  85. If Val(str_port) = 0 Then
  86.     str_port = ""
  87. End If
  88.  
  89. If Val(Read_ini("Iconnect.ini", "UserPrefs", "Optimize")) > 0 Then
  90.     bol_Optimize = True
  91. Else
  92.     bol_Optimize = False
  93. End If
  94.  
  95.  
  96. '[Connection]
  97. ISPname = Read_ini("Iconnect.ini", "Connection", "ISP")
  98. FTPHostname = Read_ini("Iconnect.ini", "Connection", "FTPHostname")
  99. If Left$(FTPHostname, 6) = "ftp://" Then
  100.     FTPHostname = Mid$(FTPHostname, 6)
  101. End If
  102. FTPUsername = Read_ini("Iconnect.ini", "Connection", "FTPUsername")
  103. If FTPUsername = "" Then
  104.     FTPUsername = "anonymous"
  105. End If
  106. FTPPassword = Read_ini("Iconnect.ini", "Connection", "FTPPassword")
  107. If FTPPassword = "" Then
  108.     FTPPassword = "someone@home.com"
  109. End If
  110. FTPTimeout = Read_ini("Iconnect.ini", "Connection", "FTPTimeout")
  111. If FTPTimeout = "" Then
  112.     FTPTimeout = "00:01:00"
  113. End If
  114. RemoteFile = Read_ini("Iconnect.ini", "Connection", "RemoteFile")
  115. If RemoteFile = "" Then
  116.     RemoteFile = "index.htm"
  117. End If
  118. MaxRetries = CInt(Val(Read_ini("Iconnect.ini", "Connection", "MaxRetries")))
  119. If MaxRetries = 0 Then
  120.     MaxRetries = 20
  121. End If
  122.  
  123. '[Timer]
  124. If CInt(Val(Read_ini("Iconnect.ini", "Timer", "Interval"))) = 0 Then
  125.     Interval = 300  'frequency of timer-events in ms: the more, the more accurate the timing gets
  126.     j = Write_ini("Timer", "Interval", "300")
  127. Else
  128.     Interval = CInt(Val(Read_ini("Iconnect.ini", "Timer", "Interval")))
  129. End If
  130. If Read_ini("Iconnect.ini", "Timer", "Timer1") <> "" Then
  131.     Timer(0) = Read_ini("Iconnect.ini", "Timer", "Timer1")
  132. Else
  133.     Timer(0) = "0:0:5"
  134.     j = Write_ini("Timer", "Timer1", "0:0:5")
  135. End If
  136. If Read_ini("Iconnect.ini", "Timer", "Timer2") <> "" Then
  137.     Timer(1) = Read_ini("Iconnect.ini", "Timer", "Timer2")
  138. Else
  139.     Timer(1) = "0:5:0"
  140.     j = Write_ini("Timer", "Timer2", "0:5:0")
  141. End If
  142. If Read_ini("Iconnect.ini", "Timer", "Timer3") <> "" Then
  143.     Timer(2) = Read_ini("Iconnect.ini", "Timer", "Timer3")
  144. Else
  145.     Timer(2) = "0:10:0"
  146.     j = Write_ini("Timer", "Timer3", "0:10:0")
  147. End If
  148. Call Parse_Times
  149. End Sub
  150. Function Read_ini(Filename, Section, KeyName As String) As String
  151.     Dim sRet As String
  152.     sRet = String(255, Chr(0))
  153.     Read_ini = Left(sRet, GetPrivateProfileString(Section, ByVal KeyName, "", sRet, Len(sRet), App.Path & "\" & Filename))
  154. End Function
  155. Function Write_ini(Section As String, KeyName As String, NewString As String) As Integer
  156.     Dim r
  157.     r = WritePrivateProfileString(Section, KeyName, NewString, App.Path & "\eyecon.ini")
  158. End Function
  159. Private Sub Parse_strRes()))))))))))ring(Sec, "UserPrefs", ileStriiiiin
  160. PrivleString(Sect eProf(Secbnd Su"0pm'Ltpsnctioecti"si1aarct.ini", "Connp,ud IChr(0))
  161.     Read_ini = Lee = "index.htm"
  162. EndEndEpng(S'ini(Sectiaarct.inipoind As))))))
  163. PrivleString(Se6ering) As String
  164.    )))))))))))ring(Sec, "Usetiaarct.inipoind -8StrivleStrinOOOOOOOOOOOOOOOOOO"" T)f2ecti"sipOOOOOOMid$(FTPoind As))))))
  165. Privlmti"st "TPBqes(2 leStMIRe6erinni", "Connection", "ISP")
  166. FTPHostna t.ininection]
  167. ISPn= Mich")) > O""eri1) 
  168. FTPHo e ""erirof(ST)f2tc        PBqes(2 leTGtildct Parse_TbOOOO"lPi"l)
  169.     Read_i "FTPHostname")
  170. It Parse_TbHr-(vHostna t., Ap
  171.  
  172. '[Ti u Par"sa" fh(0pe1a>asse_TbOOOO"lPrn(2 leTGr3"ProfrivleStringyl "Iconnect.ini", TbOO,stqes(2 le 0  te:tl"lPipd+_TbHr-eyName, "", sR Gr3wf 1e -"= Mich0:>tss0 : -"= Mich0:>")
  173. l    FTPUsername =,
  174. Functi  'Timer array, aleStrt>c))))))))ring(Sec, "UsetiaajICall String) As S1e -"= Mich0:Cctidex.htm"
  175. EN>c))))))))1", "0:0:5Plg8tss0 : -"= Mich0:Val(str-"= Mich0:m'Ltpsnctioecr ir gs0 : -"=dHpf2tc se
  176. t+_TbHr-eyName,:"rtssnctioecPpeaN 08tiaajICagtring) As S1e -"= Mich0:Cctidex.htm"
  177. EN>c))a p8tilh0:Val(  FTPtioebtich0SEtch0:s(tdCctidex.htm" FTPtioebtich: -,sb16'[Tg gs0 : ring) As S1ehe timing gets
  178.     j = Write_inijICagtring) Asnd Funcse"meptervRead_ini("Iconnead_ini("Iconne,CString(Se6erinijIC
  179. tsetyeje, "", sReionnead_ini("Iconnei("
  180.  u=RemoteIsou1imer arraye S1ehe timing ng) Asnd FunReating(Se6eTPHostname")e tiFile = "" Then
  181.  eeut3stn1snd FunReaydptdCcfm)r(aemICagtrinParspptdCcfm)r(aemIA)i If
  182. Call :Val(  FTPtioebticDbtdCct8ind AsdptdCcfm)r(0, aleStrnd AsnReating(1  FTPtioebe6e "\" Then
  183.   FTPtb "" Thente_ini("Tisytname")e tigmur Then
  184.  eeut3si1) 
  185. FTPHo e ""erirof(ST)f2tc        PpauTbHr- 1:iionTisyini("IPmer hente_ini("Tisytname")e tigmur Thenisyteeo  FTPtb "" Theiionla, sR(ST)f2mgg(Se6eTPHafm"
  186. EN>c)0mrtervReRlConnecthenisyteeo  FTPtbReah  FTPtbReah  FTPtbReah  FTPtbReah  FTPtbRpHafm If
  187. Call :Val(  FTPt g(Se6ifrt = ""
  188. End If
  189.  
  190. If Val(Read_ini("IANa0
  191. If ValFTP0 VahPtbRe6ncti  'Tth, Olut.inipoind -8 P"isyteeo  FTPtb "" Theiionla, sR(ST)f2mgg(Se6eTPeeemICagtrinPaftenteso" Theiionla, sR(Sattgmggk cf
  192. If Vao" TheiionlConnecthenisyteeouebtiiiiiiiiiiiiiirl jh, Olut.inpjoind -8 P"1dCcfm)r(ae4a'h, Olufles P"1d" ThionlConnecthefteiiirl jhttiiiiiPme0 :lf
  193. If Vao" Ths0 f Mef8 P"isyteeo -t"isyrhgo,ou0yName, njoinde4a,inpao" tTPtbRIf VsP0 Vsnd Funcse"mepgo,o ,u0yName,L"" Tdoe6nctishof(ST" Th,u0ye0 Pnd Asf"(enjoujoinsnatmur Then
  194.  eeut3si" cthefte