Advertisement
ASP_Volume3 String Manipulation #44469

Compression, uncompression using RLE-algorithm

Compresses strings, most effective on bitmap files

AI

Yapay Zeka Özeti: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kaynak Kod
original-source
'Copyright 1997 Jouni vuorio
public function compress()
On Error Resume Next
For TT = 1 To Len(Text1)
sana1 = Mid(Text1, TT, 1)
sana2 = Mid(Text1, TT + 1, 1)
sana3 = Mid(Text1, TT + 2, 1)
X = 1
If Not sana1 = sana2 Then löyty = 2
If sana1 = sana2 Then
If sana1 = sana3 Then
löyty = 1
End If
End If

If löyty = 1 Then
alku:
X = X + 1
merkki = Mid(Text1, TT + X + 1, 1)
If merkki = sana1 Then GoTo alku
sana = Chr(255) & Chr(X - 1) & sana1
TT = TT + X
End If
If löyty = 2 Then sana = sana1
Text = Text & sana
Next
Text1 = Text
end function
public function uncompress()
On Error Resume Next
For TT = 1 To Len(Text1)
sana1 = Asc(Mid(Text1, TT, 1))
sana2 = Asc(Mid(Text1, TT + 1, 1))
sana3 = Asc(Mid(Text1, TT + 2, 1))
sana4 = Asc(Mid(Text1, TT - 1, 1))
If sana1 = 255 Then
For TT6 = 1 To sana2
sana = sana & Chr(sana3)
Next
sana1 = ""
sana2 = ""
End If
If sana = "" Then
If Not sana4 = 255 Then
sana = Chr(sana1)
End If
End If
Text = Text & sana
sana = ""
Next

Text1 = Text
end function
'comments to jouni.vuorio@vtoy.fi

