Table of Contents

VB BRIDGE FUNCTIONS

VB Bridge has the following functions.

Detect the User Request

VB Bridge contains a function, which allows it to detect the type of form sent to it by IIS. This function is controlled by the VB_Bridge_RequestMethod variable.

There are three possible VB_Bridge_RequestMethod variables. These are POST, GET and NONE. Use whichever is appropriate to any given program.

Getting the User IP

VB Bridge can return the user IP address. The IP address is set to the following variable; vb_bridge_LocalIP.

Getting the Remote User Name

When a remote user logs onto the server using Directory Permissions, the user name is set to the variable, vb_bridge_remote_user.

File Uploading

File uploading makes it possible for end-users to send files from their computer through a browser to the server. File size is unlimited.

To allow end-users to upload files to the server, you need to include the following source code in your html.

ENCTYPE="multipart/form-data"...
INPUT TYPE="FILE"...

This is supported by Netscape 2.0 and Internet Explorer 3.0 or higher. The browser will read the input type FILE and place a BROWSE button next to the input field on the browser. This allows the end-user to easily select the appropriate file.

The following is an example for HTML form:

<FORM ENCTYPE="multipart/form-data" METHOD="POST" ACTION="scripts/vb_bridge2.dll">
<INPUT TYPE="FILE" NAME="ATTACH" SIZE=40>
</FORM>

In the following sample source code, the program copies the uploaded file from the temporary directory where the file was stored by the server (c:/temp/filename.ext), renames and saves it in an Inetpub directory. Then the program detects the format type and sends the renamed file back to the browser.


Sub Program_Main()
  SetServerAdminiEmail ("support@pspinc.com")
  Dim UploadFile As String
  UploadFile = GetField("upload")

  Expr = Right(UploadFile, 4)
  NowDate = Format(Date, "MMDDYY")
  NowTime = Format(Time, "HHMMSS")
  NewFile = "c:\inetpub\wwwroot\vbbridge\demo\upload\" + NowDate + NowTime + Expr
  FileCopy UploadFile, NewFile
  Dim ConType
  If Expr = ".txt" Then
      ConType = "text/plain"
  ElseIf Expr = ".doc" Then
    ConType = "application/msword"
  ElseIf Expr = ".xls" Then
    ConType = "text/tab-separated-values"
  ElseIf Expr = ".gif" Then
    ConType = "image/gif"
  ElseIf Expr = ".jpg" Then
    ConType = "image/jpeg"
  ElseIf Expr = ".htm" Then
    ConType = "text/html"
  End If
  Send ("" + Chr(13) + Chr(10) + Chr(13) + Chr(10))
  SendFile (NewFile)
  Kill UploadFile
  ReturnToISAPI (1)

End Sub

Returning HTML to the Client

VB Bridge includes a function that makes it easy to generate HTML code. This function, Send (html), is used as shown below.

Send ("<Content-Type: text/html>" + Chr(13) + Chr(10) + Chr(13) + Chr(10))
Send ("<HTML>" + Chr(13) + Chr(10))
Send ("<BODY>")
Send ("<HEAD><TITLE>THIS IS A TEST.</TITLE></HEAD>" + Chr(13) + Chr(10))
Send ("<P>THIS IS A TEST.</P>")
Send ("</BODY>" + Chr$(13) + Chr$(10))
Send ("</HTML>" + Chr$(13) + Chr$(10))

Note: (Chr(13) + Chr(10) add a carriage return or and a line feed (CR,LF) at the end of each line.)

SendFile

SendFile allows your program to grab an HTML file, pull out each line and send them to the browser.

To send a file include this code in your program:

