home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PILOT / PC / GCM / PMONEY / FORM1.FRM (.txt) next >
Encoding:
Visual Basic Form  |  1996-11-26  |  20.2 KB  |  595 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Pilot Money Viewer 1.0"
  4.    ClientHeight    =   5895
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1575
  7.    ClientWidth     =   6720
  8.    Height          =   6330
  9.    Left            =   1080
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "notify"
  12.    ScaleHeight     =   5895
  13.    ScaleWidth      =   6720
  14.    Top             =   1200
  15.    Width           =   6840
  16.    Begin VB.Frame FrameGeneral 
  17.       Caption         =   "General Setting"
  18.       Height          =   5295
  19.       Left            =   6720
  20.       TabIndex        =   6
  21.       Top             =   0
  22.       Visible         =   0   'False
  23.       Width           =   4335
  24.       Begin VB.ComboBox comboTrans 
  25.          Height          =   315
  26.          Left            =   1320
  27.          Style           =   2  'Dropdown List
  28.          TabIndex        =   12
  29.          Top             =   960
  30.          Width           =   2895
  31.       End
  32.       Begin VB.ComboBox comboTypes 
  33.          Height          =   315
  34.          Left            =   1320
  35.          Style           =   2  'Dropdown List
  36.          TabIndex        =   11
  37.          Top             =   600
  38.          Width           =   2895
  39.       End
  40.       Begin VB.ComboBox comboCats 
  41.          Height          =   315
  42.          Left            =   1320
  43.          Style           =   2  'Dropdown List
  44.          TabIndex        =   8
  45.          Top             =   240
  46.          Width           =   2895
  47.       End
  48.       Begin VB.Label Label5 
  49.          Caption         =   "Transatction"
  50.          Height          =   255
  51.          Left            =   240
  52.          TabIndex        =   10
  53.          Top             =   1080
  54.          Width           =   975
  55.       End
  56.       Begin VB.Label Label4 
  57.          Caption         =   "Types"
  58.          Height          =   255
  59.          Left            =   240
  60.          TabIndex        =   9
  61.          Top             =   720
  62.          Width           =   975
  63.       End
  64.       Begin VB.Label Label3 
  65.          Caption         =   "Categories"
  66.          Height          =   255
  67.          Left            =   240
  68.          TabIndex        =   7
  69.          Top             =   360
  70.          Width           =   975
  71.       End
  72.    End
  73.    Begin VB.CommandButton btnDone 
  74.       Caption         =   "Done"
  75.       Height          =   375
  76.       Left            =   5400
  77.       TabIndex        =   4
  78.       Top             =   5400
  79.       Width           =   1215
  80.    End
  81.    Begin VB.CommandButton btnGeneral 
  82.       Caption         =   "General"
  83.       Height          =   375
  84.       Left            =   2280
  85.       TabIndex        =   3
  86.       Top             =   5400
  87.       Width           =   1215
  88.    End
  89.    Begin VB.Frame FrameDetails 
  90.       Caption         =   "Details"
  91.       Height          =   5295
  92.       Left            =   2280
  93.       TabIndex        =   2
  94.       Top             =   0
  95.       Width           =   4335
  96.       Begin VB.TextBox txt 
  97.          Height          =   285
  98.          Index           =   9
  99.          Left            =   1080
  100.          TabIndex        =   27
  101.          Text            =   "Text1"
  102.          Top             =   2040
  103.          Width           =   3135
  104.       End
  105.       Begin VB.CheckBox chk 
  106.          Caption         =   "Private"
  107.          Height          =   255
  108.          Index           =   10
  109.          Left            =   1080
  110.          TabIndex        =   26
  111.          Top             =   2880
  112.          Width           =   1455
  113.       End
  114.       Begin VB.TextBox txt 
  115.          Height          =   285
  116.          Index           =   4
  117.          Left            =   1080
  118.          TabIndex        =   25
  119.          Text            =   "Text1"
  120.          Top             =   1680
  121.          Width           =   3135
  122.       End
  123.       Begin VB.CheckBox chk 
  124.          Caption         =   "Receipt"
  125.          Height          =   255
  126.          Index           =   8
  127.          Left            =   1080
  128.          TabIndex        =   23
  129.          Top             =   2640
  130.          Width           =   1455
  131.       End
  132.       Begin VB.CheckBox chk 
  133.          Caption         =   "Cleared"
  134.          Height          =   255
  135.          Index           =   7
  136.          Left            =   1080
  137.          TabIndex        =   22
  138.          Top             =   2400
  139.          Width           =   1455
  140.       End
  141.       Begin VB.TextBox txt 
  142.          Height          =   1095
  143.          Index           =   6
  144.          Left            =   1080
  145.          TabIndex        =   17
  146.          Text            =   "Text1"
  147.          Top             =   3360
  148.          Width           =   3135
  149.       End
  150.       Begin VB.TextBox txt 
  151.          Height          =   285
  152.          Index           =   5
  153.          Left            =   1080
  154.          TabIndex        =   16
  155.          Text            =   "Text1"
  156.          Top             =   1320
  157.          Width           =   3135
  158.       End
  159.       Begin VB.TextBox txt 
  160.          Height          =   285
  161.          Index           =   3
  162.          Left            =   1080
  163.          TabIndex        =   15
  164.          Text            =   "Text1"
  165.          Top             =   960
  166.          Width           =   3135
  167.       End
  168.       Begin VB.TextBox txt 
  169.          Height          =   285
  170.          Index           =   2
  171.          Left            =   1080
  172.          TabIndex        =   14
  173.          Text            =   "Text1"
  174.          Top             =   600
  175.          Width           =   3135
  176.       End
  177.       Begin VB.TextBox txt 
  178.          Height          =   285
  179.          Index           =   1
  180.          Left            =   1080
  181.          TabIndex        =   13
  182.          Text            =   "Text1"
  183.          Top             =   240
  184.          Width           =   3135
  185.       End
  186.       Begin VB.Label Label2 
  187.          Caption         =   "Category"
  188.          Height          =   255
  189.          Index           =   6
  190.          Left            =   240
  191.          TabIndex        =   28
  192.          Top             =   2040
  193.          Width           =   735
  194.       End
  195.       Begin VB.Label Label2 
  196.          Caption         =   "Type"
  197.          Height          =   255
  198.          Index           =   5
  199.          Left            =   240
  200.          TabIndex        =   24
  201.          Top             =   1680
  202.          Width           =   735
  203.       End
  204.       Begin VB.Label Label2 
  205.          Caption         =   "Notes:"
  206.          Height          =   255
  207.          Index           =   4
  208.          Left            =   240
  209.          TabIndex        =   21
  210.          Top             =   3360
  211.          Width           =   735
  212.       End
  213.       Begin VB.Label Label2 
  214.          Caption         =   "Descript:"
  215.          Height          =   255
  216.          Index           =   3
  217.          Left            =   240
  218.          TabIndex        =   20
  219.          Top             =   1320
  220.          Width           =   735
  221.       End
  222.       Begin VB.Label Label2 
  223.          Caption         =   "Date"
  224.          Height          =   255
  225.          Index           =   2
  226.          Left            =   240
  227.          TabIndex        =   19
  228.          Top             =   960
  229.          Width           =   735
  230.       End
  231.       Begin VB.Label Label2 
  232.          Caption         =   "Amount"
  233.          Height          =   255
  234.          Index           =   1
  235.          Left            =   240
  236.          TabIndex        =   18
  237.          Top             =   600
  238.          Width           =   735
  239.       End
  240.       Begin VB.Label Label2 
  241.          Caption         =   "Check#"
  242.          Height          =   255
  243.          Index           =   0
  244.          Left            =   240
  245.          TabIndex        =   5
  246.          Top             =   240
  247.          Width           =   735
  248.       End
  249.    End
  250.    Begin VB.ListBox List1 
  251.       Height          =   5520
  252.       Left            =   120
  253.       TabIndex        =   0
  254.       Top             =   240
  255.       Width           =   2055
  256.    End
  257.    Begin VB.Label Label1 
  258.       Caption         =   "Transacation:"
  259.       Height          =   255
  260.       Left            =   120
  261.       TabIndex        =   1
  262.       Top             =   0
  263.       Width           =   1815
  264.    End
  265. Attribute VB_Name = "Form1"
  266. Attribute VB_Creatable = False
  267. Attribute VB_Exposed = False
  268. Option Explicit
  269. 'things to do: if record is deleted, don't show it
  270. ' change view screen to a grid
  271. ' allow grid export to .CSV file
  272. ''''''''''''''''''''''''''''''''''''''''''
  273. '''''' Conduit Manager structures
  274. ''''''''''''''''''''''''''''''''''''''''''
  275. Private Type tHeader
  276.   sName As String * 32
  277.   dwUnknown1 As Long
  278.   dwTime1 As Long
  279.   dwTime2 As Long
  280.   dwTime3 As Long
  281.   dwLastSync As Long
  282.   ofsAppInfo As Long
  283.   ofsCategories As Long
  284.   dwType As Long
  285.   dwCreator As Long
  286.   dwUnknown2  As Long
  287.   dwUnknown As Long
  288.   wNumRecs As Integer
  289. End Type
  290. Const kOfsSort = &H34
  291. Const kOfsCategories = &H38
  292. Const kOfsCreator = &H3C
  293. Const kOfsNumRecs = &H4C
  294. Const kOfsEntries = &H4E
  295. Private Type tRecEntry
  296.   ofs As Long
  297.   attrib As Long
  298. End Type
  299. Const DIRTY = &H40000000
  300. Const DELETED = &H80000000
  301. Const RE_PRIVATE = &H10000000
  302. '''''''''''''''''''''''''''''''''''''''''''
  303. '''' Pilot Money structures
  304. '''''''''''''''''''''''''''''''''''''''''''
  305. 'NOTE: remember: all of the numbers are Mac format!
  306. Private Type MoneyAppInfo
  307.     renamedCategories As Integer
  308.     categoryLabels(15) As String * 16 'actually char[16][16]
  309.     categoryUniqIDs As String * 16  'actually char[16]
  310.     lastUniqID As Byte
  311.     Reserved1 As Byte
  312.     Reserved2 As Integer
  313.         'The above stuff is all standard. The type and tran labels are
  314.         ' for the popup lists in the Transaction Edit screen
  315.     typeLabels(19) As String * 10   'actually char[20][10];
  316.     tranLabels(19) As String * 20  'actually char[20][20];
  317. End Type
  318. Private Type MoneyPreferences
  319.     displayPref As Byte          '// Display Prefs - Used for check# display etc
  320.     repeatBound As Integer      '/ How far in advance we repeat transactions
  321.     currentCategory As Integer '    // What category are we looking at
  322.     topVisibleRecord As Integer '   // Which is the first record on the page
  323.     currentRecord As Integer    ';      // Which record were we last looking at?
  324.     currentRecordID As Long '    // The ID of that recod in case the hotsync
  325.         'changes things and we need to look for it
  326.     amountwidth As Byte
  327.     prefflags As Byte ' // Width of the amount column and some flags
  328.     mainstatuschoise As Byte '   // On the main display do we show Current, Min, Max balance?
  329.     dollarSign As Byte '       // What character do we want to use for the amounts?
  330.     version As Byte '          // What version of the database are we on?
  331. End Type
  332. Private Type DateTime
  333.     sec As Integer
  334.     min As Integer
  335.     hour As Integer
  336.     day As Integer
  337.     month As Integer
  338.     year As Integer
  339.     dow As Integer
  340. End Type
  341. Private Type MoneyTransaction
  342.     flags As Integer '          // Has it cleared? Do we have a receipt? 1=cleared, 2=noExport
  343.     checknum As Integer '       // Check number or 0
  344.     amount As Long
  345.     total As Long     '/ The "dollar" value of the amount and the runn
  346.             'ing total after this transaction clears
  347.     amountc As Integer
  348.     totalc As Integer ';   // The cents values as above
  349.     date As DateTime '           // Transaction date
  350.     repeat As Byte ';         // Type of repeat or 0 if it doesnt repeat
  351.     flags2 As Byte ';         // More flags; 1=receipt
  352.     type As Byte '           // Which of the "type" list items this belongs to
  353.     Reserved1 As Byte '      // for expansion
  354.     Reserved2 As Byte '      // For expansion
  355.     Reserved3 As Byte '      // For expansion
  356.     description As String * 19 '    // The actual description of the transaction
  357.     note As String * 401 '        // '0' terminated notes field.
  358. End Type
  359. 'screen versions
  360. Const kCheckNum = 1
  361. Const kAmount = 2
  362. Const kDate = 3
  363. Const kType = 4
  364. Const kDesc = 5
  365. Const kNote = 6
  366. Const kCleared = 7
  367. Const kReceipt = 8
  368. Const kCategory = 9
  369. Const kPrivate = 10
  370. '########################################
  371. '############ REGISTRY ##################
  372. '########################################
  373. Const REG_SZ As Long = 1
  374. Const REG_DWORD As Long = 4
  375. Const HKEY_CLASSES_ROOT = &H80000000
  376. Const HKEY_CURRENT_USER = &H80000001
  377. Const HKEY_LOCAL_MACHINE = &H80000002
  378. Const HKEY_USERS = &H80000003
  379. Const ERROR_NONE = 0
  380. Const ERROR_BADDB = 1
  381. Const ERROR_BADKEY = 2
  382. Const ERROR_CANTOPEN = 3
  383. Const ERROR_CANTREAD = 4
  384. Const ERROR_CANTWRITE = 5
  385. Const ERROR_OUTOFMEMORY = 6
  386. Const ERROR_INVALID_PARAMETER = 7
  387. Const ERROR_ACCESS_DENIED = 8
  388. Const ERROR_INVALID_PARAMETERS = 87
  389. Const ERROR_NO_MORE_ITEMS = 259
  390. Const KEY_ALL_ACCESS = &H3F
  391. Const REG_OPTION_NON_VOLATILE = 0
  392. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  393. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
  394.     "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
  395.     ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
  396. Private Declare Function RegQueryValueExString Lib "advapi32.dll" Alias _
  397.     "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
  398.     String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
  399.     As String, lpcbData As Long) As Long
  400. Private Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias _
  401.     "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
  402.     String, ByVal lpReserved As Long, lpType As Long, lpData As _
  403.     Long, lpcbData As Long) As Long
  404. Private Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias _
  405.     "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
  406.     String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
  407.     As Long, lpcbData As Long) As Long
  408. Const sMainKey = "Software\Palm Computing\Pilot Desktop"
  409. 'Globals
  410. Dim sFileName As String         'the file
  411. Dim header As tHeader           'file header
  412. Dim appinfo As MoneyAppInfo     'file header
  413. Dim aRecEntry() As tRecEntry    'copy of the file index
  414. Dim aRec() As MoneyTransaction  'holds the actual data; one-to-one with aRecEntry()
  415. Dim nRecs As Integer
  416. Dim nCurSel As Integer          'index into the list1 list box
  417. Sub FillScreen(i As Integer)
  418.     nCurSel = i
  419.     txt(kCheckNum) = Format(SwapWord(aRec(nCurSel).checknum))
  420.     txt(kAmount) = Format(SwapLong(aRec(nCurSel).amount) + SwapWord(aRec(nCurSel).amountc) / 100#, "$#0.00")
  421.     txt(kDate) = Format(PilotToDate(aRec(nCurSel).date), "General Date")
  422.     txt(kDesc) = aRec(nCurSel).description
  423.     txt(kNote) = aRec(nCurSel).note
  424.     txt(kType) = comboTypes.List(aRec(nCurSel).type)
  425.     txt(kCategory) = comboCats.List((aRecEntry(nCurSel).attrib And &HF000000) \ &H1000000)
  426.     chk(kCleared) = aRec(nCurSel).flags And 1
  427.     chk(kReceipt) = aRec(nCurSel).flags2 And 1
  428.     If ((aRecEntry(nCurSel).attrib And RE_PRIVATE) = RE_PRIVATE) Then
  429.         chk(kPrivate) = 1
  430.     Else
  431.         chk(kPrivate) = 0
  432.     End If
  433. End Sub
  434. Private Function PilotToDate(s As DateTime) As Date
  435.     Dim dw2 As Long
  436.     PilotToDate = DateSerial(SwapWord(s.year), SwapWord(s.month), SwapWord(s.day)) + _
  437.         TimeSerial(SwapWord(s.hour), SwapWord(s.min), SwapWord(s.sec))
  438.     'CDate(dw2 / 3600# / 24#) ' - CDate("Jan 1, 1970")
  439. End Function
  440. Sub OpenAndRead(sFile As String)
  441.     List1.Clear
  442.     comboCats.Clear
  443.     comboTrans.Clear
  444.     comboTypes.Clear
  445.     nRecs = 0
  446.     On Error GoTo or_err
  447.     Dim dwFileLen As Long
  448.     dwFileLen = FileLen(sFile)
  449.     Open sFile For Binary Access Read As 1
  450.     Get #1, , header
  451.     nRecs = SwapWord(header.wNumRecs)
  452.     ReDim aRecEntry(nRecs - 1)
  453.     Dim i As Integer
  454.     For i = 0 To nRecs - 1
  455.         Get #1, , aRecEntry(i)
  456.         aRecEntry(i).attrib = SwapLong(aRecEntry(i).attrib)
  457.     Next
  458.     Dim dw As Long
  459.     dw = SwapLong(header.ofsAppInfo)
  460.     Seek #1, dw + 1
  461.     Get #1, , appinfo
  462.     ReDim aRec(nRecs - 1)
  463.     For i = 0 To nRecs - 1
  464.         dw = SwapLong(aRecEntry(i).ofs)
  465.         Seek #1, dw + 1
  466.         Get #1, , aRec(i)
  467.     Next
  468.     Close #1
  469.     'fill the list box
  470.     For i = 0 To nRecs - 1
  471.         If (aRecEntry(i).attrib And DELETED) = 0 Then
  472.             List1.AddItem Format(PilotToDate(aRec(i).date), "Short Date") & "  " & Format(SwapLong(aRec(i).amount), "Currency")
  473.         End If
  474.     Next
  475.     For i = 0 To 15
  476.         If Asc(appinfo.categoryLabels(i)) = 0 Then Exit For
  477.         comboCats.AddItem appinfo.categoryLabels(i)
  478.     Next
  479.     comboCats.ListIndex = 0
  480.         
  481.     For i = 0 To 19
  482.         If Asc(appinfo.typeLabels(i)) = 0 Then Exit For
  483.         comboTypes.AddItem appinfo.typeLabels(i)
  484.     Next
  485.     comboTypes.ListIndex = 0
  486.         
  487.     For i = 0 To 15
  488.         If Asc(appinfo.tranLabels(i)) = 0 Then Exit For
  489.         comboTrans.AddItem appinfo.tranLabels(i)
  490.     Next
  491.     comboTrans.ListIndex = 0
  492.         
  493.     List1.ListIndex = 0
  494.     Exit Sub
  495. or_err:
  496.     Close #1
  497.     On Error GoTo 0
  498. End Sub
  499. Public Function SwapWord(w As Integer)
  500.     Dim s As String
  501.     s = Right("000" & Hex(w), 4)
  502.     SwapWord = Val("&H" & Mid(s, 3, 2) & Mid(s, 1, 2))
  503. End Function
  504. Public Function SwapLong(d As Long)
  505.     Dim s As String
  506.     s = Right("0000000" & Hex(d), 8)
  507.     SwapLong = Val("&H" & Mid(s, 7, 2) & Mid(s, 5, 2) & Mid(s, 3, 2) & Mid(s, 1, 2))
  508. End Function
  509. Private Sub btnDone_Click()
  510.     End
  511. End Sub
  512. Private Sub btnGeneral_Click()
  513.     If FrameGeneral.Visible Then
  514.         FrameGeneral.Visible = False
  515.         FrameDetails.Visible = True
  516.     Else
  517.         FrameGeneral.Left = FrameDetails.Left
  518.         FrameGeneral.Visible = True
  519.         FrameDetails.Visible = False
  520.     End If
  521. End Sub
  522. Private Sub Form_LinkExecute(CmdStr As String, Cancel As Integer)
  523.     Static sTitle As String
  524.     Select Case CmdStr
  525.         Case "sync start"
  526. '            If bDirty Then SaveRecords
  527.             sTitle = Form1.Caption
  528.             Form1.Caption = sTitle & " (syncing)"
  529.             Me.Enabled = False
  530.         Case "sync finished"
  531.             Me.Enabled = True
  532.             Form1.Caption = sTitle
  533.             OpenAndRead (sFileName)
  534.     End Select
  535.     Cancel = 0
  536. End Sub
  537.                                 'the listbox.itemdata is a index into the aRecs() array
  538. Private Sub Form_Load()
  539.     sFileName = QueryValue(sMainKey & "\Preferences", "LastUserDir")
  540.     If sFileName <> "" Then
  541.         sFileName = sFileName & "\PMoney\PMoney.dat"
  542.         OpenAndRead (sFileName)
  543.     End If
  544. End Sub
  545. 'usage:    QueryValue "TestKey\SubKey1", "StringValue"
  546. Public Function QueryValue(sKeyName As String, sValueName As String) As Variant
  547.     Dim lRetVal As Long         'result of the API functions
  548.     Dim hKey As Long         'handle of opened key
  549.     Dim vValue As Variant      'setting of queried value
  550.     lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0, _
  551.         KEY_ALL_ACCESS, hKey)
  552.     lRetVal = QueryValueEx(hKey, sValueName, vValue)
  553.     QueryValue = vValue
  554.     RegCloseKey (hKey)
  555. End Function
  556. Function QueryValueEx(ByVal lhKey As Long, _
  557.     ByVal szValueName As String, _
  558.     vValue As Variant) As Long
  559.         Dim cch As Long
  560.         Dim lrc As Long
  561.         Dim lType As Long
  562.         Dim lValue As Long
  563.         Dim sValue As String
  564.         On Error GoTo QueryValueExError
  565.         ' Determine the size and type of data to be read
  566.         lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
  567.         If lrc <> ERROR_NONE Then Error 5
  568.         Select Case lType
  569.             ' For strings
  570.             Case REG_SZ:
  571.                 sValue = String(cch, 0)
  572.                 lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch)
  573.                 If lrc = ERROR_NONE Then
  574.                     vValue = Left$(sValue, cch - 1) 'RegQuery returns the 0 term
  575.                 Else
  576.                     vValue = Empty
  577.                 End If
  578.             ' For DWORDS
  579.             Case REG_DWORD:
  580.                 lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, lValue, cch)
  581.                 If lrc = ERROR_NONE Then vValue = lValue
  582.             Case Else
  583.                 'all other data types not supported
  584.                 lrc = -1
  585.         End Select
  586. QueryValueExExit:
  587.         QueryValueEx = lrc
  588.         Exit Function
  589. QueryValueExError:
  590.         Resume QueryValueExExit
  591. End Function
  592. Private Sub List1_Click()
  593.     FillScreen List1.ListIndex
  594. End Sub
  595.