<font color="#000000" face="Comic Sans MS" size="2">
<BR>PHP is a server side scripting language that makes it easy to create dynamic websites.
<BR>The code is similar to Java and C++ so if you know one or both of these languages you should be able to pick up PHP fairly easily.
<BR>
<BR>To use PHP you must either upload your site to a server that supports PHP or set up your own server. Unless you have a fast internet connection uploading your files for testing all the time will most likely not be a very good option for you. A good option is to have your own server on your local workstation. The best way to do this would be to use Windows 2000 or XP with Internet Information Services installed. You can then download the PHP engine and install it on your computer. This will allow you to test your pages quickly. However there are other ways of doing this such as the Apache sever.
<BR>
<BR>PHP is an embedded language. This means that you can embed code within a HTML document. There are a few ways in which this can be done:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>&lt;? echo ”Test Message”; ?&gt;
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>This is the most common way of embedding code, but it may cause problems if your code must co-exist with XML. 
<BR>
<BR>Another common way to embed is:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>&lt;?PHP echo ”Test Message”; ?&gt;
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>I recommend using this method for embedding for compatibility with other systems.
<BR>
<BR>There are two other alternate methods but these two aren’t used very often:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>&lt;% echo ”Test Message”; %&gt;
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>By default this method is turned off, and I do not recommend using it.
<BR>
<BR>The final way is similar to putting JavaScript in your page:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>&lt;SCRIPT LANGUAGE=”php”&gt;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo ”TestMessage”;
<BR>&lt;/SCRIPT&gt;
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>Every file you create that contains PHP code you must make sure the extension is the PHP extension set on your server. I usually just use .php, but some people say that you should use the PHP version .php3 or .php4. I have never had any problems but there may be some issues with other servers which is why I still mentioned it.
<BR>
<BR>As I mentioned earlier PHP’s syntax comes from languages like C++. This means that you can use: // /* */ and even # for comments. Also the structure of things like for loops are similar, but variables in PHP are different.
<BR>All variables have a $ sign at the start and is followed by an alphabetic or underscore character. No data type declarations are necessary and you do not have to initialise the variables:
</FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>&lt;? 
<BR>$name;
<BR>$name=”John”;
<BR>echo “My name is $name”;
<BR>?&gt;
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>OUTPUT:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;My name is John
<BR>
<BR>Notice how I can just put the variable name inside the output string. 
<BR>Double quotes will be checked for variables and escape sequences.
<BR>If you do not want this to happen you would use single quotes:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>&lt;? 
<BR>$name;
<BR>$name=”John”;
<BR>echo ‘My name is $name’;
<BR>?&gt;
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>OUTPUT:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;My name is $name
<BR>
<BR>If you do wish to specify the data type for a variable you can use type casting:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>$number = (int) = “342asd”;
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>This will create an integer value of 342.
<BR>The types PHP supports are as follows:
<BR>
<BR>(int), (integer)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;– Cast to integer
<BR>(real), (double), (float)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;– Cast to float
<BR>(string)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;– Cast to string
<BR>(array)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Cast to array
<BR>(object)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Cast to object
<BR>
<BR>
<BR>Selection is something that is very important to know for every language. Selection in PHP is very similar to C++ and Java. We will fist start with the If statement:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>if(expression){
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statements
<BR>}
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>This is a basic If statement. It is a bit hard to understand this way because we have nothing to test for so I will expand and put some sample data in.
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>if($name == “John”){
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo “John is the creator of this tut”;
<BR>}
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>Now with this data in it will say if the value in $name is equal to the string “John” then do the code within the braces.
<BR>We can then further expand on this to do something else if the value is not true:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>if($name == “John”) {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo “John is the creator of this tut”;
<BR>} else {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo “$name is not the creator of this tut”;
<BR>}
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>This code will do the same as previous but it will now output the second echo statement if it is not true.
<BR>Say the value of $name is “Bob”. It will go through and say is $name the same as “John”. No its not so we will go to else and output “Bob is not the creator of this tut”.
<BR>Getting confused? I hope not because we are going to expand on this code again and test for a second name.
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>if($name == “John”){
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo “John is the creator of this tut”;
<BR>} else if($name == “Bob”){
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo “I don’t know any Bob”;
<BR>} else {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo “$name is not the creator of this tut”;
<BR>}
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>This code again does the same as previous but it will test for two conditions.
<BR>Say the value of $name is still “Bob”. It will look at the first condition. Is the value in $name the same as “John”? No, So go to the next if. Is the value in $name the same as “Bob”? Yes, output “I don’t know any Bob”.
<BR>You can keep expanding on this testing for as many conditions as you wish.
<BR>
<BR>Just a note if you have only one line after you if statement you don’t have to have braces:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>if($name == “John”)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo “John is the creator of this tut”;
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>But if you want two or more statements you must have braces. I just find it easier to use braces all the time.
<BR>
<BR>Also you may be wondering why I am using “==”. Well if you think to where you assign a value:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>$name = “John”;
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>That is how you assign a value, so if you had:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>if($name = “John”)
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>You would be trying to assign a value and you would receive an error.
<BR>Other comparisons you can do are things like &&, ||, >, <
<BR>I will explain the Boolean operators in a later tutorial.
<BR>
<BR>The next selection statement is the Switch. The basic syntax is as follows:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>switch(expression) {
<BR>case expression:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statements
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>default:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statements
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>}
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>Again this is a bit hard to follow so I will put some meaningful code in to help:
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>switch($name) {
<BR>case “John”:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo “John is the creator of this tut”
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>default:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statements
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>}
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>This will basically do the same sort of thing as an if statement. If the value in $name is “John” then output “John is the creator of this tut”. If not then go to the next case, in this example the next case is the “default:”. This acts in a similar way to “else” in an if statement. 
<BR>Also just like if statements you can expand and test for more values. To do this all you need to do is to add in more case statements.
<BR></FONT><font color="#0000CD" face="Comic Sans MS" size="2">
<BR>switch($name) {
<BR>case “John”:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo “John is the creator of this tut”
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>case “Bob”:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo “I don’t know Bob”
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>default:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statements
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
<BR>}
<BR></Font><font color="#000000" face="Comic Sans MS" size="2">
<BR>
<BR>That concludes my first PHP Tutorial.
Check out my <a href="http://www.jcroucher.com">site</a> for more tutorials and code.
<BR>
</Font>
Module Module1
  Public Sub AutoComplete(ByVal cbo As ComboBox, ByVal e As System.Windows.Forms.KeyEventArgs)
    'call this from your form passing in the name of your combobox and the event arg:
    '  AutoComplete(cboState, e)
    Dim iIndex As Integer
    Dim sActual As String
    Dim sFound As String
    Dim bMatchFound As Boolean
    'if backspace then remove the last character that was typed in and try to find a match.
    'note that the selected text from the last character typed in to the end of the combo text field will also be deleted.
    If e.KeyCode = Keys.Back Then
      cbo.Text = Mid(cbo.Text, 1, Len(cbo.Text) - 1)
    End If
    ' Do nothing for some keys such as navigation keys.
    If ((e.KeyCode = Keys.Left) Or _
      (e.KeyCode = Keys.Right) Or _
      (e.KeyCode = Keys.Up) Or _
      (e.KeyCode = Keys.Down) Or _
      (e.KeyCode = Keys.PageUp) Or _
      (e.KeyCode = Keys.PageDown) Or _
      (e.KeyCode = Keys.Home) Or _
      (e.KeyCode = Keys.End)) Then
      Return
    End If
    Do
      ' Store the actual text that has been typed.
      sActual = cbo.Text
      ' Find the first match for the typed value.
      iIndex = cbo.FindString(sActual)
      ' Get the text of the first match.
      'if index > -1 then a match was found.
      If (iIndex > -1) Then
        sFound = cbo.Items(iIndex).ToString()
        ' Select this item from the list.
        cbo.SelectedIndex = iIndex
        ' Select the portion of the text that was automatically
        ' added so that additional typing will replace it.
        cbo.SelectionStart = sActual.Length
        cbo.SelectionLength = sFound.Length
        bMatchFound = True
      Else
        'if there isn't a match and the text typed in is only 1 character or nothing then just select the first
        'entry in the combo box.
        If sActual.Length = 1 Or sActual.Length = 0 Then
          cbo.SelectedIndex = 0
          cbo.SelectionStart = 0
          cbo.SelectionLength = Len(cbo.Text)
          bMatchFound = True
        Else
          'if there isn't a match for the text typed in then remove the last character of the text typed in
          'and try to find a match.
          cbo.SelectionStart = sActual.Length - 1
          cbo.SelectionLength = sActual.Length - 1
          cbo.Text = Mid(cbo.Text, 1, Len(cbo.Text) - 1)
        End If
      End If
    Loop Until bMatchFound
  End Sub
End Module
Orijinal Yorumlar (3)
Wayback Machine'den kurtarıldı