Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1629 lines
50 KiB

  1. '//+----------------------------------------------------------------------------
  2. '//
  3. '// File: global.bas
  4. '//
  5. '// Module: pbadmin.exe
  6. '//
  7. '// Synopsis: The implementation of functions global to PBA.
  8. '//
  9. '// Copyright (c) 1997-1999 Microsoft Corporation
  10. '//
  11. '// Author: quintinb Created Header 09/02/99
  12. '//
  13. '//+----------------------------------------------------------------------------
  14. Attribute VB_Name = "global"
  15. Option Explicit
  16. 'Declare configuration global variables
  17. Public PBFileName As String
  18. Public RegionFilename As String
  19. Public signature As String
  20. Public PartialCab As String
  21. Public FullCab As String
  22. Public DBName As String
  23. Public locPath As Variant 'define the app path.
  24. Public updateFound As Integer
  25. Public gStatusText(0 To 1) As String
  26. Public gRegionText(-1 To 0) As String
  27. Public gCommandStatus As Integer
  28. Public gBuildDir
  29. Public gCLError As Boolean
  30. Public HTMLHelpFile As String
  31. ' Registry and resource values
  32. Global gsRegAppTitle As String
  33. 'region edit list
  34. Type EditLists
  35. Action() As String
  36. Region() As String
  37. OldRegion() As String
  38. ID() As Integer
  39. Count As Integer
  40. End Type
  41. Public Type tmpFont
  42. Name As String
  43. Size As Integer
  44. Charset As Integer
  45. End Type
  46. Public gfnt As tmpFont
  47. 'Declare the global constants for flag calculations
  48. Global Const Global_Or = 2
  49. Global Const Global_And = &HFFFF
  50. Public result As Long
  51. Public service As Integer
  52. 'Set the check point for the insert operation
  53. Public code As Integer
  54. Public Type bitValues
  55. desc(1) As String
  56. End Type
  57. Public gQuote As String
  58. 'Declare the database and dynasets for the tables
  59. Public gsCurrentPB As String
  60. Public gsCurrentPBPath As String
  61. Public MyWorkspace As Workspace
  62. Public gsyspb As Database
  63. Public Gsyspbpost As Database
  64. Public GsysRgn As Recordset
  65. Public GsysCty As Recordset
  66. Public GsysDial As Recordset
  67. Public GsysVer As Recordset
  68. Public GsysDelta As Recordset
  69. 'Declare the recordset for accessing information
  70. Public GsysNRgn As Recordset
  71. Public GsysNCty As Recordset
  72. Public GsysNDial As Recordset
  73. Public GsysNVer As Recordset
  74. Public GsysNDelta As Recordset
  75. Public temp As Recordset
  76. 'Declare recordset to directly hand DAO RS to data control
  77. Public rsDataDelta As Recordset
  78. Public dbDataDelta As Database
  79. 'registry
  80. Global Const HKEY_LOCAL_MACHINE = &H80000002
  81. Global Const KEY_ALL_ACCESS = &H3F
  82. Global Const ERROR_NONE = 0
  83. Public Const REG_SZ = 1
  84. Public Const REG_DWORD = 4
  85. Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.
  86. Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
  87. Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  88. Declare Function RegQueryValueExString Lib "advapi32.dll" Alias _
  89. "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
  90. String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
  91. As String, lpcbData As Long) As Long
  92. Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias _
  93. "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
  94. String, ByVal lpReserved As Long, lpType As Long, lpData As _
  95. Long, lpcbData As Long) As Long
  96. Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias _
  97. "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
  98. String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
  99. As Long, lpcbData As Long) As Long
  100. 'Public gsDAOPath As String
  101. 'Declare Function DllRegisterServer Lib "gsDAOPath" () As Long
  102. Declare Function OSWritePrivateProfileString% Lib "kernel32" _
  103. Alias "WritePrivateProfileStringA" _
  104. (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal FileName$)
  105. Declare Function OSWritePrivateProfileSection% Lib "kernel32" _
  106. Alias "WritePrivateProfileSectionA" _
  107. (ByVal AppName$, ByVal KeyName$, ByVal FileName$)
  108. 'Declare Function OSGetPrivateProfileString% Lib "kernel32" _
  109. ' Alias "GetPrivateProfileStringA" _
  110. ' (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal ReturnString$, ByVal NumBytes As Integer, ByVal FileName$)
  111. Declare Function OSWinHelp% Lib "user32" Alias "WinHelpA" (ByVal hWnd&, ByVal HelpFile$, ByVal wCommand%, dwData As Any) 'helpfile API
  112. 'Declare Function WinHelp Lib "user32" Alias "WinHelpA" (ByVal hwnd As Long, ByVal HelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long 'helpfile API
  113. Declare Function HtmlHelp Lib "hhwrap.dll" Alias "CallHtmlHelp" (ByVal hWnd As Long, ByVal HelpFile As String, ByVal wCommand As Long, ByVal dwData As Any) As Long
  114. 'Declare Function HtmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" (ByVal hWnd As Long, ByVal HelpFile As String, ByVal wCommand As Long, dwData As Any) As Long
  115. Public Const HELP_CONTEXT = &H1
  116. Public Const HELP_INDEX = &H3
  117. Public Const HH_DISPLAY_TOPIC = &H0
  118. Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
  119. Declare Function GetUserDefaultLCID& Lib "kernel32" ()
  120. Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, _
  121. lpReOpenBuff As OFSTRUCT, _
  122. ByVal wStyle As Long) As Long
  123. Public Const OFS_MAXPATHNAME = 128
  124. Public Const OF_EXIST = &H4000
  125. Declare Function apiGetWindowsDirectory& Lib "kernel32" Alias _
  126. "GetWindowsDirectoryA" (ByVal lpbuffer As String, ByVal _
  127. nSize As Long)
  128. Type OFSTRUCT
  129. cBytes As Byte
  130. fFixedDisk As Byte
  131. nErrCode As Integer
  132. Reserved1 As Integer
  133. Reserved2 As Integer
  134. szPathName(OFS_MAXPATHNAME) As Byte
  135. End Type
  136. Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
  137. Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long
  138. Public Const RESOURCETYPE_DISK = &H1
  139. Type NETRESOURCE
  140. dwScope As Long
  141. dwType As Long
  142. dwDisplayType As Long
  143. dwUsage As Long
  144. lpLocalName As String
  145. lpRemoteName As String
  146. lpComment As String
  147. lpProvider As String
  148. End Type
  149. Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias _
  150. "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, _
  151. lpSectorsPerCluster As Long, lpBytesPerSector As Long, _
  152. lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) _
  153. As Long
  154. Public Const VER_PLATFORM_WIN32s = 0
  155. Public Const VER_PLATFORM_WIN32_WINDOWS = 1
  156. Public Const VER_PLATFORM_WIN32_NT = 2
  157. Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
  158. Type OSVERSIONINFO
  159. dwOSVersionInfoSize As Long
  160. dwMajorVersion As Long
  161. dwMinorVersion As Long
  162. dwBuildNumber As Long
  163. dwPlatformId As Long
  164. szCSDVersion As String * 128 ' Maintenance string for PSS usage
  165. End Type
  166. Public Sub GetFont(fnt As tmpFont)
  167. Const DEFAULT_CHARSET = 1
  168. Const SYMBOL_CHARSET = 2
  169. Const SHIFTJIS_CHARSET = 128
  170. Const HANGEUL_CHARSET = 129
  171. Const CHINESEBIG5_CHARSET = 136
  172. Const CHINESESIMPLIFIED_CHARSET = 134
  173. Dim MyLCID As Integer
  174. MyLCID = GetUserDefaultLCID()
  175. Select Case MyLCID
  176. Case &H404 ' Traditional Chinese
  177. fnt.Charset = CHINESEBIG5_CHARSET
  178. fnt.Name = ChrW(&H65B0) + ChrW(&H7D30) + ChrW(&H660E) _
  179. + ChrW(&H9AD4) 'New Ming-Li
  180. fnt.Size = 9
  181. Case &H411 ' Japan
  182. fnt.Charset = SHIFTJIS_CHARSET
  183. fnt.Name = ChrW(&HFF2D) + ChrW(&HFF33) + ChrW(&H20) + ChrW(&HFF30) + _
  184. ChrW(&H30B4) + ChrW(&H30B7) + ChrW(&H30C3) + ChrW(&H30AF)
  185. fnt.Size = 9
  186. Case &H412 'Korea UserLCID
  187. fnt.Charset = HANGEUL_CHARSET
  188. fnt.Name = ChrW(&HAD74) + ChrW(&HB9BC) 'Korea FontName
  189. fnt.Size = 9 'Korea FontSize
  190. Case &H804 ' Simplified Chinese
  191. fnt.Charset = CHINESESIMPLIFIED_CHARSET
  192. fnt.Name = ChrW(&H5B8B) + ChrW(&H4F53)
  193. fnt.Size = 9
  194. Case Else ' The other countries
  195. fnt.Charset = DEFAULT_CHARSET
  196. fnt.Name = "MS Sans Serif"
  197. fnt.Size = 8
  198. End Select
  199. End Sub
  200. Function DeletePOP(ByRef ID As Long, ByRef dbPB As Database) As Integer
  201. Dim strSQL As String
  202. Dim deltnum As Integer, i As Integer
  203. Dim deltasql As String
  204. Dim deletecheck As Recordset
  205. Set GsysDial = dbPB.OpenRecordset("select * from Dialupport where accessnumberId = " & CStr(ID), dbOpenSnapshot)
  206. If GsysDial.EOF And GsysDial.BOF Then
  207. DeletePOP = ID
  208. Exit Function
  209. End If
  210. strSQL = "DELETE FROM DialUpPort WHERE AccessNumberID = " & ID
  211. dbPB.Execute strSQL
  212. Set GsysDelta = dbPB.OpenRecordset("Select * from Delta order by DeltaNum", dbOpenDynaset)
  213. If GsysDelta.RecordCount = 0 Then
  214. deltnum = 1
  215. Else
  216. GsysDelta.MoveLast
  217. deltnum = GsysDelta!deltanum
  218. If deltnum > 6 Then
  219. deltnum = deltnum - 1
  220. End If
  221. End If
  222. For i = 1 To deltnum
  223. deltasql = "Select * from delta where DeltaNum = " & i% & _
  224. " AND AccessNumberId = '" & ID & "' " & _
  225. " order by DeltaNum"
  226. Set GsysDelta = dbPB.OpenRecordset(deltasql, dbOpenDynaset)
  227. If Not (GsysDelta.BOF And GsysDelta.EOF) Then
  228. GsysDelta.Edit
  229. Else
  230. GsysDelta.AddNew
  231. GsysDelta!deltanum = i%
  232. GsysDelta!AccessNumberId = ID
  233. End If
  234. GsysDelta!CountryNumber = 0
  235. GsysDelta!AreaCode = 0
  236. GsysDelta!AccessNumber = 0
  237. GsysDelta!MinimumSpeed = 0
  238. GsysDelta!MaximumSpeed = 0
  239. GsysDelta!RegionID = 0
  240. GsysDelta!CityName = "0"
  241. GsysDelta!ScriptId = "0"
  242. GsysDelta!Flags = 0
  243. GsysDelta.Update
  244. Next i%
  245. Set deletecheck = dbPB.OpenRecordset("DialUpPort", dbOpenSnapshot)
  246. If deletecheck.RecordCount = 0 Then
  247. dbPB.Execute "DELETE from PhoneBookVersions"
  248. dbPB.Execute "DELETE from delta"
  249. End If
  250. LogPOPDelete GsysDial
  251. On Error GoTo 0
  252. Exit Function
  253. DeleteErr:
  254. DeletePOP = ID
  255. Exit Function
  256. End Function
  257. Function FilterPBKey(KeyAscii As Integer, objTextBox As TextBox) As Integer
  258. Select Case KeyAscii
  259. ' space32 "34 %37 '39 *42 /47 :58 <60 =61 >62 ?63 \92 |124 !33 ,44 ;59 .46 &38 {123 }125 [91 ]93
  260. Case 32, 34, 37, 39, 42, 47, 58, 60, 61, 62, 63, 92, 124, 33, 44, 59, 46, 38, 123, 125, 91, 93
  261. KeyAscii = 0
  262. Beep
  263. End Select
  264. If KeyAscii <> 8 Then
  265. Dim TextLeng As Integer ' Current text length
  266. Dim SelLeng As Integer ' Current selected text length
  267. Dim KeyLeng As Integer ' inputted character length ANSI -> 2
  268. ' DBCS -> 4
  269. TextLeng = LenB(StrConv(objTextBox.Text, vbFromUnicode))
  270. SelLeng = LenB(StrConv(objTextBox.SelText, vbFromUnicode))
  271. KeyLeng = Len(Hex(KeyAscii)) / 2
  272. If (TextLeng - SelLeng + KeyLeng) > 8 Then
  273. KeyAscii = 0
  274. Beep
  275. End If
  276. End If
  277. FilterPBKey = KeyAscii
  278. End Function
  279. Function FilterNumberKey(KeyAscii As Integer) As Integer
  280. ' numbers and backspace
  281. If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
  282. KeyAscii = 0
  283. Beep
  284. End If
  285. FilterNumberKey = KeyAscii
  286. End Function
  287. Function GetDeltaCount(ByVal version As Integer) As Integer
  288. If version > 5 Then
  289. GetDeltaCount = 5
  290. Else
  291. GetDeltaCount = version - 1
  292. End If
  293. End Function
  294. Function GetPBVersion(ByRef dbPB As Database) As Integer
  295. Dim rsVer As Recordset
  296. ' open db
  297. Set rsVer = dbPB.OpenRecordset("SELECT max(Version) as MaxVer FROM PhoneBookVersions")
  298. If IsNull(rsVer!MaxVer) Then
  299. GetPBVersion = 1
  300. Else
  301. GetPBVersion = rsVer!MaxVer
  302. End If
  303. rsVer.Close
  304. End Function
  305. Function GetSQLDeltaInsert(ByRef Record As Variant, ByVal deltanum As Integer) As String
  306. Dim strSQL As String
  307. Dim intX As Integer
  308. On Error GoTo SQLInsertErr
  309. strSQL = "INSERT into Delta " & _
  310. " (DeltaNum, AccessNumberID, CountryNumber,RegionID,CityName,AreaCode, " & _
  311. " AccessNumber, MinimumSpeed, MaximumSpeed, FlipFactor, Flags, ScriptID)" & _
  312. " VALUES (" & deltanum & ","
  313. For intX = 0 To 10
  314. Select Case intX
  315. Case 1, 2, 6 To 9
  316. strSQL = strSQL & Record(intX) & ","
  317. Case 10
  318. strSQL = strSQL & Chr(34) & Record(intX) & Chr(34) & ")"
  319. Case Else
  320. strSQL = strSQL & Chr(34) & Record(intX) & Chr(34) & ","
  321. End Select
  322. Next
  323. GetSQLDeltaInsert = strSQL
  324. On Error GoTo 0
  325. Exit Function
  326. SQLInsertErr:
  327. Exit Function
  328. End Function
  329. Function GetSQLDeltaUpdate(ByRef Record As Variant, ByVal deltanum As Integer) As String
  330. Dim strSQL As String
  331. On Error GoTo SQLUpdateErr
  332. strSQL = "UPDATE Delta SET" & _
  333. " CountryNumber=" & Record(1) & _
  334. ", RegionID=" & Record(2) & _
  335. ", CityName=" & Chr(34) & Record(3) & Chr(34) & _
  336. ", AreaCode='" & Record(4) & "'" & _
  337. ", AccessNumber='" & Record(5) & "'" & _
  338. ", MinimumSpeed=" & Record(6) & _
  339. ", MaximumSpeed=" & Record(7) & _
  340. ", FlipFactor=" & Record(8) & _
  341. ", Flags=" & Record(9) & _
  342. ", ScriptID='" & Record(10) & "'"
  343. strSQL = strSQL & " WHERE AccessNumberID='" & Record(0) & "'" & _
  344. " AND DeltaNum=" & deltanum
  345. GetSQLDeltaUpdate = strSQL
  346. On Error GoTo 0
  347. Exit Function
  348. SQLUpdateErr:
  349. GetSQLDeltaUpdate = ""
  350. Exit Function
  351. ' If cmbstatus.ItemData(cmbstatus.ListIndex) = 1 Then
  352. ' 'insert the delta table (production pop)
  353. '
  354. ' For i = 1 To deltnum
  355. ' deltasql = "Select * from delta where DeltaNum = " & i% & " order by DeltaNum"
  356. ' Set GsysDelta = GsysPb.OpenRecordset(deltasql, dbOpenDynaset)
  357. '
  358. ' addFound = 0 'initialize delta not found
  359. ' Do While GsysDelta.EOF = False
  360. ' If GsysDelta!AccessNumberId = Val(txtid.Text) Then
  361. ' addFound = 1
  362. ' Exit Do
  363. ' Else
  364. ' GsysDelta.MoveNext
  365. ' End If
  366. ' Loop
  367. '
  368. ' If addFound = 0 Then
  369. ' GsysDelta.AddNew
  370. ' GsysDelta!deltanum = i%
  371. ' GsysDelta!AccessNumberId = txtid.Text
  372. ' Else
  373. ' GsysDelta.Edit
  374. ' End If
  375. '' GsysDelta!CountryNumber = dbCmbCty.ItemData(dbCmbCty.ListIndex)
  376. ' GsysDelta!AreaCode = maskArea.Text
  377. ' GsysDelta!AccessNumber = maskAccNo.Text
  378. ' If Trim(cmbmin.Text) <> "" Or Val(cmbmin.Text) = 0 Then
  379. ' GsysDelta!MinimumSpeed = Val(cmbmin.Text)
  380. ' Else
  381. '' GsysDelta!MinimumSpeed = Null
  382. ' End If
  383. ' If Trim(cmbmax.Text) <> "" Or Val(cmbmax.Text) = 0 Then
  384. '' GsysDelta!MaximumSpeed = Val(cmbmax.Text)
  385. ' Else
  386. ' GsysDelta!MaximumSpeed = Null
  387. ' End If
  388. '' GsysDelta!regionID = cmbRegion.ItemData(cmbRegion.ListIndex)
  389. ' GsysDelta!CityName = txtcity.Text
  390. ' GsysDelta!ScriptID = txtscript.Text
  391. ' GsysDelta!FlipFactor = 0
  392. ' GsysDelta!Flags = result
  393. ' GsysDelta.Update
  394. ' Next i%
  395. ' End If
  396. End Function
  397. Function GetSQLPOPInsert(ByRef Record As Variant) As String
  398. Dim strSQL As String
  399. Dim intX As Integer
  400. Dim bAddFields As Boolean
  401. If UBound(Record) < 14 Then
  402. bAddFields = True
  403. Else
  404. bAddFields = False
  405. End If
  406. strSQL = "INSERT into DialUpPort " & _
  407. " (AccessNumberID, CountryNumber,RegionID,CityName,AreaCode, " & _
  408. " AccessNumber, MinimumSpeed, MaximumSpeed, FlipFactor, Flags, " & _
  409. " ScriptID, Status, StatusDate, ServiceType, Comments)" & _
  410. " VALUES ("
  411. For intX = 0 To 14
  412. Select Case intX
  413. Case 0 To 2, 6 To 9
  414. strSQL = strSQL & Record(intX) & ","
  415. Case 11
  416. If bAddFields Then
  417. strSQL = strSQL & "'1',"
  418. Else
  419. 'strSQL = strSQL & "'" & Record(intX) & "',"
  420. strSQL = strSQL & Chr(34) & Record(intX) & Chr(34) & ","
  421. End If
  422. Case 12
  423. strSQL = strSQL & "'" & Date & "',"
  424. Case 13
  425. strSQL = strSQL & "' ',"
  426. Case 14
  427. If bAddFields Then
  428. strSQL = strSQL & "'')"
  429. Else
  430. strSQL = strSQL & "'" & Record(12) & "')"
  431. End If
  432. Case Else
  433. strSQL = strSQL & Chr(34) & Record(intX) & Chr(34) & ","
  434. End Select
  435. Next
  436. GetSQLPOPInsert = strSQL
  437. End Function
  438. Function GetSQLPOPUpdate(ByRef Record As Variant) As String
  439. Dim strSQL As String
  440. Dim bAddFields As Boolean
  441. On Error GoTo SQLUpdateErr
  442. If UBound(Record) < 14 Then
  443. bAddFields = True
  444. Else
  445. bAddFields = False
  446. End If
  447. strSQL = "UPDATE DISTINCTROW DialUpPort SET" & _
  448. " CountryNumber=" & Record(1) & _
  449. ", RegionID=" & Record(2) & _
  450. ", CityName=" & Chr(34) & Record(3) & Chr(34) & _
  451. ", AreaCode='" & Record(4) & "'" & _
  452. ", AccessNumber='" & Record(5) & "'" & _
  453. ", MinimumSpeed=" & Record(6) & _
  454. ", MaximumSpeed=" & Record(7) & _
  455. ", FlipFactor=" & Record(8) & _
  456. ", Flags=" & Record(9) & _
  457. ", ScriptID='" & Record(10) & "'"
  458. If bAddFields Then
  459. strSQL = strSQL & _
  460. ", Status='1'" & _
  461. ", StatusDate='" & Date & " '" & _
  462. ", ServiceType=' '" & _
  463. ", Comments=''"
  464. Else
  465. strSQL = strSQL & _
  466. ", Status='" & Record(11) & "'" & _
  467. ", StatusDate='" & Date & " '" & _
  468. ", ServiceType=' '" & _
  469. ", Comments=" & Chr(34) & Record(12) & Chr(34)
  470. End If
  471. strSQL = strSQL & " WHERE AccessNumberID=" & Record(0)
  472. GetSQLPOPUpdate = strSQL
  473. On Error GoTo 0
  474. Exit Function
  475. SQLUpdateErr:
  476. GetSQLPOPUpdate = ""
  477. Exit Function
  478. End Function
  479. Function ReplaceChars(ByVal InString As String, ByVal OldChar As String, ByVal NewChar As String) As String
  480. Dim intX As Integer
  481. intX = 1
  482. Do While intX < Len(InString) And intX <> 0
  483. intX = InStr(intX, InString, OldChar)
  484. If intX < Len(InString) And intX <> 0 Then
  485. InString = Left$(InString, intX - 1) & NewChar & _
  486. Right$(InString, Len(InString) - intX)
  487. End If
  488. Loop
  489. ReplaceChars = InString
  490. End Function
  491. Function GetDriveSpace(ByVal Drive As String, ByVal Required As Double) As Double
  492. 'input: <drive path>, <required space in bytes>
  493. 'returns: <space available in bytes>, if adequate space OR
  494. ' <-2> if not adequate space OR
  495. ' <-1> if there was a problem determining space available
  496. Dim bRC As Boolean
  497. Dim intRC As Long
  498. Dim intSectors As Long
  499. Dim intBytes As Long
  500. Dim intFreeClusters As Long
  501. Dim intClusters As Long
  502. Dim strUNC As String
  503. Dim netRes As NETRESOURCE
  504. On Error GoTo GetSpaceErr
  505. Drive = Trim(Drive)
  506. If Left(Drive, 2) = "\\" Then 'unc
  507. strUNC = Right(Drive, Len(Drive) - 2)
  508. strUNC = "\\" & Left(strUNC, InStr(InStr(strUNC, "\") + 1, strUNC, "\") - 1)
  509. If ItIsNT Then ' can use GetDiskFreeSpace directly
  510. strUNC = strUNC & "\"
  511. bRC = GetDiskFreeSpace(strUNC, intSectors, intBytes, intFreeClusters, intClusters)
  512. Else
  513. netRes.dwType = RESOURCETYPE_DISK
  514. netRes.lpLocalName = "Q:"
  515. netRes.lpRemoteName = strUNC
  516. netRes.lpProvider = ""
  517. If WNetAddConnection2(netRes, vbNullString, vbNullString, 0) = 0 Then
  518. bRC = GetDiskFreeSpace(netRes.lpLocalName & "\", intSectors, intBytes, intFreeClusters, intClusters)
  519. intRC = WNetCancelConnection2(netRes.lpLocalName, 0, True)
  520. End If
  521. End If
  522. Else
  523. bRC = GetDiskFreeSpace(Left(Drive, 3), intSectors, intBytes, intFreeClusters, intClusters)
  524. End If
  525. If bRC Then
  526. GetDriveSpace = intBytes * intSectors * intFreeClusters
  527. If Required > GetDriveSpace And Not GetDriveSpace < 0 Then
  528. MsgBox LoadResString(6052) & Drive, vbExclamation
  529. GetDriveSpace = -2
  530. End If
  531. Else
  532. GetDriveSpace = -1 'problem determining drive space
  533. End If
  534. On Error GoTo 0
  535. Exit Function
  536. GetSpaceErr:
  537. GetDriveSpace = -1
  538. Exit Function
  539. End Function
  540. ' comm
  541. Function GetFileStat() As Integer
  542. ' this caused a crash!
  543. ' need something better.
  544. If CheckPath(locPath & gsCurrentPB & ".mdb") <> 0 Then
  545. 'problem
  546. GetFileStat = 1
  547. Else
  548. GetFileStat = 0
  549. End If
  550. End Function
  551. Function GetMyShortPath(ByVal LongPath As String) As String
  552. Dim strBuffer As String
  553. Dim intRC As Integer
  554. On Error GoTo PathErr
  555. strBuffer = Space(500)
  556. intRC = GetShortPathName(LongPath, strBuffer, 500)
  557. If Trim(strBuffer) <> "" Then
  558. GetMyShortPath = Left$(strBuffer, InStr(strBuffer, Chr$(0)) - 1)
  559. Else
  560. GetMyShortPath = ""
  561. End If
  562. On Error GoTo 0
  563. Exit Function
  564. PathErr:
  565. GetMyShortPath = ""
  566. Exit Function
  567. End Function
  568. Function ItIsNT() As Boolean
  569. Dim v As OSVERSIONINFO
  570. v.dwOSVersionInfoSize = Len(v)
  571. GetVersionEx v
  572. ItIsNT = False
  573. If v.dwPlatformId = VER_PLATFORM_WIN32_NT Then ItIsNT = True
  574. End Function
  575. Function LogEdit(ByVal Record As String) As Integer
  576. Dim intFile As Integer
  577. Dim strFile As String
  578. On Error GoTo LogErr
  579. intFile = FreeFile
  580. strFile = locPath & gsCurrentPB & "\" & gsCurrentPB & ".log"
  581. If CheckPath(strFile) <> 0 Then
  582. Open strFile For Output As #intFile
  583. Print #intFile, LoadResString(5236); ", "; LoadResString(5237) & _
  584. ", "; LoadResString(5238); ", "; LoadResString(5239)
  585. Close intFile
  586. End If
  587. Open strFile For Append As #intFile
  588. Print #intFile, Now & ", " & Record
  589. Close #intFile
  590. On Error GoTo 0
  591. Exit Function
  592. LogErr:
  593. Exit Function
  594. End Function
  595. Function LogError(ByVal Record As String) As Integer
  596. Dim intFile As Integer
  597. Dim strFile As String
  598. On Error GoTo LogErr
  599. intFile = FreeFile
  600. strFile = locPath & "error.log"
  601. If CheckPath(strFile) <> 0 Then
  602. Open strFile For Output As #intFile
  603. Print #intFile, LoadResString(5236); ", "; LoadResString(5237) & _
  604. ", "; LoadResString(5238); ", "; LoadResString(5239)
  605. Close intFile
  606. End If
  607. Open strFile For Append As #intFile
  608. Print #intFile, Now & ", " & Record
  609. Close #intFile
  610. On Error GoTo 0
  611. Exit Function
  612. LogErr:
  613. Exit Function
  614. End Function
  615. Function LogPOPAdd(ByRef RS As Recordset) As Integer
  616. Dim strAction As String
  617. Dim strRecord, strKey As String
  618. Dim intX As Integer
  619. strAction = LoadResString(5233)
  620. strRecord = LogPOPRecord(RS)
  621. strKey = RS!CityName
  622. LogEdit strAction & ", " & strKey & ", " & strRecord
  623. End Function
  624. Function LogPOPEdit(ByRef Key As String, ByRef RS As Recordset) As Integer
  625. Dim strAction As String
  626. Dim strRecord
  627. Dim intX As Integer
  628. strAction = LoadResString(5234)
  629. strRecord = LogPOPRecord(RS)
  630. LogEdit strAction & ", " & Key & ", " & strRecord
  631. End Function
  632. Function LogPOPDelete(ByRef RS As Recordset) As Integer
  633. Dim strAction As String
  634. Dim strRecord, strKey As String
  635. Dim intX As Integer
  636. strAction = LoadResString(5235)
  637. strRecord = LogPOPRecord(RS)
  638. strKey = RS!CityName
  639. LogEdit strAction & ", " & strKey & ", " & strRecord
  640. End Function
  641. Function LogPOPRecord(ByRef RS As Recordset) As String
  642. Dim strRecord As String
  643. Dim intX As Integer
  644. strRecord = RS(0)
  645. For intX = 1 To RS.Fields.Count - 2
  646. strRecord = strRecord & ";" & RS(intX)
  647. Next
  648. LogPOPRecord = strRecord
  649. End Function
  650. Function LogPublish(ByVal Key As String) As Integer
  651. Dim strAction As String
  652. strAction = LoadResString(6058)
  653. LogEdit strAction & ", " & Key & ", " & gsCurrentPB
  654. End Function
  655. Function LogRegionAdd(ByVal Key As String, ByVal Record As String) As Integer
  656. Dim strAction As String
  657. strAction = LoadResString(5230)
  658. LogEdit strAction & ", " & Key & ", " & Record
  659. End Function
  660. Function LogRegionEdit(ByVal Key As String, ByVal Record As String) As Integer
  661. Dim strAction As String
  662. strAction = LoadResString(5231)
  663. LogEdit strAction & ", " & Key & ", " & Record
  664. End Function
  665. Function LogRegionDelete(ByVal Key As String, ByVal Record As String) As Integer
  666. Dim strAction As String
  667. strAction = LoadResString(5232)
  668. LogEdit strAction & ", " & Key & ", " & Record
  669. End Function
  670. Function MakeFullINF(ByVal strNewPB As String) As Integer
  671. Dim strINFfile As String
  672. Dim strTemp As String
  673. If CheckPath(locPath & strNewPB) <> 0 Then
  674. MkDir locPath & strNewPB
  675. End If
  676. Exit Function
  677. ' we're not doing this anymore - no INFs
  678. strINFfile = locPath & strNewPB & "\" & strNewPB & ".inf"
  679. If CheckPath(strINFfile) <> 0 Then
  680. FileCopy locPath & "fullcab.inf", strINFfile
  681. strTemp = Chr(34) & strNewPB & Chr(34)
  682. OSWritePrivateProfileString "Strings", "ShortSvcName", strTemp, strINFfile
  683. strTemp = strNewPB & ".pbk" & Chr(13) & Chr(10) & strNewPB & ".pbr"
  684. OSWritePrivateProfileSection "Install.CopyFiles", strTemp, strINFfile
  685. OSWritePrivateProfileString vbNullString, vbNullString, vbNullString, strINFfile
  686. End If
  687. End Function
  688. Function MakeLogFile(ByVal PBName As String) As Integer
  689. Dim intFile As Integer
  690. Dim strFile As String
  691. On Error GoTo MakeFileErr
  692. If CheckPath(locPath & PBName) <> 0 Then
  693. MkDir locPath & PBName
  694. End If
  695. intFile = FreeFile
  696. strFile = locPath & PBName & "\" & PBName & ".log"
  697. If CheckPath(strFile) = 0 Then
  698. Kill strFile
  699. End If
  700. Open strFile For Output As #intFile
  701. Print #intFile, LoadResString(5236); ", "; LoadResString(5237) & _
  702. ", "; LoadResString(5238); ", "; LoadResString(5239)
  703. Close intFile
  704. On Error GoTo 0
  705. Exit Function
  706. MakeFileErr:
  707. Exit Function
  708. End Function
  709. Public Function masterOutfile(file As String, ds As Recordset)
  710. Dim strTemp As String
  711. Dim intFile As Integer
  712. intFile = FreeFile
  713. Open file For Output As #intFile
  714. While Not ds.EOF
  715. Print #intFile, Trim(ds!AccessNumberId); ",";
  716. Print #intFile, Trim(ds!CountryNumber); ",";
  717. If IsNull(ds!RegionID) Then
  718. Print #intFile, ""; ",";
  719. Else
  720. Print #intFile, Trim(ds!RegionID); ",";
  721. End If
  722. Print #intFile, ds!CityName; ",";
  723. Print #intFile, Trim(ds!AreaCode); ",";
  724. Print #intFile, Trim(ds!AccessNumber); ",";
  725. Print #intFile, Trim(ds!MinimumSpeed); ",";
  726. Print #intFile, Trim(ds!MaximumSpeed); ",";
  727. Print #intFile, Trim(ds!FlipFactor); ",";
  728. Print #intFile, Trim(ds!Flags); ",";
  729. If IsNull(ds!ScriptId) Then
  730. Print #intFile, ""
  731. Else
  732. Print #intFile, ds!ScriptId
  733. End If
  734. ds.MoveNext
  735. Wend
  736. Close #intFile
  737. End Function
  738. Public Function deltaoutfile(file As String, ds As Recordset)
  739. Dim strTemp As String
  740. Dim intFile As Integer
  741. intFile = FreeFile
  742. Open file For Output As #intFile
  743. While Not ds.EOF
  744. If ds!CityName = "" Or IsNull(ds!CityName) Then
  745. Print #intFile, ds!AccessNumberId; ",";
  746. Print #intFile, "0"; ",";
  747. Print #intFile, "0"; ",";
  748. Print #intFile, "0"; ",";
  749. Print #intFile, "0"; ",";
  750. Print #intFile, "0"; ",";
  751. Print #intFile, "0"; ",";
  752. Print #intFile, "0"; ",";
  753. Print #intFile, "0"; ",";
  754. Print #intFile, "0"; ",";
  755. Print #intFile, "0"
  756. Else
  757. Print #intFile, Trim(ds!AccessNumberId); ",";
  758. Print #intFile, Trim(ds!CountryNumber); ",";
  759. If IsNull(ds!RegionID) Then
  760. Print #intFile, ""; "0,";
  761. Else
  762. Print #intFile, Trim(ds!RegionID); ",";
  763. End If
  764. Print #intFile, ds!CityName; ",";
  765. Print #intFile, Trim(ds!AreaCode); ",";
  766. Print #intFile, Trim(ds!AccessNumber); ",";
  767. strTemp = Trim(ds!MinimumSpeed)
  768. If Val(strTemp) = 0 Then strTemp = ""
  769. Print #intFile, strTemp; ",";
  770. strTemp = Trim(ds!MaximumSpeed)
  771. If Val(strTemp) = 0 Then strTemp = ""
  772. Print #intFile, strTemp; ",";
  773. Print #intFile, "0"; ",";
  774. Print #intFile, Trim(ds!Flags); ",";
  775. If IsNull(ds!ScriptId) Then
  776. Print #intFile, ""
  777. Else
  778. Print #intFile, ds!ScriptId
  779. End If
  780. End If
  781. ds.MoveNext
  782. Wend
  783. Close #intFile
  784. End Function
  785. Public Function GetINISetting(ByVal section As String, ByVal Key As String) As Variant
  786. Dim intFile, intX As Integer
  787. Dim strLine, strINIFile As String
  788. Dim varTemp(0 To 99, 0 To 1) As Variant
  789. On Error GoTo ReadErr
  790. GetINISetting = Null
  791. intFile = FreeFile
  792. strINIFile = locPath & gsRegAppTitle & ".ini"
  793. Open strINIFile For Input Access Read As #intFile
  794. Do While Not EOF(intFile)
  795. Line Input #intFile, strLine
  796. strLine = Trim(strLine)
  797. If strLine = "[" & section & "]" Then
  798. If Key = "" Then
  799. 'return all keys
  800. intX = 0
  801. Do While Not EOF(intFile)
  802. Line Input #intFile, strLine
  803. strLine = Trim(strLine)
  804. If Left(strLine, 1) <> "[" Then
  805. If strLine <> "" And InStr(strLine, "=") <> 0 Then
  806. varTemp(intX, 0) = Left(strLine, InStr(strLine, "=") - 1)
  807. varTemp(intX, 1) = Right(strLine, Len(strLine) - InStr(strLine, "="))
  808. intX = intX + 1
  809. End If
  810. Else
  811. Exit Do
  812. End If
  813. Loop
  814. Close #intFile
  815. GetINISetting = varTemp
  816. Exit Function
  817. Else
  818. 'return single key
  819. Do While Not EOF(intFile)
  820. Line Input #intFile, strLine
  821. strLine = Trim(strLine)
  822. If strLine <> "" Then
  823. If Key = Left(strLine, InStr(strLine, "=") - 1) Then
  824. GetINISetting = Right(strLine, Len(strLine) - InStr(strLine, "="))
  825. Close #intFile
  826. Exit Function
  827. ElseIf strLine <> "" And Left(strLine, 1) = "[" Then
  828. Close #intFile
  829. Exit Function
  830. End If
  831. End If
  832. Loop
  833. End If
  834. Exit Do
  835. End If
  836. Loop
  837. Close #intFile
  838. Exit Function
  839. ReadErr:
  840. Close #intFile
  841. Exit Function
  842. End Function
  843. Public Function isBitSet(n As Long, i As Integer) As Integer
  844. Dim p As Long
  845. If i = 31 Then
  846. isBitSet = (n < 0) * -1
  847. Else
  848. p = 2 ^ i
  849. isBitSet = (n And p) / p
  850. End If
  851. End Function
  852. Public Sub CenterForm(C As Object, p As Object)
  853. C.Move (p.Width - C.Width) / 2, (p.Height - C.Height) / 2
  854. End Sub
  855. Public Function ReIndexRegions(pb As Database) As Boolean
  856. Dim rsTemp As Recordset, rsTempPop As Recordset, rsTempDelta As Recordset
  857. Dim index As Integer, curindex As Integer, i As Integer, deltnum As Integer
  858. Dim strSQL As String, deltasql As String, popsql As String
  859. On Error GoTo ReIndexError
  860. Set rsTemp = pb.OpenRecordset("Region", dbOpenDynaset)
  861. If Not rsTemp.EOF And Not rsTemp.BOF Then
  862. rsTemp.MoveFirst
  863. index = 1
  864. Do Until rsTemp.EOF
  865. curindex = rsTemp!RegionID
  866. If curindex <> index Then
  867. rsTemp.Edit
  868. rsTemp!RegionID = index
  869. rsTemp.Update
  870. popsql = "Select * from DialUpPort where RegionID = " & curindex
  871. Set rsTempPop = pb.OpenRecordset(popsql, dbOpenDynaset)
  872. If Not (rsTempPop.BOF And rsTempPop.EOF) Then
  873. rsTempPop.MoveFirst
  874. Do Until rsTempPop.EOF
  875. rsTempPop.Edit
  876. rsTempPop!RegionID = index
  877. rsTempPop.Update
  878. If rsTempPop!status = 1 Then
  879. Set rsTempDelta = pb.OpenRecordset("Select * from Delta order by DeltaNum", dbOpenDynaset)
  880. If rsTempDelta.RecordCount = 0 Then
  881. deltnum = 1
  882. Else
  883. rsTempDelta.MoveLast
  884. deltnum = rsTempDelta!deltanum
  885. If deltnum > 6 Then
  886. deltnum = deltnum - 1
  887. End If
  888. End If
  889. For i = 1 To deltnum
  890. deltasql = "Select * from delta where DeltaNum = " & i & _
  891. " AND AccessNumberId = '" & rsTempPop!AccessNumberId & "' " & _
  892. " order by DeltaNum"
  893. Set rsTempDelta = pb.OpenRecordset(deltasql, dbOpenDynaset)
  894. If Not (rsTempDelta.BOF And rsTempDelta.EOF) Then
  895. rsTempDelta.Edit
  896. Else
  897. rsTempDelta.AddNew
  898. rsTempDelta!deltanum = i
  899. rsTempDelta!AccessNumberId = rsTempPop!AccessNumberId
  900. End If
  901. If rsTempPop!status = 1 Then
  902. rsTempDelta!CountryNumber = rsTempPop!CountryNumber
  903. rsTempDelta!AreaCode = rsTempPop!AreaCode
  904. rsTempDelta!AccessNumber = rsTempPop!AccessNumber
  905. rsTempDelta!MinimumSpeed = rsTempPop!MinimumSpeed
  906. rsTempDelta!MaximumSpeed = rsTempPop!MaximumSpeed
  907. rsTempDelta!RegionID = rsTempPop!RegionID
  908. rsTempDelta!CityName = rsTempPop!CityName
  909. rsTempDelta!ScriptId = rsTempPop!ScriptId
  910. rsTempDelta!Flags = rsTempPop!Flags
  911. rsTempDelta.Update
  912. End If
  913. Next i
  914. End If
  915. rsTempPop.MoveNext
  916. Loop
  917. End If
  918. End If
  919. index = index + 1
  920. rsTemp.MoveNext
  921. Loop
  922. End If
  923. ReIndexRegions = True
  924. Exit Function
  925. ReIndexError:
  926. ReIndexRegions = False
  927. End Function
  928. Public Function RegGetValue(sKeyName As String, sValueName As String) As String
  929. Dim lRetVal As Long 'result of the API functions
  930. Dim hKey As Long 'handle of opened key
  931. Dim vValue As Variant 'setting of queried value
  932. lRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKeyName, 0, _
  933. KEY_ALL_ACCESS, hKey)
  934. lRetVal = QueryValueEx(hKey, sValueName, vValue)
  935. 'MsgBox vValue
  936. RegCloseKey (hKey)
  937. RegGetValue = vValue
  938. End Function
  939. Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As _
  940. String, vValue As Variant) As Long
  941. Dim cch As Long
  942. Dim lrc As Long
  943. Dim lType As Long
  944. Dim lValue As Long
  945. Dim sValue As String
  946. On Error GoTo QueryValueExError
  947. ' Determine the size and type of data to be read
  948. lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
  949. If lrc <> ERROR_NONE Then Error 5
  950. Select Case lType
  951. ' For strings
  952. Case REG_SZ:
  953. sValue = String(cch, 0)
  954. lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch)
  955. If lrc = ERROR_NONE Then
  956. vValue = Left$(sValue, cch)
  957. Else
  958. vValue = Empty
  959. End If
  960. ' For DWORDS
  961. Case REG_DWORD:
  962. lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, lValue, cch)
  963. If lrc = ERROR_NONE Then vValue = lValue
  964. Case Else
  965. 'all other data types not supported
  966. lrc = -1
  967. End Select
  968. QueryValueExExit:
  969. QueryValueEx = lrc
  970. Exit Function
  971. QueryValueExError:
  972. Resume QueryValueExExit
  973. End Function
  974. Function CheckPath(ByVal path As String) As Integer
  975. 'function returns 0 if path exists
  976. Dim intRC As Integer
  977. On Error GoTo PathErr
  978. If Trim(path) = "" Or IsNull(path) Then
  979. CheckPath = 1
  980. Exit Function
  981. End If
  982. intRC = GetAttr(path)
  983. CheckPath = 0
  984. Exit Function
  985. PathErr:
  986. CheckPath = 1
  987. Exit Function
  988. End Function
  989. Function SavePOP(ByRef Record As Variant, ByRef dbPB As Database) As Integer
  990. ' Handles inserting or updating a POP.
  991. ' If Record(0) = "" then generate new AccessNumberID and INSERT.
  992. ' Otherwise do like cmdImportRegions; just do an UPDATE and
  993. ' then an INSERT.
  994. Dim strSQL As String
  995. Dim rsPB As Recordset
  996. Dim intX, intNewID As Integer
  997. Dim bInService As Boolean
  998. Dim NewPOP As Recordset
  999. Dim deltasql As String
  1000. Dim deltnum As Integer, i As Integer, addFound As Integer
  1001. On Error GoTo SaveErr
  1002. If Record(0) = "" Then
  1003. Set rsPB = dbPB.OpenRecordset("SELECT max(AccessNumberID) as MaxID from DialUpPort", dbOpenSnapshot)
  1004. If IsNull(rsPB!maxID) Then
  1005. intNewID = 1
  1006. Else
  1007. intNewID = rsPB!maxID + 1
  1008. End If
  1009. rsPB.Close
  1010. Record(0) = intNewID 'try this: edit a referenced array
  1011. 'INSERT
  1012. strSQL = GetSQLPOPInsert(Record)
  1013. dbPB.Execute strSQL
  1014. Else
  1015. Set GsysDial = dbPB.OpenRecordset("SELECT * from DialUpPort where AccessNumberID = " & CStr(Record(0)), dbOpenSnapshot)
  1016. If GsysDial.EOF And GsysDial.BOF Then
  1017. 'INSERT
  1018. strSQL = GetSQLPOPInsert(Record)
  1019. dbPB.Execute strSQL ', dbFailOnError
  1020. Set GsysDial = dbPB.OpenRecordset("SELECT * from DialUpPort where AccessNumberID = " & CStr(Record(0)), dbOpenSnapshot)
  1021. LogPOPAdd GsysDial
  1022. Else
  1023. 'UPDATE
  1024. strSQL = GetSQLPOPUpdate(Record)
  1025. dbPB.Execute strSQL ', dbFailOnError
  1026. 'INSERT
  1027. strSQL = GetSQLPOPInsert(Record)
  1028. dbPB.Execute strSQL ', dbFailOnError
  1029. Set NewPOP = dbPB.OpenRecordset("SELECT * from DialUpPort where AccessNumberID = " & CStr(Record(0)), dbOpenSnapshot)
  1030. LogPOPEdit GsysDial!CityName, NewPOP
  1031. End If
  1032. End If
  1033. If UBound(Record) < 14 Then
  1034. bInService = True
  1035. ElseIf Record(11) = 1 Then
  1036. bInService = True
  1037. Else
  1038. bInService = False
  1039. End If
  1040. If bInService Then ' insert to Delta table if 'In Service'
  1041. Set GsysDelta = dbPB.OpenRecordset("Select * from Delta order by DeltaNum", dbOpenDynaset)
  1042. If GsysDelta.RecordCount = 0 Then
  1043. deltnum = 1
  1044. Else
  1045. GsysDelta.MoveLast
  1046. deltnum = GsysDelta!deltanum
  1047. If deltnum > 6 Then
  1048. deltnum = deltnum - 1
  1049. End If
  1050. End If
  1051. For i = 1 To deltnum
  1052. deltasql = "Select * from delta where DeltaNum = " & i% & " order by DeltaNum"
  1053. Set GsysDelta = dbPB.OpenRecordset(deltasql, dbOpenDynaset)
  1054. addFound = 0 'initialize delta not found
  1055. Do While GsysDelta.EOF = False
  1056. If GsysDelta!AccessNumberId = Record(0) Then
  1057. addFound = 1
  1058. Exit Do
  1059. Else
  1060. GsysDelta.MoveNext
  1061. End If
  1062. Loop
  1063. If addFound = 0 Then
  1064. GsysDelta.AddNew
  1065. GsysDelta!deltanum = i%
  1066. GsysDelta!AccessNumberId = Record(0)
  1067. Else
  1068. GsysDelta.Edit
  1069. End If
  1070. GsysDelta!CountryNumber = Record(1)
  1071. GsysDelta!AreaCode = Record(4)
  1072. GsysDelta!AccessNumber = Record(5)
  1073. GsysDelta!MinimumSpeed = Record(6)
  1074. GsysDelta!MaximumSpeed = Record(7)
  1075. GsysDelta!RegionID = Record(2)
  1076. GsysDelta!CityName = Record(3)
  1077. GsysDelta!ScriptId = Record(10)
  1078. GsysDelta!FlipFactor = Record(8)
  1079. GsysDelta!Flags = Record(9)
  1080. GsysDelta.Update
  1081. Next i%
  1082. End If
  1083. On Error GoTo 0
  1084. Exit Function
  1085. SaveErr:
  1086. SavePOP = CInt(Record(0))
  1087. Exit Function
  1088. End Function
  1089. Function SetFonts(ByRef frmToApply As Form) As Integer
  1090. Const SYMBOL_CHARSET As Integer = 2
  1091. Dim Ctl As Control
  1092. Dim fnt As tmpFont
  1093. GetFont fnt
  1094. If Not TypeOf frmToApply Is MDIForm Then
  1095. If frmToApply.Font.Charset <> SYMBOL_CHARSET Then
  1096. If frmToApply.Font.Size >= 8 And frmToApply.Font.Size <= 9 Then
  1097. frmToApply.Font.Name = fnt.Name
  1098. frmToApply.Font.Size = fnt.Size
  1099. frmToApply.Font.Charset = fnt.Charset
  1100. Else
  1101. frmToApply.Font.Name = fnt.Name
  1102. frmToApply.Font.Charset = fnt.Charset
  1103. End If
  1104. End If
  1105. End If
  1106. On Error Resume Next
  1107. For Each Ctl In frmToApply.Controls
  1108. If Ctl.Font.Charset <> SYMBOL_CHARSET Then
  1109. If Ctl.Font.Size >= 8 And Ctl.Font.Size <= 9 Then
  1110. Ctl.Font.Name = fnt.Name
  1111. Ctl.Font.Size = fnt.Size
  1112. Ctl.Font.Charset = fnt.Charset
  1113. Else
  1114. Ctl.Font.Name = fnt.Name
  1115. Ctl.Font.Charset = fnt.Charset
  1116. End If
  1117. End If
  1118. Next
  1119. On Error GoTo 0
  1120. End Function
  1121. Function GetLocalPath() As String
  1122. ' returns short version of local path
  1123. ' also sets global variable locpath
  1124. On Error GoTo PathErr
  1125. 'locPath = GetMyShortPath(Trim(LCase(App.Path)))
  1126. locPath = Trim(LCase(App.path))
  1127. If Right(locPath, 1) <> "\" Then
  1128. locPath = locPath + "\"
  1129. End If
  1130. '''locPath = "c:\\Program Files\\pbantop\\"
  1131. GetLocalPath = locPath
  1132. On Error GoTo 0
  1133. Exit Function
  1134. PathErr:
  1135. GetLocalPath = ""
  1136. Exit Function
  1137. End Function
  1138. Function SplitLine(ByVal Line As String, ByVal Delimiter As String) As Variant
  1139. ReDim varArray(30)
  1140. Dim intX As Integer
  1141. On Error GoTo SplitErr
  1142. Line = Line & Delimiter
  1143. intX = 0
  1144. ' split out fields - deconstruct Line
  1145. Do While (InStr(Line, Delimiter) <> 0 & intX < 30)
  1146. varArray(intX) = Trim(Left(Line, InStr(Line, Delimiter) - 1))
  1147. If InStr(Line, Delimiter) + 1 <= Len(Line) Then
  1148. Line = Right(Line, Len(Line) - InStr(Line, Delimiter))
  1149. Else
  1150. Exit Do
  1151. End If
  1152. intX = intX + 1
  1153. Loop
  1154. ReDim Preserve varArray(intX)
  1155. SplitLine = varArray()
  1156. On Error GoTo 0
  1157. Exit Function
  1158. SplitErr:
  1159. SplitLine = 1
  1160. Exit Function
  1161. End Function
  1162. Function QuietTestNewPBName(ByVal strNewPB As String) As Integer
  1163. Dim strTemp As String
  1164. Dim varRegKeys As Variant
  1165. Dim intX As Integer
  1166. Dim varTemp As Variant
  1167. On Error GoTo ErrTrap
  1168. strNewPB = Trim(strNewPB)
  1169. If strNewPB = "" Or strNewPB = "empty_pb" Or strNewPB = "pbserver" Then
  1170. QuietTestNewPBName = 6049
  1171. Exit Function
  1172. Else
  1173. varTemp = strNewPB
  1174. If IsNumeric(varTemp) Then
  1175. QuietTestNewPBName = 6095
  1176. Exit Function
  1177. End If
  1178. varRegKeys = GetINISetting("Phonebooks", strNewPB)
  1179. If Not IsNull(varRegKeys) Then
  1180. QuietTestNewPBName = 6050
  1181. Exit Function
  1182. End If
  1183. strTemp = locPath & strNewPB & ".mdb"
  1184. If CheckPath(strTemp) = 0 Then
  1185. QuietTestNewPBName = 6020
  1186. Exit Function
  1187. End If
  1188. 'test write access
  1189. On Error GoTo FileErr
  1190. Open strTemp For Output As #1
  1191. Close #1
  1192. Kill strTemp
  1193. End If
  1194. QuietTestNewPBName = 0
  1195. Exit Function
  1196. ErrTrap:
  1197. Exit Function
  1198. FileErr:
  1199. QuietTestNewPBName = 6051
  1200. Exit Function
  1201. End Function
  1202. Function TestNewPBName(ByVal strNewPB As String) As Integer
  1203. Dim rt As Integer
  1204. Dim intX As Integer
  1205. rt = QuietTestNewPBName(strNewPB)
  1206. If rt <> 0 Then
  1207. If rt = 6020 Then
  1208. ' File already exists
  1209. intX = MsgBox(LoadResString(6020) & Chr(13) & strNewPB & Chr$(13) & _
  1210. LoadResString(6021), _
  1211. vbQuestion + vbYesNo + vbDefaultButton2)
  1212. If intX = vbNo Then ' 7 == no
  1213. TestNewPBName = 1
  1214. Exit Function
  1215. End If
  1216. End If
  1217. MsgBox rt, vbExclamation
  1218. TestNewPBName = 1
  1219. Else
  1220. TestNewPBName = 0
  1221. End If
  1222. End Function
  1223. Public Sub SelectText(txtBox As Control)
  1224. txtBox.SelStart = 0
  1225. txtBox.SelLength = Len(txtBox.Text)
  1226. End Sub
  1227. Public Sub CheckChar(ASCIIChar As Integer)
  1228. Select Case ASCIIChar
  1229. Case 34
  1230. Beep
  1231. ASCIIChar = 0
  1232. Case 44
  1233. Beep
  1234. ASCIIChar = 0
  1235. Case 128 To 159
  1236. Beep
  1237. ASCIIChar = 0
  1238. End Select
  1239. End Sub
  1240. Public Function CreatePB(ByRef strNewPB As String) As Integer
  1241. Dim dblFreeSpace As Double
  1242. Dim rt As Integer
  1243. dblFreeSpace = GetDriveSpace(locPath, 250000)
  1244. If dblFreeSpace = -2 Then
  1245. cmdLogError 6054
  1246. CreatePB = -2
  1247. Exit Function
  1248. End If
  1249. rt = QuietTestNewPBName(strNewPB)
  1250. If rt = 0 Then
  1251. 'ok
  1252. MakeFullINF strNewPB
  1253. MakeLogFile strNewPB
  1254. FileCopy locPath & "empty_pb.mdb", locPath & strNewPB & ".mdb"
  1255. OSWritePrivateProfileString "Phonebooks", strNewPB, strNewPB & ".mdb", locPath & gsRegAppTitle & ".ini"
  1256. OSWritePrivateProfileString vbNullString, vbNullString, vbNullString, locPath & gsRegAppTitle & ".ini"
  1257. Else
  1258. cmdLogError rt
  1259. CreatePB = -1
  1260. End If
  1261. CreatePB = 0
  1262. End Function
  1263. Public Function SetOptions(strURL As String, strUser As String, strPassword As String) As Integer
  1264. Dim i As Integer
  1265. Dim strTemp As String
  1266. Dim configuration As Recordset
  1267. On Error GoTo ErrTrap
  1268. strURL = Trim(strURL)
  1269. strUser = Trim(strUser)
  1270. strPassword = Trim(strPassword)
  1271. If strTemp <> "" Then
  1272. ' max len 64, alpha, numeric
  1273. If strUser = "" Or InStr(strUser, " ") Then
  1274. cmdLogError 6010
  1275. SetOptions = 1
  1276. Exit Function
  1277. ' max len 64, alpha, numeric, meta
  1278. ElseIf strPassword = "" Then
  1279. cmdLogError 6011
  1280. SetOptions = 2
  1281. Exit Function
  1282. End If
  1283. End If
  1284. Set configuration = gsyspb.OpenRecordset("Configuration", dbOpenDynaset)
  1285. If configuration.RecordCount = 0 Then
  1286. configuration.AddNew
  1287. Else
  1288. configuration.Edit
  1289. End If
  1290. configuration!index = 1
  1291. If strURL <> "" Then
  1292. configuration!URL = strURL
  1293. Else
  1294. configuration!URL = Null
  1295. End If
  1296. If strUser <> "" Then
  1297. configuration!ServerUID = strUser
  1298. Else
  1299. configuration!ServerUID = Null
  1300. End If
  1301. If strPassword <> "" Then
  1302. configuration!ServerPWD = strPassword
  1303. Else
  1304. configuration!ServerPWD = Null
  1305. End If
  1306. configuration!NewVersion = 0
  1307. configuration.Update
  1308. configuration.Close
  1309. SetOptions = 0
  1310. Exit Function
  1311. ErrTrap:
  1312. SetOptions = 3
  1313. End Function
  1314. Public Function cmdLogError(ErrorNum As Integer, Optional ErrorMsg As String)
  1315. Dim intFile As Integer
  1316. Dim strFile As String
  1317. On Error GoTo LogErr
  1318. gCLError = True
  1319. intFile = FreeFile
  1320. strFile = locPath & "import.log"
  1321. Open strFile For Append As #intFile
  1322. On Error GoTo 0
  1323. Print #intFile, Now & ", " & gsCurrentPB & ", " & LoadResString(ErrorNum) & ErrorMsg
  1324. Close #intFile
  1325. MsgBox LoadResString(6083)
  1326. Exit Function
  1327. LogErr:
  1328. Exit Function
  1329. End Function