![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Advanced Visual Basic Techniques
Next the function uses ConvertToken to turn the \; combinations back into semi-colons. It uses UnprotectChar to convert plus signs into spaces and asterisks into carriage returns. UnprotectChar reverses the effects of subroutine ProtectChar. Finally, RemoveSegment returns the resulting string.
Public Function RemoveSegment(txt As String) As String
Dim pos As Integer
Dim txt_len As Integer
Dim token As String
Find the first semi-colon not after \.
txt_len = Len(txt)
pos = 1
Do
pos = InStr(pos, txt, ;)
If its not found, use all of txt.
If pos = 0 Then
pos = txt_len + 1
Exit Do
End If
If the 1st character is ;, the
segment is blank.
If pos = 1 Then Exit Do
If the previous character is not \,
this is a segment delimiter.
If Mid$(txt, pos - 1, 1) <> \ Then Exit Do
Look for the next ;.
pos = pos + 1
Loop
Break the token off.
token = Left$(txt, pos - 1)
If pos > txt_len Then
txt =
Else
txt = Right$(txt, txt_len - pos)
End If
Restore hidden semi-colons.
ConvertToken token, \;, ;
Restore hidden spaces.
UnprotectChar token, +,
Restore hidden carriage returns.
UnprotectChar token, *, vbCrLf
Return the result.
RemoveSegment = token
End Function
UnprotectChar UnprotectChar reverses the effects of subroutine ProtectChar. For example, it converts the substring \+ into a plus sign and other plus signs into spaces. UnprotectChar uses InStr to locate the first occurrence of the character with the back slash (\+). Because it has found the first occurrence, any occurrence of the character (plus) within the first part of the string should be converted into the other character (space). The program uses ConvertToken to make that substitution. It then adds the first character (plus) without the slash and looks for more instances. For example, consider the case of converting plus signs into spaces and suppose the data contains the following text: She+sells+sea\+shells+down+by+the+sea\+shore The first occurrence of \+ lies just before the word shells. That means any plus signs before that point should be converted into spaces. After making these substitutions and adding the plus character without a slash, the output string is: She sells sea+ The program searches for the next occurrence of \+ in the input text and repeats the substitution process to get: She sells sea+shells down by the sea+ The routine finds no more \+ substrings so the final result is: She sells sea+shells down by the sea+shore The following code shows subroutine UnprotectChar in its entirety:
Public Sub UnprotectChar(txt As String, fr_ch As String, _
to_ch As String)
Dim fr_str As String
Dim new_txt As String
Dim old_pos As Integer
Dim new_pos As Integer
Dim token As String
Dim fr_len As Integer
Dim txt_len As Integer
fr_str = \ & fr_ch
fr_len = Len(fr_str)
txt_len = Len(txt)
new_txt =
old_pos = 1
Do
Find the next \fr_ch.
new_pos = InStr(old_pos, txt, fr_str)
If new_pos < 1 Then new_pos = txt_len + 1
Convert fr_ch into to_ch in this part.
token = Mid$(txt, old_pos, new_pos - old_pos)
ConvertToken token, fr_ch, to_ch
Add the result to the new string.
new_txt = new_txt & token
If were beyond the end, were done.
If new_pos > txt_len Then Exit Do
Add the fr_ch.
new_txt = new_txt & fr_ch
Move beyond the \fr_ch.
old_pos = new_pos + fr_len
Loop
txt = new_txt
End Sub
SummaryMicrosofts Internet Transfer Control allows a Web page to retrieve or execute a file on a remote server. The InetXfer ActiveX control uses the Internet Transfer Control to send data to a remote program. InetXfer takes care of the special processing needed to keep the data safe during transit. ProgramSaveData.EXE, running on the server computer, unpacks the data sent by InetXferand appends it to a file. The WebSurvey application was kept simple intentionally so it would be easy to concentrate on the new tasks of sending and receiving data across a network. This application could be extended to provide much more elaborate surveys or other programs that would allow a Web user to interact with a program running on a remote server.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.
|