home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code2 / string / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1994-07-15  |  15.0 KB  |  422 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         =   "
  129. 1994 by INside; P.O. Box 965; 3000 Bern 9; Switzerland"
  130.       Height          =   195
  131.       Left            =   1920
  132.       TabIndex        =   9
  133.       Top             =   6570
  134.       Width           =   4935
  135.    End
  136.    Begin Label Label2 
  137.       AutoSize        =   -1  'True
  138.       BackStyle       =   0  'Transparent
  139.       Caption         =   "Label2"
  140.       FontBold        =   -1  'True
  141.       FontItalic      =   0   'False
  142.       FontName        =   "MS Sans Serif"
  143.       FontSize        =   9.75
  144.       FontStrikethru  =   0   'False
  145.       FontUnderline   =   0   'False
  146.       Height          =   240
  147.       Left            =   4140
  148.       TabIndex        =   6
  149.       Top             =   90
  150.       Width           =   720
  151.    End
  152.    Begin Label Label1 
  153.       AutoSize        =   -1  'True
  154.       BackStyle       =   0  'Transparent
  155.       Caption         =   "Output text window:"
  156.       FontBold        =   -1  'True
  157.       FontItalic      =   0   'False
  158.       FontName        =   "MS Sans Serif"
  159.       FontSize        =   9.75
  160.       FontStrikethru  =   0   'False
  161.       FontUnderline   =   0   'False
  162.       Height          =   240
  163.       Index           =   1
  164.       Left            =   1950
  165.       TabIndex        =   5
  166.       Top             =   1575
  167.       Width           =   1965
  168.    End
  169.    Begin Label Label1 
  170.       AutoSize        =   -1  'True
  171.       BackStyle       =   0  'Transparent
  172.       Caption         =   "Source text window:"
  173.       FontBold        =   -1  'True
  174.       FontItalic      =   0   'False
  175.       FontName        =   "MS Sans Serif"
  176.       FontSize        =   9.75
  177.       FontStrikethru  =   0   'False
  178.       FontUnderline   =   0   'False
  179.       Height          =   240
  180.       Index           =   0
  181.       Left            =   1965
  182.       TabIndex        =   4
  183.       Top             =   90
  184.       Width           =   2040
  185.    End
  186.    Begin Menu dat 
  187.       Caption         =   "&File"
  188.       Begin Menu datei 
  189.          Caption         =   "&Exit"
  190.          Index           =   0
  191.       End
  192.    End
  193.    Begin Menu in 
  194.       Caption         =   "&?"
  195.       Begin Menu info 
  196.          Caption         =   "&Info"
  197.          Index           =   0
  198.       End
  199.    End
  200. Option Explicit
  201. Sub Command1_Click ()
  202. '***********************************************************
  203. '**      SAMPLE CODE FOR THE ReverseStr FUNCTION       **
  204. '***********************************************************
  205. '*   Reverses the indicated string                         *
  206. '***********************************************************
  207. 'variable used to store the return value of the function call:
  208. Dim ret As Integer
  209. 'variables used to time the function call:
  210. Dim tstart As Long
  211. Dim atRev As Long
  212. 'initialize the variables
  213. lpstrDATA = Space$(65000)
  214. 'when calling dll's, the memory for strings being passed
  215. 'back and forth must be allocated by Visual Basic.
  216. 'this is done simply by filling up the variable with blanks!
  217. 'assign the string to be reversed to the variable:
  218. lpstrDATA = text1.Text
  219. 'get the system tick count as a timer mark:
  220. tstart = GetTickCount()
  221. 'execute the dll function:
  222. ret = ReverseStr(lpstrDATA)
  223. 'get the system tick count as a timer mark:
  224. atRev = GetTickCount()
  225. 'assign the resulting string now stored in lpstrDATA to the
  226. 'textfield:
  227. text2.Text = Trim$(lpstrDATA)
  228. 'please note: all the empty space in a string can easily be eliminated
  229. 'by "trimming" the string variable!
  230. MsgBox "It took me " + Trim$(Str$(atRev - tstart)) + " milliseconds to reverse a string 65000 chars length", 64, DLG_CAPTION
  231. 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
  232. End Sub
  233. Sub Command2_Click ()
  234. '***********************************************************
  235. '**      SAMPLE CODE FOR THE FindRightChar FUNCTION       **
  236. '***********************************************************
  237. '*   Searches the last occurence of iChar within lpstrDATA *
  238. '*   and highlights the character in the text1 textbox     *
  239. '***********************************************************
  240. 'variable used to store the return value of the function call:
  241. Dim ret As Integer
  242. Dim char As String
  243. char = InputBox("Enter character to be found:")
  244. 'only one character by be searched!
  245. If Len(char) > 1 Then
  246.   MsgBox "only one character by be searched!", 48, DLG_CAPTION
  247.   Exit Sub
  248. End If
  249. iChar = Asc(char)
  250. 'initialize the variables
  251. lpstrDATA = Space$(65000)
  252. 'when calling dll's, the memory for strings being passed
  253. 'back and forth must be allocated by Visual Basic.
  254. 'this is done simply by filling up the variable with blanks!
  255. 'assign the string being searched to the variable:
  256. lpstrDATA = text1.Text
  257. 'execute the dll function:
  258. ret = FindRightChar(lpstrDATA, iChar)
  259. 'the return value stores the position of the last occurence
  260. 'of iChar within lpstrDATA
  261. 'if the return value <= 0 then no occurence
  262. If ret <= 0 Then
  263.   MsgBox "Character not found!", 48, DLG_CAPTION
  264.   text1.SelStart = CLng(ret - 1)
  265.   text1.SelLength = CLng(1)
  266.   text1.SetFocus
  267. End If
  268. End Sub
  269. Sub Command3_Click ()
  270. '***********************************************************
  271. '**      SAMPLE CODE FOR THE LexSortStr FUNCTION       **
  272. '***********************************************************
  273. '* sorts a list containing a bunch of strings *
  274. '***********************************************************
  275. 'variable used to store the return value of the function call:
  276. Dim ret, a, b, position, exited As Integer
  277. Dim iCase As Integer 'Case sensitivity
  278. Dim iNofC As Integer 'Number of Characters to check
  279. Dim lpstrSTRING1 As String * 1024
  280. Dim lpstrSTRING2 As String * 1024
  281. 'initialize the variables
  282. 'allocate memory:
  283. lpstrSTRING1 = Space$(1024)
  284. lpstrSTRING1 = Space$(1024)
  285. 'when calling dll's, the memory for strings being passed
  286. 'back and forth must be allocated by Visual Basic.
  287. 'this is done simply by filling up the variable with blanks!
  288. 'clear the destination listbox:
  289. list2.Clear
  290. '1=case sensitive comparison, 0=non case sensitive
  291. If casesens.Value Then
  292.   iCase = 1
  293.   iCase = 0
  294. End If
  295. 'the number of characters to sort by
  296. iNofC = Val(textnum.Text)
  297. 'add the first entry so we have something to compare with the first string
  298. ' list2.AddItem list1.List(0)
  299. For a = 0 To list1.ListCount - 1
  300.   lpstrSTRING1 = list1.List(a)
  301.   b = -1
  302.     b = b + 1
  303.     lpstrSTRING2 = list2.List(b)
  304.     'execute the dll function:
  305.     ret = LexSortStr(lpstrSTRING1, lpstrSTRING2, iNofC, iCase)
  306.     'the return value shows to following:
  307.     'if ret < 0 : string1 is before string2
  308.     'if ret = 0 : string1 is the same as string2
  309.     'if ret > 0 : string1 is after string2
  310.     If b >= list2.ListCount Then
  311.       list2.AddItem list1.List(a), b
  312.       exited = True
  313.       Exit Do
  314.     End If
  315.   Loop Until ret <= 0
  316.   If exited = False Then
  317.     list2.AddItem list1.List(a), b
  318.   Else
  319.     exited = False
  320.   End If
  321. End Sub
  322. Sub Command4_Click ()
  323. '***********************************************************
  324. '**      SAMPLE CODE FOR THE FindFirstNIS FUNCTION       **
  325. '**      FindFirstNIS = FindFirst[N]ot[I]n[S]ubstring
  326. '***********************************************************
  327. '*   Searches the first occurence of a character in lpstrDATA *
  328. '*   not contained in the subset string lpstrMAP           *
  329. '*   and highlights the character in the text1 textbox     *
  330. '***********************************************************
  331. 'variable used to store the return value of the function call:
  332. Dim ret As Integer
  333. Dim subset As String
  334. Dim lpstrSUBSET As String * 256
  335. 'initialize the variables
  336. 'allocate memory:
  337. lpstrSUBSET = Space$(256)
  338. lpstrDATA = Space$(65000)
  339. 'when calling dll's, the memory for strings being passed
  340. 'back and forth must be allocated by Visual Basic.
  341. 'this is done simply by filling up the variable with blanks!
  342. subset = InputBox("Enter character subset:")
  343. lpstrSUBSET = subset
  344. 'assign the string being searched to the variable:
  345. lpstrDATA = text1.Text
  346. 'execute the dll function:
  347. ret = FindFirstNIS(lpstrDATA, lpstrSUBSET)
  348. 'the return value stores the position of the last occurence
  349. 'of iChar within lpstrDATA
  350. 'if the return value <= 0 then no occurence
  351. If ret <= 0 Then
  352.   MsgBox "Subset not contained within searched DATA!", 48, DLG_CAPTION
  353.   text1.SelStart = CLng(ret)
  354.   text1.SelLength = CLng(1)
  355.   text1.SetFocus
  356. End If
  357. End Sub
  358. Sub Command5_Click ()
  359. '***********************************************************
  360. '**      SAMPLE CODE FOR THE LexSortStr FUNCTION       **
  361. '***********************************************************
  362. '* indicates the lexical order of two strings *
  363. '***********************************************************
  364. 'variable used to store the return value of the function call:
  365. Dim ret As Integer
  366. Dim iCase As Integer 'Case sensitivity
  367. Dim iNofC As Integer 'Number of Characters to check
  368. Dim lpstrSTRING1 As String * 1024
  369. Dim lpstrSTRING2 As String * 1024
  370. 'initialize the variables
  371. 'allocate memory:
  372. lpstrSTRING1 = Space$(1024)
  373. lpstrSTRING1 = Space$(1024)
  374. 'when calling dll's, the memory for strings being passed
  375. 'back and forth must be allocated by Visual Basic.
  376. 'this is done simply by filling up the variable with blanks!
  377. lpstrSTRING1 = InputBox("Enter the first string to compare:")
  378. lpstrSTRING2 = InputBox("Enter the second string to compare:")
  379. iCase = 1 '1=case sensitive comparison, 0=non case sensitive
  380. iNofC = 10 'compare the first 10 characters of the string
  381. 'execute the dll function:
  382. ret = LexSortStr(lpstrSTRING1, lpstrSTRING2, iNofC, iCase)
  383. 'the return value shows to following:
  384. 'if ret < 0 : string1 is before string2
  385. 'if ret = 0 : string1 is the same as string2
  386. 'if ret > 0 : string1 is after string2
  387. Select Case ret
  388. Case Is < 0
  389.   MsgBox "'" + Trim$(lpstrSTRING1) + "' BEFORE '" + Trim$(lpstrSTRING2) + "'", 64, DLG_CAPTION
  390. Case 0
  391.   MsgBox "'" + Trim$(lpstrSTRING1) + "' THE SAME as '" + Trim$(lpstrSTRING2) + "'", 64, DLG_CAPTION
  392. Case Is > 0
  393.   MsgBox "'" + Trim$(lpstrSTRING1) + "' AFTER '" + Trim$(lpstrSTRING2) + "'", 64, DLG_CAPTION
  394. End Select
  395. End Sub
  396. Sub datei_Click (Index As Integer)
  397. Unload form1
  398. End Sub
  399. Sub Form_Load ()
  400. Dim fhnd As Integer
  401. Dim dummy As String
  402. form1.Left = screen.Width / 2 - form1.Width / 2
  403. form1.Top = screen.Height / 2 - form1.Height / 2
  404. label2.Caption = "length:" + Str$(Len(text1.Text)) + " characters"
  405. list1.AddItem "this demonstrates"
  406. list1.AddItem "thiS demonstrates"
  407. list1.AddItem "the usE of lexical order"
  408. list1.AddItem "the use of lexical order"
  409. list1.AddItem "string sorting with"
  410. list1.AddItem "string Sorting with"
  411. list1.AddItem "the almighty STRING.DLL"
  412. list1.AddItem "case sensitive"
  413. list1.AddItem "or not; your choice!"
  414. End Sub
  415. Sub info_Click (Index As Integer)
  416. Dim res As Integer
  417. Select Case Index
  418. Case 0
  419.   res = STRINGVer(form1.hWnd)
  420. End Select
  421. End Sub
  422.