home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vqstrg / vqdemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-12-05  |  15.2 KB  |  486 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "VqString Demonstration"
  4.    ClientHeight    =   4140
  5.    ClientLeft      =   1050
  6.    ClientTop       =   2280
  7.    ClientWidth     =   7860
  8.    ControlBox      =   0   'False
  9.    Height          =   4830
  10.    Left            =   990
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   4140
  16.    ScaleWidth      =   7860
  17.    Top             =   1650
  18.    Width           =   7980
  19.    Begin PictureBox Picture1 
  20.       AutoSize        =   -1  'True
  21.       BorderStyle     =   0  'None
  22.       Height          =   1575
  23.       Left            =   5040
  24.       Picture         =   VQDEMO.FRX:0000
  25.       ScaleHeight     =   1575
  26.       ScaleWidth      =   2535
  27.       TabIndex        =   8
  28.       Top             =   1200
  29.       Width           =   2535
  30.    End
  31.    Begin Frame Frame1 
  32.       Caption         =   "VqString Viewer/Editor"
  33.       Height          =   2715
  34.       Left            =   360
  35.       TabIndex        =   7
  36.       Top             =   660
  37.       Width           =   4395
  38.       Begin HScrollBar HScroll1 
  39.          Enabled         =   0   'False
  40.          Height          =   375
  41.          LargeChange     =   100
  42.          Left            =   240
  43.          Max             =   8192
  44.          Min             =   1
  45.          TabIndex        =   6
  46.          Top             =   1980
  47.          Value           =   1
  48.          Width           =   3795
  49.       End
  50.       Begin TextBox Text2 
  51.          Enabled         =   0   'False
  52.          Height          =   315
  53.          Left            =   3240
  54.          TabIndex        =   3
  55.          Top             =   840
  56.          Width           =   795
  57.       End
  58.       Begin TextBox Text1 
  59.          Enabled         =   0   'False
  60.          Height          =   315
  61.          Left            =   300
  62.          ScrollBars      =   2  'Vertical
  63.          TabIndex        =   1
  64.          Top             =   840
  65.          Width           =   2715
  66.       End
  67.       Begin Label Label1 
  68.          Caption         =   "S&croll"
  69.          Height          =   255
  70.          Left            =   240
  71.          TabIndex        =   5
  72.          Top             =   1680
  73.          Width           =   675
  74.       End
  75.       Begin Label Label5 
  76.          Height          =   315
  77.          Left            =   300
  78.          TabIndex        =   4
  79.          Top             =   1200
  80.          Width           =   3735
  81.       End
  82.       Begin Label Label3 
  83.          Caption         =   "&Select"
  84.          Height          =   255
  85.          Left            =   3240
  86.          TabIndex        =   2
  87.          Top             =   540
  88.          Width           =   615
  89.       End
  90.       Begin Label Label2 
  91.          Caption         =   "&Edit"
  92.          Height          =   255
  93.          Left            =   300
  94.          TabIndex        =   0
  95.          Top             =   540
  96.          Width           =   555
  97.       End
  98.    End
  99.    Begin Menu Demo 
  100.       Caption         =   "&Demonstration"
  101.       Begin Menu VarLenStr 
  102.          Caption         =   "&Variable Length Strings"
  103.          Shortcut        =   ^V
  104.       End
  105.       Begin Menu FixLenStr 
  106.          Caption         =   "&Fixed Length Strings"
  107.          Shortcut        =   ^F
  108.       End
  109.       Begin Menu Separator1 
  110.          Caption         =   "-"
  111.       End
  112.       Begin Menu ExitProgram 
  113.          Caption         =   "E&xit"
  114.          Shortcut        =   ^X
  115.       End
  116.    End
  117.    Begin Menu Help 
  118.       Caption         =   "&Help"
  119.       Begin Menu Contents 
  120.          Caption         =   "&Contents"
  121.          Shortcut        =   {F1}
  122.       End
  123.       Begin Menu Search 
  124.          Caption         =   "&Search"
  125.       End
  126.       Begin Menu Separator2 
  127.          Caption         =   "-"
  128.       End
  129.       Begin Menu About 
  130.          Caption         =   "&About"
  131.       End
  132.    End
  133. Sub About_Click ()
  134. Dim WinFlags As Long
  135. Dim Mode As String, Processor As String
  136. '------  Get current Windows configuration
  137. WinFlags = GetWinFlags()
  138. CRLF$ = Chr$(13) + Chr$(10)
  139. If WinFlags And WF_ENHANCED Then Mode = "386 Enhanced" Else Mode = "Standard"
  140. Temp$ = "VqString Demonstration " + CRLF$
  141. Temp$ = Temp$ + "Vi Qual Software" + CRLF$
  142. Temp$ = Temp$ + "Version 1.0" + CRLF$ + CRLF$
  143. Temp$ = Temp$ + "by Robert B. Heberger" + CRLF$ + CRLF$
  144. Temp$ = Temp$ + "Mode: " + Mode + CRLF$
  145. Temp$ = Temp$ + "Free Memory: " + Format$(GetFreeSpace(0) \ 1024) + " KB"
  146. MsgBox Temp$, 64, "VqStrings"
  147. End Sub
  148. Sub Contents_Click ()
  149. numData& = 1
  150. TempNum% = WinHelp(hWnd, "vqstring.hlp", HELP_CONTEXT, ByVal numData&)
  151. End Sub
  152. Sub ExitProgram_Click ()
  153. '------ Erase VqString arrays
  154. x& = VqFixLenStr(Test, 1, 0, VqEraseString)
  155. x& = VqVarLenStr(Test, 1, 0, VqEraseString)
  156. End Sub
  157. Sub FixLenStr_Click ()
  158. On Error GoTo FixedDemoError
  159. CR$ = Chr$(13) + Chr$(10)
  160. Msg$ = "A huge array of 8,192 fixed length strings will be built," + CR$
  161. Msg$ = Msg$ + "for a total of 131,072 bytes, or 128K of string space." + CR$ + CR$
  162. Msg$ = Msg$ + "The string length is limited to 16 characters." + CR$ + CR$
  163. Msg$ = Msg$ + "They will be stored in a VqString Array." + CR$ + CR$
  164. Msg$ = Msg$ + "Most of the time will be used by Visual Basic to build" + CR$
  165. Msg$ = Msg$ + "the strings."
  166. Response% = MsgBox(Msg$, 65, "Fixed Length Strings")
  167. Form1.Refresh
  168. If Response% = IDCANCEL Then Exit Sub
  169. Text1.Text = ""
  170. Label5.Caption = ""
  171. Text2.Text = ""
  172. Text1.Refresh
  173. Mode = 0
  174. HScroll1.Value = 1
  175. Mode = FixedMode
  176. Elements = 8192
  177. StrSize = 16
  178. '------ Initialize fixed length VqString array
  179. x& = VqFixLenStr(Test, 1, Elements, StrSize)
  180. If x& < 0 Then
  181.     Beep
  182.     MsgBox "Can't allocate buffer", 64, "Error"
  183.     Exit Sub
  184. End If
  185. '------ Fill fixed length VqString array
  186. MousePointer = HourGlass
  187. For i& = 1 To 8192
  188.     Temp$ = Space$(5)
  189.     LSet Temp$ = Str$(i&)
  190.     Test = "Test String" + Temp$
  191.     If VqFixLenStr(Test, 1, i&, VqPutString) < 0 Then Error Abs(VqError)
  192. MousePointer = Default
  193. Text1.Enabled = True
  194. Text2.Enabled = True
  195. HScroll1.Enabled = True
  196. Frame1.Caption = "Fixed Length Strings"
  197. Test = Space$(16)
  198. If VqFixLenStr(Test, 1, 1, VqGetString) < 0 Then Error Abs(VqError)
  199. Text1.Text = Test
  200. SaveText1Text = Text1.Text
  201. SaveHScroll1Value = HScroll1.Value
  202. Label5.Caption = Space$(Len(Text1.Text)) + "|"
  203. Text2.Text = LTrim$(Str$(1))
  204. Exit Sub
  205. FixedDemoError:
  206. MsgBox Error$, 0, "Error"
  207. End Sub
  208. Sub Form_Load ()
  209. Text1.FontName = "Terminal"
  210. Text1.FontBold = False
  211. Text2.FontName = "Terminal"
  212. Text2.FontBold = False
  213. Label5.FontName = "Terminal"
  214. Label5.FontBold = False
  215. LastControl = TextOne
  216. SaveHScroll1Value = HScroll1.Value
  217. End Sub
  218. Sub HelpIndex_Click ()
  219. numData& = 1
  220. TempNum% = WinHelp(hWnd, "c:\vb\hugestr\vqstring.hlp", HELP_CONTEXT, ByVal numData&)
  221. End Sub
  222. Sub HScroll1_Change ()
  223. On Error GoTo HScroll1ChangeError
  224. CR$ = Chr$(13) + Chr$(10)
  225. ScrollEvent = True
  226. Index& = HScroll1.Value
  227. Select Case Mode
  228.     Case VariableMode
  229.         Temp$ = SaveText1Text
  230.         If VqPutVarString(Temp$, 1, CLng(SaveHScroll1Value)) < 0 Then Error Abs(VqError)
  231.         If VqGetVarString(Test, 1, Index&) < 0 Then Error Abs(VqError)
  232.     Case FixedMode
  233.         Temp$ = Space$(16)
  234.         LSet Temp$ = SaveText1Text
  235.         If VqFixLenStr(Temp$, 1, CLng(SaveHScroll1Value), VqPutString) < 0 Then Error Abs(VqError)
  236.         If VqFixLenStr(Test, 1, Index&, VqGetString) < 0 Then Error Abs(VqError)
  237. End Select
  238. Text1.Text = Test
  239. If Mode = FixedMode Then Label5.Caption = Space$(Len(Text1.Text)) + "|"
  240. Text2.Text = LTrim$(Str$(Index&))
  241. Exit Sub
  242. HScroll1ChangeError:
  243. If Mode = VariableMode And VqError = OutOfStringSpace Then
  244.     Beep
  245.     Msg$ = "Out of string space." + CR$
  246.     Msg$ = Msg$ + "There is a limit of 131,072" + CR$
  247.     Msg$ = Msg$ + "bytes in this array."
  248.     MsgBox Msg$, 64, "Out of String Space"
  249.     Test = "Test String" + Str$(SaveHScroll1Value)
  250.     Text1.Text = Test
  251.     SaveText1Text = Test
  252.     Resume Next
  253. End If
  254. MsgBox Error$, 0, "Error"
  255. End Sub
  256. Sub HScroll1_GotFocus ()
  257. On Error GoTo HScroll1GotFocusError
  258. CR$ = Chr$(13) + Chr$(10)
  259. Select Case Mode
  260.     Case FixedMode
  261.         Temp$ = Space$(16)
  262.         LSet Temp$ = SaveText1Text
  263.         If VqFixLenStr(Temp$, 1, CLng(SaveHScroll1Value), VqPutString) < 0 Then Error Abs(VqError)
  264.     Case VariableMode
  265.         Temp$ = SaveText1Text
  266.         If VqPutVarString(Temp$, 1, CLng(SaveHScroll1Value)) < 0 Then Error Abs(VqError)
  267. End Select
  268. Exit Sub
  269. HScroll1GotFocusError:
  270. If Mode = VariableMode And VqError = OutOfStringSpace Then
  271.     Beep
  272.     Msg$ = "Out of string space." + CR$
  273.     Msg$ = Msg$ + "There is a limit of 131,072" + CR$
  274.     Msg$ = Msg$ + "bytes in this array."
  275.     MsgBox Msg$, 64, "Out of String Space"
  276.     Test = "Test String" + Str$(SaveHScroll1Value)
  277.     Text1.Text = Test
  278.     SaveText1Text = Test
  279.     Resume Next
  280. End If
  281. MsgBox Error$, 0, "Error"
  282. End Sub
  283. Sub Pause (Seconds%)
  284. Start! = Timer
  285. Finish = Start + Seconds
  286. While Timer < Finish! And DoEvents()
  287. End Sub
  288. Sub Search_Click ()
  289. numData& = 1
  290. TempNum% = WinHelp(hWnd, "vqstring.hlp", HELP_CONTEXT, ByVal numData&)
  291. Pause (1)
  292. SendKeys ("%s"), True
  293. End Sub
  294. Sub Text1_Change ()
  295. If Not ScrollEvent Then
  296.     SaveText1Text = Text1.Text
  297.     SaveHScroll1Value = HScroll1.Value
  298. End If
  299. ScrollEvent = False
  300. End Sub
  301. Sub Text1_GotFocus ()
  302. LastControl = TextOne
  303. SaveHScroll1Value = HScroll1.Value
  304. SaveText1Text = Text1.Text
  305. End Sub
  306. Sub Text1_KeyDown (KeyCode As Integer, Shift As Integer)
  307. If Mode = FixedMode Then Label5.Caption = Space$(Len(Text1.Text)) + "|"
  308. End Sub
  309. Sub Text1_KeyPress (KeyAscii As Integer)
  310. On Error GoTo Text1KeyPressError
  311. CR$ = Chr$(13) + Chr$(10)
  312. If KeyAscii = 13 Then
  313.     KeyAscii = 0
  314.     Select Case Mode
  315.         Case FixedMode
  316.             Temp$ = Space$(16)
  317.             LSet Temp$ = Text1.Text
  318.             If VqFixLenStr(Temp$, 1, CLng(HScroll1.Value), VqPutString) < 0 Then Error Abs(VqError)
  319.         Case VariableMode
  320.             Temp$ = Text1.Text
  321.             If VqPutVarString(Temp$, 1, CLng(HScroll1.Value)) < 0 Then Error Abs(VqError)
  322.     End Select
  323.     If HScroll1.Value < 8192 Then HScroll1.Value = HScroll1.Value + 1
  324. ElseIf KeyAscii <> 8 And Mode = FixedMode And Len(Text1.Text) = 16 Then
  325.     KeyAscii = 0
  326.     Beep
  327. End If
  328. Exit Sub
  329. Text1KeyPressError:
  330. If Mode = VariableMode And VqError = OutOfStringSpace Then
  331.     Beep
  332.     Msg$ = "Out of string space." + CR$
  333.     Msg$ = Msg$ + "There is a limit of 131,072" + CR$
  334.     Msg$ = Msg$ + "bytes in this array."
  335.     MsgBox Msg$, 64, "Out of String Space"
  336.     Test = "Test String" + Str$(SaveHScroll1Value)
  337.     Text1.Text = Test
  338.     SaveText1Text = Test
  339.     Resume Next
  340. End If
  341. MsgBox Error$, 0, "Error"
  342. End Sub
  343. Sub Text1_KeyUp (KeyCode As Integer, Shift As Integer)
  344. If Mode = FixedMode Then Label5.Caption = Space$(Len(Text1.Text)) + "|"
  345. End Sub
  346. Sub Text1_LostFocus ()
  347. On Error GoTo Text1LostFocusError
  348. CR$ = Chr$(13) + Chr$(10)
  349. Select Case Mode
  350.     Case FixedMode
  351.         Temp$ = Space$(16)
  352.         LSet Temp$ = Text1.Text
  353.         If VqFixLenStr(Temp$, 1, CLng(HScroll1.Value), VqPutString) < 0 Then Error Abs(VqError)
  354.     Case VariableMode
  355.         Temp$ = Text1.Text
  356.         If VqPutVarString(Temp$, 1, CLng(HScroll1.Value)) < 0 Then Error Abs(VqError)
  357. End Select
  358. Exit Sub
  359. Text1LostFocusError:
  360. If Mode = VariableMode And VqError = OutOfStringSpace Then
  361.     Beep
  362.     Msg$ = "Out of string space." + CR$
  363.     Msg$ = Msg$ + "There is a limit of 131,072" + CR$
  364.     Msg$ = Msg$ + "bytes in this array."
  365.     MsgBox Msg$, 64, "Out of String Space"
  366.     Test = "Test String" + Str$(SaveHScroll1Value)
  367.     Text1.Text = Test
  368.     SaveText1Text = Test
  369.     Text2.SetFocus
  370.     Resume Next
  371. End If
  372. MsgBox Error$, 0, "Error"
  373. End Sub
  374. Sub Text2_GotFocus ()
  375. LastControl = TextTwo
  376. SaveHScroll1Value = HScroll1.Value
  377. SaveText1Text = Text1.Text
  378. End Sub
  379. Sub Text2_KeyPress (KeyAscii As Integer)
  380. If KeyAscii = 13 Then
  381.     If Val(Text2.Text) < 1 Or Val(Text2.Text) > 8192 Then
  382.         KeyAscii = 0
  383.         Beep
  384.         MsgBox "Value must be between 1 and 8192", 64, "VqString"
  385.         Exit Sub
  386.     End If
  387.     KeyAscii = 0
  388.     HScroll1.Value = Val(Text2.Text)
  389. End If
  390. End Sub
  391. Sub Text2_LostFocus ()
  392. If Val(Text2.Text) < 1 Or Val(Text2.Text) > 8192 Then
  393.     KeyAscii = 0
  394.     Beep
  395.     MsgBox "Value must be between 1 and 8192", 64, "VqString"
  396.     Text2.SetFocus
  397.     Exit Sub
  398. End If
  399. KeyAscii = 0
  400. HScroll1.Value = Val(Text2.Text)
  401. End Sub
  402. Sub VarLenStr_Click ()
  403. On Error GoTo VariableDemoError
  404. CR$ = Chr$(13) + Chr$(10)
  405. Msg$ = "A huge array of 8,192 variable length strings will be built," + CR$
  406. Msg$ = Msg$ + "for a total of 129,965 bytes, with 1,107 bytes free." + CR$ + CR$
  407. Msg$ = Msg$ + "They will be stored in a VqString Array." + CR$ + CR$
  408. Msg$ = Msg$ + "Most of the time will be used by Visual Basic to build" + CR$
  409. Msg$ = Msg$ + "the strings."
  410. Response% = MsgBox(Msg$, 65, "Variable Length Strings")
  411. Form1.Refresh
  412. If Response% = IDCANCEL Then Exit Sub
  413. Mode = 0
  414. HScroll1.Value = 1
  415. Mode = VariableMode
  416. Text1.Text = ""
  417. Text2.Text = ""
  418. Label5.Caption = ""
  419. Text1.Refresh
  420. Label5.Refresh
  421. Elements = 8192
  422. Bufsize = 131072
  423. '------ Initialize variable length VqString array
  424. x& = VqVarLenStr(Test, 1, Elements, Bufsize)
  425. If x& < 0 Then
  426.     Beep
  427.     MsgBox "Can't allocate buffer", 64, "Error"
  428.     Exit Sub
  429. End If
  430. '------ Fill variable length VqString array
  431. MousePointer = HourGlass
  432. For i& = 1 To 8192
  433.     Test = "Test String" + Str$(i&)
  434.     If VqPutVarString(Test, 1, i&) < 0 Then Error Abs(VqError)
  435. MousePointer = Default
  436. Text1.Enabled = True
  437. Text2.Enabled = True
  438. HScroll1.Enabled = True
  439. 'x& = VqVarLenStr(Strng$, 1, 1, VqVarMemUsed)
  440. 'Print Str$(x&)
  441. 'x& = VqVarLenStr(Strng$, 1, 1, VqVarMemFree)
  442. 'Print Str$(x&)
  443. Frame1.Caption = "Variable Length Strings"
  444. If VqGetVarString(Test, 1, 1) < 0 Then Error Abs(VqError)
  445. Text1.Text = Test
  446. SaveText1Text = Text1.Text
  447. SaveHScroll1Value = HScroll1.Value
  448. Text2.Text = LTrim$(Str$(1))
  449. Exit Sub
  450. VariableDemoError:
  451. MsgBox Error$, 0, "Error"
  452. End Sub
  453. Function VqGetVarString (Strng$, Handle%, Page&)
  454. '------ Support function to get string from variable length
  455. '------  VqString array.
  456. x% = VqVarLenStr(Strng$, Handle%, Page&, VqVarGetSize)
  457. If x% < 0 Then
  458.     VqGetVarString = x%
  459.     VqError = x%
  460.     Exit Function
  461. End If
  462. Strng$ = Space$(x%)
  463. x% = VqVarLenStr(Strng$, Handle%, Page&, VqGetString)
  464. If x% < 0 Then
  465.     VqGetVarString = x%
  466.     VqError = x%
  467.     Exit Function
  468. End If
  469. VqGetVarString = 0
  470. VqError = 0
  471. End Function
  472. Function VqPutVarString (Strng$, Handle%, Page&)
  473. '------ Support function to store string in variable length
  474. '------  VqString array.
  475. '------ Need to append Chr$(0) to end of string.
  476. Strng$ = Strng$ + Chr$(0)
  477. x% = VqVarLenStr(Strng$, Handle%, Page&, VqPutString)
  478. If x% < 0 Then
  479.     VqPutVarString = x%
  480.     VqError = x%
  481.     Exit Function
  482. End If
  483. VqPutVarString = 0
  484. VqError = 0
  485. End Function
  486.