home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code2 / string / form1.frm next >
Text File  |  1994-07-15  |  15KB  |  488 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Sample Application To Demonstrate STRING.DLL"
  5.    ClientHeight    =   7035
  6.    ClientLeft      =   1245
  7.    ClientTop       =   1710
  8.    ClientWidth     =   8160
  9.    Height          =   7725
  10.    Left            =   1185
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   7035
  13.    ScaleWidth      =   8160
  14.    Top             =   1080
  15.    Width           =   8280
  16.    Begin SSFrame Frame3D1 
  17.       Caption         =   "LexSortStr Demo"
  18.       Font3D          =   3  'Inset w/light shading
  19.       Height          =   3405
  20.       Left            =   120
  21.       TabIndex        =   10
  22.       Top             =   3015
  23.       Width           =   7920
  24.       Begin TextBox textnum 
  25.          Height          =   300
  26.          Left            =   2655
  27.          TabIndex        =   15
  28.          Text            =   "10"
  29.          Top             =   1965
  30.          Width           =   405
  31.       End
  32.       Begin SSCheck casesens 
  33.          Caption         =   "Case sensitive"
  34.          Font3D          =   0  'None
  35.          Height          =   285
  36.          Left            =   2640
  37.          TabIndex        =   14
  38.          Top             =   1560
  39.          Width           =   1935
  40.       End
  41.       Begin CommandButton Command3 
  42.          BackColor       =   &H00000000&
  43.          Caption         =   "Sort the lefthand list into right"
  44.          Height          =   510
  45.          Left            =   2595
  46.          TabIndex        =   13
  47.          Top             =   900
  48.          Width           =   2745
  49.       End
  50.       Begin ListBox List2 
  51.          Height          =   2370
  52.          Left            =   5400
  53.          TabIndex        =   12
  54.          Top             =   315
  55.          Width           =   2445
  56.       End
  57.       Begin ListBox List1 
  58.          Height          =   2370
  59.          Left            =   75
  60.          TabIndex        =   11
  61.          Top             =   315
  62.          Width           =   2445
  63.       End
  64.       Begin Label Label4 
  65.          BackStyle       =   0  'Transparent
  66.          Caption         =   "# of characters to sort by"
  67.          Height          =   240
  68.          Left            =   3105
  69.          TabIndex        =   16
  70.          Top             =   2025
  71.          Width           =   2205
  72.       End
  73.    End
  74.    Begin CommandButton Command5 
  75.       Caption         =   "LexSortStr"
  76.       Height          =   480
  77.       Left            =   120
  78.       TabIndex        =   8
  79.       Top             =   2070
  80.       Width           =   1755
  81.    End
  82.    Begin CommandButton Command4 
  83.       Caption         =   "FindFirstNIS"
  84.       Height          =   480
  85.       Left            =   120
  86.       TabIndex        =   7
  87.       Top             =   1515
  88.       Width           =   1755
  89.    End
  90.    Begin CommandButton Command2 
  91.       Caption         =   "FindRightChar"
  92.       Height          =   480
  93.       Left            =   120
  94.       TabIndex        =   3
  95.       Top             =   960
  96.       Width           =   1755
  97.    End
  98.    Begin TextBox Text2 
  99.       Height          =   975
  100.       Left            =   1965
  101.       MultiLine       =   -1  'True
  102.       ScrollBars      =   3  'Both
  103.       TabIndex        =   2
  104.       Top             =   1815
  105.       Width           =   6090
  106.    End
  107.    Begin TextBox Text1 
  108.       Height          =   1125
  109.       Left            =   1965
  110.       MultiLine       =   -1  'True
  111.       ScrollBars      =   3  'Both
  112.       TabIndex        =   1
  113.       Text            =   "This is a test string; This is a test string; This is a test string; This is a test string; This is a test string; This is a test string; This is a test string; This is a test string; This is a test string; This is a test string; This is a test string; Th"
  114.       Top             =   390
  115.       Width           =   6090
  116.    End
  117.    Begin CommandButton Command1 
  118.       Caption         =   "ReverseStr"
  119.       Height          =   495
  120.       Left            =   120
  121.       TabIndex        =   0
  122.       Top             =   405
  123.       Width           =   1755
  124.    End
  125.    Begin Label Label3 
  126.       AutoSize        =   -1  'True
  127.       BackStyle       =   0  'Transparent
  128.       Caption         =   "⌐1994 by INside; P.O. Box 965; 3000 Bern 9; Switzerland"
  129.       Height          =   195
  130.       Left            =   1920
  131.       TabIndex        =   9
  132.       Top             =   6570
  133.       Width           =   4935
  134.    End
  135.    Begin Label Label2 
  136.       AutoSize        =   -1  'True
  137.       BackStyle       =   0  'Transparent
  138.       Caption         =   "Label2"
  139.       FontBold        =   -1  'True
  140.       FontItalic      =   0   'False
  141.       FontName        =   "MS Sans Serif"
  142.       FontSize        =   9.75
  143.       FontStrikethru  =   0   'False
  144.       FontUnderline   =   0   'False
  145.       Height          =   240
  146.       Left            =   4140
  147.       TabIndex        =   6
  148.       Top             =   90
  149.       Width           =   720
  150.    End
  151.    Begin Label Label1 
  152.       AutoSize        =   -1  'True
  153.       BackStyle       =   0  'Transparent
  154.       Caption         =   "Output text window:"
  155.       FontBold        =   -1  'True
  156.       FontItalic      =   0   'False
  157.       FontName        =   "MS Sans Serif"
  158.       FontSize        =   9.75
  159.       FontStrikethru  =   0   'False
  160.       FontUnderline   =   0   'False
  161.       Height          =   240
  162.       Index           =   1
  163.       Left            =   1950
  164.       TabIndex        =   5
  165.       Top             =   1575
  166.       Width           =   1965
  167.    End
  168.    Begin Label Label1 
  169.       AutoSize        =   -1  'True
  170.       BackStyle       =   0  'Transparent
  171.       Caption         =   "Source text window:"
  172.       FontBold        =   -1  'True
  173.       FontItalic      =   0   'False
  174.       FontName        =   "MS Sans Serif"
  175.       FontSize        =   9.75
  176.       FontStrikethru  =   0   'False
  177.       FontUnderline   =   0   'False
  178.       Height          =   240
  179.       Index           =   0
  180.       Left            =   1965
  181.       TabIndex        =   4
  182.       Top             =   90
  183.       Width           =   2040
  184.    End
  185.    Begin Menu dat 
  186.       Caption         =   "&File"
  187.       Begin Menu datei 
  188.          Caption         =   "&Exit"
  189.          Index           =   0
  190.       End
  191.    End
  192.    Begin Menu in 
  193.       Caption         =   "&?"
  194.       Begin Menu info 
  195.          Caption         =   "&Info"
  196.          Index           =   0
  197.       End
  198.    End
  199. End
  200. Option Explicit
  201.  
  202. Sub Command1_Click ()
  203. '***********************************************************
  204. '**      SAMPLE CODE FOR THE ReverseStr FUNCTION       **
  205. '***********************************************************
  206. '*   Reverses the indicated string                         *
  207. '***********************************************************
  208.  
  209. 'variable used to store the return value of the function call:
  210. Dim ret As Integer
  211. 'variables used to time the function call:
  212. Dim tstart As Long
  213. Dim atRev As Long
  214.  
  215. 'initialize the variables
  216. lpstrDATA = Space$(65000)
  217. 'when calling dll's, the memory for strings being passed
  218. 'back and forth must be allocated by Visual Basic.
  219. 'this is done simply by filling up the variable with blanks!
  220.  
  221. 'assign the string to be reversed to the variable:
  222. lpstrDATA = text1.Text
  223.  
  224. 'get the system tick count as a timer mark:
  225. tstart = GetTickCount()
  226.  
  227. 'execute the dll function:
  228. ret = ReverseStr(lpstrDATA)
  229.  
  230. 'get the system tick count as a timer mark:
  231. atRev = GetTickCount()
  232.  
  233. 'assign the resulting string now stored in lpstrDATA to the
  234. 'textfield:
  235. text2.Text = Trim$(lpstrDATA)
  236. 'please note: all the empty space in a string can easily be eliminated
  237. 'by "trimming" the string variable!
  238.  
  239. MsgBox "It took me " + Trim$(Str$(atRev - tstart)) + " milliseconds to reverse a string 65000 chars length", 64, DLG_CAPTION
  240.  
  241. If atRev - tstart > 200 Then MsgBox "You must have been reading the about dialog; it normally doesn't take that long! <g> Try it again and it will be *A LOT* faster...", 64, DLG_CAPTION
  242.  
  243. End Sub
  244.  
  245. Sub Command2_Click ()
  246. '***********************************************************
  247. '**      SAMPLE CODE FOR THE FindRightChar FUNCTION       **
  248. '***********************************************************
  249. '*   Searches the last occurence of iChar within lpstrDATA *
  250. '*   and highlights the character in the text1 textbox     *
  251. '***********************************************************
  252.  
  253. 'variable used to store the return value of the function call:
  254. Dim ret As Integer
  255. Dim char As String
  256.  
  257. char = InputBox("Enter character to be found:")
  258.  
  259. 'only one character by be searched!
  260. If Len(char) > 1 Then
  261.   MsgBox "only one character by be searched!", 48, DLG_CAPTION
  262.   Exit Sub
  263. End If
  264. iChar = Asc(char)
  265. 'initialize the variables
  266. lpstrDATA = Space$(65000)
  267. 'when calling dll's, the memory for strings being passed
  268. 'back and forth must be allocated by Visual Basic.
  269. 'this is done simply by filling up the variable with blanks!
  270.  
  271. 'assign the string being searched to the variable:
  272. lpstrDATA = text1.Text
  273.  
  274.  
  275. 'execute the dll function:
  276. ret = FindRightChar(lpstrDATA, iChar)
  277.  
  278. 'the return value stores the position of the last occurence
  279. 'of iChar within lpstrDATA
  280.  
  281. 'if the return value <= 0 then no occurence
  282. If ret <= 0 Then
  283.   MsgBox "Character not found!", 48, DLG_CAPTION
  284. Else
  285.   text1.SelStart = CLng(ret - 1)
  286.   text1.SelLength = CLng(1)
  287.   text1.SetFocus
  288. End If
  289.  
  290.  
  291. End Sub
  292.  
  293. Sub Command3_Click ()
  294. '***********************************************************
  295. '**      SAMPLE CODE FOR THE LexSortStr FUNCTION       **
  296. '***********************************************************
  297. '* sorts a list containing a bunch of strings *
  298. '***********************************************************
  299.  
  300. 'variable used to store the return value of the function call:
  301. Dim ret, a, b, position, exited As Integer
  302.  
  303. Dim iCase As Integer 'Case sensitivity
  304. Dim iNofC As Integer 'Number of Characters to check
  305.  
  306. Dim lpstrSTRING1 As String * 1024
  307. Dim lpstrSTRING2 As String * 1024
  308. 'initialize the variables
  309. 'allocate memory:
  310. lpstrSTRING1 = Space$(1024)
  311. lpstrSTRING1 = Space$(1024)
  312. 'when calling dll's, the memory for strings being passed
  313. 'back and forth must be allocated by Visual Basic.
  314. 'this is done simply by filling up the variable with blanks!
  315.  
  316. 'clear the destination listbox:
  317. list2.Clear
  318. '1=case sensitive comparison, 0=non case sensitive
  319. If casesens.Value Then
  320.   iCase = 1
  321. Else
  322.   iCase = 0
  323. End If
  324.  
  325. 'the number of characters to sort by
  326. iNofC = Val(textnum.Text)
  327. 'add the first entry so we have something to compare with the first string
  328. ' list2.AddItem list1.List(0)
  329.  
  330. For a = 0 To list1.ListCount - 1
  331.   lpstrSTRING1 = list1.List(a)
  332.   b = -1
  333.   Do
  334.     b = b + 1
  335.     lpstrSTRING2 = list2.List(b)
  336.     'execute the dll function:
  337.     ret = LexSortStr(lpstrSTRING1, lpstrSTRING2, iNofC, iCase)
  338.     'the return value shows to following:
  339.     'if ret < 0 : string1 is before string2
  340.     'if ret = 0 : string1 is the same as string2
  341.     'if ret > 0 : string1 is after string2
  342.     If b >= list2.ListCount Then
  343.       list2.AddItem list1.List(a), b
  344.       exited = True
  345.       Exit Do
  346.     End If
  347.   Loop Until ret <= 0
  348.   If exited = False Then
  349.     list2.AddItem list1.List(a), b
  350.   Else
  351.     exited = False
  352.   End If
  353. Next
  354.  
  355. End Sub
  356.  
  357. Sub Command4_Click ()
  358. '***********************************************************
  359. '**      SAMPLE CODE FOR THE FindFirstNIS FUNCTION       **
  360. '**      FindFirstNIS = FindFirst[N]ot[I]n[S]ubstring
  361. '***********************************************************
  362. '*   Searches the first occurence of a character in lpstrDATA *
  363. '*   not contained in the subset string lpstrMAP           *
  364. '*   and highlights the character in the text1 textbox     *
  365. '***********************************************************
  366.  
  367. 'variable used to store the return value of the function call:
  368. Dim ret As Integer
  369. Dim subset As String
  370. Dim lpstrSUBSET As String * 256
  371. 'initialize the variables
  372. 'allocate memory:
  373. lpstrSUBSET = Space$(256)
  374. lpstrDATA = Space$(65000)
  375. 'when calling dll's, the memory for strings being passed
  376. 'back and forth must be allocated by Visual Basic.
  377. 'this is done simply by filling up the variable with blanks!
  378.  
  379. subset = InputBox("Enter character subset:")
  380.  
  381. lpstrSUBSET = subset
  382.  
  383. 'assign the string being searched to the variable:
  384. lpstrDATA = text1.Text
  385.  
  386.  
  387. 'execute the dll function:
  388. ret = FindFirstNIS(lpstrDATA, lpstrSUBSET)
  389.  
  390. 'the return value stores the position of the last occurence
  391. 'of iChar within lpstrDATA
  392.  
  393. 'if the return value <= 0 then no occurence
  394. If ret <= 0 Then
  395.   MsgBox "Subset not contained within searched DATA!", 48, DLG_CAPTION
  396. Else
  397.   text1.SelStart = CLng(ret)
  398.   text1.SelLength = CLng(1)
  399.   text1.SetFocus
  400. End If
  401.  
  402. End Sub
  403.  
  404. Sub Command5_Click ()
  405. '***********************************************************
  406. '**      SAMPLE CODE FOR THE LexSortStr FUNCTION       **
  407. '***********************************************************
  408. '* indicates the lexical order of two strings *
  409. '***********************************************************
  410.  
  411. 'variable used to store the return value of the function call:
  412. Dim ret As Integer
  413.  
  414. Dim iCase As Integer 'Case sensitivity
  415. Dim iNofC As Integer 'Number of Characters to check
  416. Dim lpstrSTRING1 As String * 1024
  417. Dim lpstrSTRING2 As String * 1024
  418. 'initialize the variables
  419. 'allocate memory:
  420. lpstrSTRING1 = Space$(1024)
  421. lpstrSTRING1 = Space$(1024)
  422. 'when calling dll's, the memory for strings being passed
  423. 'back and forth must be allocated by Visual Basic.
  424. 'this is done simply by filling up the variable with blanks!
  425.  
  426. lpstrSTRING1 = InputBox("Enter the first string to compare:")
  427. lpstrSTRING2 = InputBox("Enter the second string to compare:")
  428.  
  429. iCase = 1 '1=case sensitive comparison, 0=non case sensitive
  430. iNofC = 10 'compare the first 10 characters of the string
  431.  
  432. 'execute the dll function:
  433. ret = LexSortStr(lpstrSTRING1, lpstrSTRING2, iNofC, iCase)
  434.  
  435. 'the return value shows to following:
  436. 'if ret < 0 : string1 is before string2
  437. 'if ret = 0 : string1 is the same as string2
  438. 'if ret > 0 : string1 is after string2
  439. Select Case ret
  440. Case Is < 0
  441.   MsgBox "'" + Trim$(lpstrSTRING1) + "' BEFORE '" + Trim$(lpstrSTRING2) + "'", 64, DLG_CAPTION
  442. Case 0
  443.   MsgBox "'" + Trim$(lpstrSTRING1) + "' THE SAME as '" + Trim$(lpstrSTRING2) + "'", 64, DLG_CAPTION
  444. Case Is > 0
  445.   MsgBox "'" + Trim$(lpstrSTRING1) + "' AFTER '" + Trim$(lpstrSTRING2) + "'", 64, DLG_CAPTION
  446. End Select
  447.  
  448.  
  449. End Sub
  450.  
  451. Sub datei_Click (Index As Integer)
  452. Unload form1
  453. End Sub
  454.  
  455. Sub Form_Load ()
  456. Dim fhnd As Integer
  457. Dim dummy As String
  458.  
  459. form1.Left = screen.Width / 2 - form1.Width / 2
  460. form1.Top = screen.Height / 2 - form1.Height / 2
  461.  
  462. label2.Caption = "length:" + Str$(Len(text1.Text)) + " characters"
  463.  
  464. list1.AddItem "this demonstrates"
  465. list1.AddItem "thiS demonstrates"
  466. list1.AddItem "the usE of lexical order"
  467. list1.AddItem "the use of lexical order"
  468. list1.AddItem "string sorting with"
  469. list1.AddItem "string Sorting with"
  470. list1.AddItem "the almighty STRING.DLL"
  471. list1.AddItem "case sensitive"
  472. list1.AddItem "or not; your choice!"
  473.  
  474.  
  475. End Sub
  476.  
  477. Sub info_Click (Index As Integer)
  478. Dim res As Integer
  479.  
  480. Select Case Index
  481. Case 0
  482.   
  483.   res = STRINGVer(form1.hWnd)
  484.  
  485. End Select
  486. End Sub
  487.  
  488.