Porting ASP code to VB COM components (2)

Source: Internet
Author: User
Tags comment tag
When you write ASP code that can save time, there's a lot to do if you want to migrate code. Follow these steps and you will
There's no trouble finding porting code.

Declaring variable types

The biggest disadvantage of Visual Basic and VBScript is that it allows developers to use variables without declaring them. If you think it's a good thing,
So when you're looking for the whole evening to look for a logic mistake caused by a small typo, you don't think about it anymore. If you use
"Option Explicit" (explicit option) to enforce a clear declaration, the IDE warns of this.

<%@ language=vbscript% >
<% Option Explicit% >

When you use Option Explicit, remember that it is just below @ declarations. Not noticing this would lead to a little
Error message.

Microsoft VBScript compilation error ' 800a0400 '

Expected statement

/test.asp, line 4

Option Explicit

^

Now the challenge is here. VBScript allows a variable to be any data type, as long as it is variant. That means that you can only put variables
Declared as variants. This is very wasteful in many ways, but it can be accepted in ASP. But in Visual Basic, when the
When you may create more efficient code, the variable is defined as a type. This program is simple, just add "as" after the declaration
[Data_type] ", then it is no longer a simple variant.

For example, now there is a variable that is a string. Open an ASP page and type "Dim strsession as String". And then
Preview this page and you'll get a little surprise.

Microsoft VBScript compilation error ' 800a0401 '

Expected end of statement

/icu/temp.asp, Line 3

Dim Strsession as String

---------------^

So how do you prepare a variable for visual Basic that does not pose a threat to ASP code? I'm not sure how to evaluate this. Yes
One way is to use a comment tag after a variable declaration. Note that this is helpful not only when porting code to VB,
Companies that offer high-paying digging when you go, it also helps others understand your code. The following is a note mark in ASP version 2
Three ways to declare variables:

Private strstring ' as String
Dim Intinteger ' as Integer
Public Bolboolean ' as Boolean

This type of data definition technique also applies to any function you use in an ASP application. (see some of the subroutines and functions below).

Private Function (strstring, Intinteger) ' as Boolean '

When I typed my ASP code, I ran through the annotations. This may not suit you, maybe you're dealing with some old code,
After porting your code, you can use the search and replace features of visual Basic to increase the data type. This makes more sense, because
You cannot annotate variables in functions and subroutines. The more code is programmed, the less the variable data type annotation is.

For more information about Visual Basic data types, see the MSDN Online article about data types.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.