Visual Basic |
C++ (MFC, RFC) |
Variable
Declarations |
Dim x As Integer
Dim s As String
Dim s1, s2 As String
Dim o 'Implicitly Object
Dim obj As New Object()
Public name As String
|
int x;
CString s;
CString s1, s2;
Object o;
Object* pObj = new Object();
public: // defined in a class declaration
CString name;
|
Statements |
Response.Write("foo") |
Response.Write("foo");
|
Comments |
' This is a comment
' This
' is
' a
' multi-line
' comment |
// This is a comment
/*
This
is
a
multi-line
comment
*/
|
Accessing
Indexed Properties |
Dim s, value As String
s = Request.QueryString("Name")
value = Request.Cookies("Key").Value
'Note that default non-indexed properties
'must be explicitly named in VB |
CString s =
Request.QueryString["Name"];
CString value = Request.Cookies["key"]; |
Arrays |
Dim a(3) As String
a(0) = "1"
a(1) = "2"
a(2) = "3" |
CString a[3];
a[0] = "1";
a[1] = "2";
a[2] = "3"; |
Initialization |
Dim s As String = "Hello
World"
Dim i As Integer = 1
Dim a() As Double = { 3.00, 4.00, 5.00 } |
CString s = "Hello
World";
int i = 1;
double[] a = { 3.00, 4.00, 5.00 };
|
If
Statements |
If Not (Request.QueryString =
Null)
...
End If
|
if (Request.QueryString != NULL)
{
...
}
|
Case
Statements |
Select (index)
case 1 :
...
case 2 :
...
case 3 :
...
End Select
|
switch (index)
{
case 1:
...
break;
case 2:
...
break;
case 3:
...
break;
default:
...
break;
}
|
For
Loops |
Dim I As Integer
For I = 0 To 2
a(I) = "test"
Next |
for (int i=0; i<3; i++)
a(i) = "test"; |
While
Loops |
Dim I As Integer
I = 0
Do While I < 3
' Do something
I = I + 1
Loop |
int i = 0;
while (i<3)
{
// Do Something
i += 1;
} |
String
Concatenation |
Dim s1, s2 As String
s2 = "hello"
s2 &= " world"
s1 = s2 & " !!!" |
CString s1;
CString s2 = "hello";
s2 += " world";
s1 = s2 + " !!!"; |
Event
Handlers |
Sub MyButton_Click()
...
End Sub |
void MyButton_Click()
{
...
} |
Casting |
Dim bj As MyObject
obj = Session("Some Value") |
MyObject* obj =
(MyObject*)Session["Some Value"]; |
Conversion |
Dim i As Integer
Dim s As String
Dim d As Double
i = 3
s = Str(i)
d = CDbl(s)
|
int i = 3;
CString s;s.Format("%d", i);
double d = atol(s); |