home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / mquery / mprofile.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-02  |  11.2 KB  |  396 lines

  1. VERSION 2.00
  2. Begin Form fStoreQry 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Stored Query Manager"
  6.    ClientHeight    =   3960
  7.    ClientLeft      =   1290
  8.    ClientTop       =   2685
  9.    ClientWidth     =   4980
  10.    ClipControls    =   0   'False
  11.    ControlBox      =   0   'False
  12.    Height          =   4365
  13.    Left            =   1230
  14.    LinkMode        =   1  'Source
  15.    LinkTopic       =   "Form1"
  16.    MaxButton       =   0   'False
  17.    MinButton       =   0   'False
  18.    ScaleHeight     =   3960
  19.    ScaleWidth      =   4980
  20.    Top             =   2340
  21.    Width           =   5100
  22.    Begin OptionButton OpSQLUser 
  23.       BackColor       =   &H00C0C0C0&
  24.       Caption         =   "Public:"
  25.       Height          =   240
  26.       Index           =   1
  27.       Left            =   465
  28.       TabIndex        =   7
  29.       Top             =   2250
  30.       Width           =   885
  31.    End
  32.    Begin OptionButton OpSQLUser 
  33.       BackColor       =   &H00C0C0C0&
  34.       Caption         =   "Private:"
  35.       Height          =   240
  36.       Index           =   0
  37.       Left            =   465
  38.       TabIndex        =   13
  39.       Top             =   1950
  40.       Value           =   -1  'True
  41.       Width           =   915
  42.    End
  43.    Begin CommandButton DeleteBtn 
  44.       Cancel          =   -1  'True
  45.       Caption         =   "&Delete"
  46.       Height          =   375
  47.       Left            =   3735
  48.       TabIndex        =   12
  49.       Top             =   3060
  50.       Width           =   1035
  51.    End
  52.    Begin SSPanel msgpanel 
  53.       Align           =   2  'Align Bottom
  54.       BackColor       =   &H00C0C0C0&
  55.       BevelInner      =   1  'Inset
  56.       Font3D          =   0  'None
  57.       ForeColor       =   &H00FF0000&
  58.       Height          =   420
  59.       Left            =   0
  60.       TabIndex        =   6
  61.       Top             =   3540
  62.       Width           =   4980
  63.    End
  64.    Begin ListBox cqueries 
  65.       BackColor       =   &H00C0C0C0&
  66.       ForeColor       =   &H00000000&
  67.       Height          =   1005
  68.       Left            =   570
  69.       Sorted          =   -1  'True
  70.       TabIndex        =   11
  71.       TabStop         =   0   'False
  72.       Top             =   390
  73.       Width           =   3855
  74.    End
  75.    Begin CommandButton BtnQuit 
  76.       Caption         =   "&Quit"
  77.       Height          =   375
  78.       Left            =   2520
  79.       TabIndex        =   5
  80.       Top             =   3060
  81.       Width           =   1035
  82.    End
  83.    Begin CommandButton BtnRead 
  84.       Caption         =   "&Load"
  85.       Height          =   375
  86.       Left            =   1305
  87.       TabIndex        =   4
  88.       Top             =   3060
  89.       Width           =   1035
  90.    End
  91.    Begin CommandButton BtnWrite 
  92.       Caption         =   "&Save"
  93.       Height          =   375
  94.       Left            =   120
  95.       TabIndex        =   3
  96.       Top             =   3060
  97.       Width           =   1035
  98.    End
  99.    Begin TextBox TxtKey 
  100.       BackColor       =   &H00C0C0C0&
  101.       Height          =   375
  102.       Left            =   1500
  103.       TabIndex        =   2
  104.       Top             =   2520
  105.       Width           =   2895
  106.    End
  107.    Begin TextBox TxtSection 
  108.       BackColor       =   &H00C0C0C0&
  109.       Height          =   375
  110.       Left            =   1500
  111.       TabIndex        =   1
  112.       TabStop         =   0   'False
  113.       Top             =   2040
  114.       Width           =   2895
  115.    End
  116.    Begin TextBox TxtINIFile 
  117.       BackColor       =   &H00C0C0C0&
  118.       Enabled         =   0   'False
  119.       Height          =   375
  120.       Left            =   1500
  121.       TabIndex        =   0
  122.       TabStop         =   0   'False
  123.       Top             =   1560
  124.       Width           =   2895
  125.    End
  126.    Begin Label lblQueries 
  127.       Alignment       =   2  'Center
  128.       AutoSize        =   -1  'True
  129.       BackColor       =   &H00C0C0C0&
  130.       Caption         =   "Select Query"
  131.       Height          =   195
  132.       Left            =   540
  133.       TabIndex        =   9
  134.       Top             =   210
  135.       Width           =   1125
  136.    End
  137.    Begin Label LblKey 
  138.       Alignment       =   1  'Right Justify
  139.       AutoSize        =   -1  'True
  140.       BackColor       =   &H00C0C0C0&
  141.       Caption         =   "Query Name:"
  142.       Height          =   195
  143.       Left            =   285
  144.       TabIndex        =   8
  145.       Top             =   2640
  146.       Width           =   1110
  147.    End
  148.    Begin Label LblINIFile 
  149.       Alignment       =   1  'Right Justify
  150.       AutoSize        =   -1  'True
  151.       BackColor       =   &H00C0C0C0&
  152.       Caption         =   "Storage:"
  153.       Height          =   195
  154.       Left            =   690
  155.       TabIndex        =   10
  156.       Top             =   1620
  157.       Width           =   735
  158.    End
  159. Dim FwriteFlag As Integer ' did I   write
  160. Dim Fdelstr As String
  161. Dim FSection As String
  162. Dim fDefaultuser As String
  163. Sub BtnQuit_Click ()
  164. ' written or quit
  165. If FwriteFlag Then ' stored query
  166. FwriteFlag = False
  167. End If
  168. gstDynaString = ""
  169. ' was this a stored query that was run
  170. If Not gStoredFlag Then     'not from storage
  171.     fQuery!RunSaveQryButton.Enabled = True
  172.     fQuery!RunQueryButton.Enabled = False
  173.         If gfFROMSQL Then  ' was a SQL Statement?
  174.             fQuery!RunQueryButton.Enabled = False
  175.         End If
  176.     fQuery!RunSaveQryButton.Enabled = True
  177. End If
  178. Unload Me
  179. End Sub
  180. Sub BtnRead_Click ()
  181.     If TxtINIFile.Text = "" Then
  182.         Beep
  183.         TxtINIFile.SetFocus
  184.         Exit Sub
  185.     End If
  186.     If TxtSection.Text = "" Then
  187.         Beep
  188.         TxtSection.SetFocus
  189.         Exit Sub
  190.     End If
  191.     If Txtkey.Text = "" Then
  192.         Beep
  193.         Txtkey.SetFocus
  194.         Exit Sub
  195.     End If
  196.     'Assign textbox contents to variables for API call.
  197.     '(API call won't take references to Textbox contents.)
  198.     Sectn$ = TxtSection.Text
  199.     Keyy$ = Txtkey.Text
  200.     DeeFalt$ = ""
  201.     FileNam$ = gWindowsDirectory + "\" + TxtINIFile.Text
  202.      gstDynaString = StringfromPrivINI(Sectn$, Keyy$, DeeFalt$, FileNam$)
  203.     If gstDynaString = "" Then
  204.         msgpanel.Caption = "Section, Key or File name not found."
  205.     Else
  206.          
  207.          
  208.           fQuery!RunSaveQryButton.Enabled = False
  209.           DeleteBtn.Enabled = True
  210.          Unload Me
  211.     End If
  212. End Sub
  213. Sub BtnWrite_Click ()
  214.      FwriteFlag = False
  215.      DeleteBtn.Enabled = False
  216.     If TxtSection.Text = "" Then
  217.         Beep
  218.         TxtSection.SetFocus
  219.         Exit Sub
  220.     End If
  221.     If Txtkey.Text = "" Then
  222.         Beep
  223.         Txtkey.SetFocus
  224.         Exit Sub
  225.     End If
  226.     ' clear out GstDynaString if it has carriage return and linefeeds
  227.     ' pasted or otherwise inserted
  228.     a% = 0
  229.     For y% = 1 To Len(gstDynaString) - 2
  230.     a% = InStr(y% + a%, gstDynaString, Chr(13) + Chr(10))
  231.             If a% Then
  232.                 gstDynaString = Left(gstDynaString, a% - 1) + " " + Mid(gstDynaString, a% + 2, Len(gstDynaString))
  233.             End If
  234.     Next y%
  235.     Sectn$ = TxtSection.Text
  236.     Keyy$ = Txtkey.Text
  237.     Valyue$ = gstDynaString
  238.     FileNam$ = gWindowsDirectory + "\" + TxtINIFile.Text
  239.     Result% = StringtoPrivINI(Sectn$, Keyy$, Valyue$, FileNam$)
  240.     If Result% = 0 Then
  241.          msgpanel.Caption = "QUERY NOT SAVED."
  242.     Else
  243.          msgpanel.Caption = "QUERY SAVED."
  244.          FwriteFlag = True
  245.     End If
  246.     gstDynaString = ""
  247. End Sub
  248. Sub cqueries_Click ()
  249. If gstDynaString = "" Then
  250. Txtkey.Text = cqueries.List(cqueries.ListIndex)
  251. BtnRead.Enabled = True
  252. DeleteBtn.Enabled = True
  253. msgpanel.Caption = "QUERY SELECTED ...LOAD OR DELETE OR QUIT."
  254. End If
  255. End Sub
  256. Sub cqueries_KeyPress (keyascii As Integer)
  257. keyascii = 0
  258. End Sub
  259. Sub DeleteBtn_Click ()
  260. Fdelstr = Txtkey.Text
  261. If MsgBox("Delete " & Fdelstr & " ?", MSGBOX_TYPE) = YES Then
  262. delquery
  263. Unload Me
  264. End If
  265. End Sub
  266. Sub delquery ()
  267. Dim f As String
  268. Dim h As String
  269. Dim a As Integer
  270. Dim b As Integer
  271. Dim filein As String
  272. Dim fileout As String
  273. On Error GoTo errorhere
  274. a = InStr(1, TxtINIFile.Text, ".")
  275. filein = gWindowsDirectory + "\" + TxtINIFile.Text
  276. fileout = gWindowsDirectory + "\" + Left(TxtINIFile, a) + "bak"
  277. h = FSection
  278. Open filein For Input As 1
  279. Open fileout For Output As 2
  280. h = Fdelstr
  281. a = 0
  282. Do Until a > 0
  283.     Line Input #1, f
  284.     a = InStr(1, f, FSection)
  285.     Print #2, f
  286. Do Until EOF(1)
  287.      Line Input #1, f
  288.      a = InStr(1, f, h)
  289.      b = InStr(1, f, "[")
  290.      If b = 1 Then ' found new section
  291.         Print #2, f
  292.         h = "XXXXXX"
  293.      Else
  294.          If a = 0 Then
  295.          Print #2, f
  296.          End If
  297.      End If
  298. closeem:
  299.         Close 1
  300.         Close 2
  301. Kill filein
  302. Name fileout As filein
  303. MsgBox Fdelstr & " Deleted", 48
  304. Exit Sub
  305. errorhere:
  306. MsgBox "Error " & Str(Err), 48
  307. Resume closeem
  308. End Sub
  309. Sub Form_Load ()
  310.     fStoreQry.Left = (Screen.Width - fStoreQry.Width) / 2
  311.     fStoreQry.Top = (Screen.Height - fStoreQry.Height) / 2
  312. '*******************************************************
  313. '*  FDefaultuser can be the user ID from a network     *
  314. '*  Then sections can be PUBLIC for all users and      *
  315. '*  Private for the individual.  This way someone      *
  316. '*  who has a particular query for the database        *
  317. '*  can share it with others.                          *
  318. '*******************************************************
  319.        
  320.        gWindowsDirectory = WinDir()
  321.        fDefaultuser = "SMYTHERE" ' from network ID if MU
  322.        gSQLUser = fDefaultuser
  323.        getsections
  324.         BtnWrite.Enabled = False
  325.         BtnRead.Enabled = False
  326.         DeleteBtn.Enabled = False
  327. If gstDynaString <> "" Then
  328. Txtkey.Text = ""
  329. BtnWrite.Enabled = True
  330. DeleteBtn.Enabled = False
  331. msgpanel.Caption = "Enter a Query Name then SAVE or QUIT"
  332. End If
  333. End Sub
  334. Sub getsections ()
  335. Dim a As Integer
  336. Dim b As Integer
  337. Dim f As String
  338. Dim filein As String
  339. FSection = gSQLUser
  340. TxtSection.Text = FSection
  341. TxtINIFile.Text = "STOREQRY.INI"
  342. filein = TxtINIFile.Text
  343. On Error GoTo nofile
  344. Open gWindowsDirectory + "\" + TxtINIFile.Text For Input As 1
  345.     Line Input #1, f
  346.     a = InStr(1, f, "[" + FSection + "]")
  347. Loop Until a > 0
  348. ' check to see why loop ended
  349. If a Then ' found the section
  350.     Do ' loop until no more keys
  351.             If EOF(1) Then
  352.                 Close 1
  353.                 Exit Sub
  354.             End If
  355.         Line Input #1, f  ' read next line
  356.         a = InStr(1, f, "=") ' if true then we have a key and value
  357.             If a = 0 Then
  358.                     Close 1
  359.                     Exit Sub
  360.             End If
  361.             
  362.                 b = InStr(1, f, "=")  ' true so parse it
  363.                 cqueries.AddItem Left(f, b - 1) 'add query name to combo box
  364.     Loop
  365. Else ' this database not here
  366. MsgBox gstDBname + " Not Found"
  367. Close 1
  368. Exit Sub
  369. End If
  370. getout:
  371. Close 1
  372. Exit Sub
  373. nofile:
  374. If Err = 62 Then
  375. Resume getout
  376. MsgBox "error = " + Str(Err)
  377. Resume getout
  378. End If
  379. End Sub
  380. Sub opSQLUser_Click (Index As Integer)
  381. SQLUserSelect (Index)
  382. cqueries.Clear
  383. getsections' Form_Load
  384. End Sub
  385. Sub SQLUserSelect (I As Integer)
  386. If I = 0 Then
  387.   gSQLUser = fDefaultuser
  388.   gSQLUser = "PUBLIC"
  389. End If
  390. End Sub
  391. Sub TxtKey_KeyPress (keyascii As Integer)
  392. If gstDynaString = "" Then
  393. keyascii = 0
  394. End If
  395. End Sub
  396.