Send ("<Contend-Type: text/html"> + Chr(13) + Chr(10)+ Chr(13) + Chr(10))
SendFile (c:\directory\path\sent.htm")

The example code below sends an html file to a frame. In this example, the frame contains a gif advertising an upcoming event.

The Frames Delimiter:

<HTML>
<HEAD>
<TITLE>VB Bridge - for Visual Basic Web Development</TITLE>
</HEAD>
<FRAMESET cols="*,165" FRAMEBORDER=0 borderwidth=0 border=0 noresize fromespacing=0>
<FRAME SRC="body.htm">
<FRAME SRC="/scripts/vb_bridge2.dll?VBEXE=c:\inetpub\scripts\vb_bridge2\rightbanner.exe">
</FRAMESET>
</BODY></HTML>

The Visual Basic source code:

Sub Program_Main ()
SetServerAdminiEmail ("greg@pspinc.com")
Send ("Contend-Type: text/html" + Chr(13) + Chr(10) + Chr(13) + Chr(10))
SendFile ("c:\inetpub\wwwroot\vbbridge\banner.htm")
ReturnToISAPI (1)
End Sub

The banner.htm file that is being sent by the rightbanner.exe:

<HTML>
<BODY bgcolor="#FFFFFF" Text="#0000AA">
<img src="graphics/comdex97.gif" alt="COMDEX 97">
</BODY></HTML>

Details on Passing Data From HTML Forms

It is convenient to set the variables to receive the field defined in the HTML within the Visual BASIC programs. You can use Global Variable As String and define this variable in Sub Program_Main ( ) within the program. It must be defined as String the data type passed from VB_Bridge.

The actual receiving of the data is handled by the line of code, Variable = GetField(Form_Field_Name). For example, if the form <INPUT TYPE="TEXT" NAME="TEL" SIZE=10 VALUE=""> is defined in an HTML file, the data entered into this field by the user will be read by Visual BASIC as follows.

TEL = GetField(PHONE)

This statement inserts the value that the user inputs into the PHONE field in the browser into the TEL variable in the Visual BASIC program that you have created.

When checkboxes are used in a form within an HTML file, the following line is used to receive the data: Variable = GetCheckBoxField(Form_Field_Name, int(n)). With checkboxes, there can be multiple data in one field, so it is necessary to use (n) to number each one. When a field contains no data, a null ("", chr(0)) is returned.

' GetCheckBoxField Sample Code
C = 0
Do While CheckedItems <> Chr(0)
C = C + 1
CheckedItems = GetCheckBoxField("CHECKED", Int(C))
Print #outFile, "<P>"
Print #outFile, CheckedItems
Print #outFile, "<P>"
Loop

Returning Control to IIS

ReturnToISAPI is a function that returns control to IIS when the Visual BASIC program has finished running. ReturnToISAPI (1) uses MIME Control-Types to tell IIS what type of data your application is sending. The SendFile section of this manual is an example of the text/html Content-Type. Here is an example of sending a JPEG formated file.

Sub Program_Main()
SetServerAdminiEmail (<"greg@pspinc.com">)
Send (<"Content-Type: image/jpeg"> + Chr$(13) +Chr$(10) + Chr$(13) + Chr$(10))
SendFile (<"c:\inetpub\wwwroot\vbbridge\photo.jpg">)
ReturnToISAPI (1)
End Sub

Whether you are sending an HTML file, URL or HTML directly from the program, "text/html" is the Content-Type you must use. Not all browsers support all MIME types. Some of the MIME types available are listed below.

text/plain
text/html
text/richtext
text/enriched
text/tab-seperated-values
text/sgml
image/gif
image/jpeg
image/x-xbitmap
image/x-pict
image/tiff
audio/basic
audio/x-wav
video/mpeg
video/quicktime
video/x-msvideo
applications/octet-stream
application/postscript
application/atomicmail
application/andrew-inset
application/atomicmail
application/andrew-inset
application/rtf
application/applefile
application/mac-binhex40
application/news-message-id
application/news-transmission
application/wordperfect5.1
application/pdf
application/zip
application/macwriteii
application/msword
application/mathematica
application/cybercash
application/sgml
multipart/x-www-form-urlendcoded
multipart/mixed
multipart/x-mixed-replace
multipart/form-data

ReturnToISAPI (2) is used to send a URL to the browser. Sometimes it is more appropriate to send a URL than to send files or HTML. In these cases, ReturnToISAPI (2) should be used.

When Visual BASIC Program Errors Occur

Using this function, you can set an e-mail address which will be displayed in the browser window along with any error message that may appear as a result of an error in your Visual BASIC application.

SetServerAdminiEmail (email_address)

Example: SetServerAminiEmail (support@pspinc.com)