Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

发表在 未分类 | 一条评论

utf8 和 UTF-8 有什么区别

“UTF-8”是标准写法,在Windows下边英文不区分大小写,所以也可以写成“utf-8”。“UTF-8”也可以把中间的“-”省略,写成“UTF8”。一般程序都能识别,但也有例外(如下文),为了严格一点,最好用标准的大写“UTF-8”。

在MySQL数据库中只能使用“utf8”

在MySQL的命令模式中只能使用“utf8”,不能使用“utf-8”,也就是说在PHP程序中只能使用“set names utf8(不加小横杠)”,如果你加了“-”此行命令将不会生效,但是在PHP中header时却要加上“-”,因为IE不认识没杠的“utf8”,原因见下文。

在IE浏览器中只能使用“utf-8”

IE中如果使用了“utf8”,页面可能会 空白 或 显示为乱码。

但是在其它浏览器却是正常的,原因是因为:其它浏览器默认使用的是UTF-8的编码,如果无法识别页面的编码就会用默认的UTF-8来解码,但是IE的默认编码是GB2312,所以默认的话就。。。。。(其它浏览器指“FireFox”、“Chrome”、“Opera”)
总结

【只有在MySQL中可以使用“utf-8”的别名“utf8”,但是在其他地方一律使用大写“UTF-8”。】

具体为:

在命令“mysql_query(set names utf8)”外一律用大写“UTF-8”。

<完>

发表在 计算机与 Internet | 一条评论

计算机相关从业人员都能做什么?

(1)你能熟练使用办公软件,如office,excel等等,会一点编程,你最起码可以做一个办公白领;如果气质好可以当高级秘书之类,风光无限,令人羡慕。
(2)你熟悉网络的话,可以做企事业单位的网管、网络维护、建网站等工作。舒舒服服的。
你能熟练使用C++编程,熟悉操作系统,你可以成为专职程序员,熟悉底层软件你还可以成为系统工程师。有点辛苦,但回报颇丰!
(3)你能熟练使用JAVA,可以处理面向对象的企业型的应用开发,公司企业WEB页面设计、INTERNET可视化软件开发及动画等,Web服务器手机上的JAVA游戏开发等等。很时髦的工作,工作时的心情很重要,哈哈!
(4)你若熟悉linux,完全可以在linux世界里自由竞争,你只需要一台电脑,连上internet以及一个好的头脑就足够了。你的linux战友们将会根据你的意见,你的代码和你的其他贡献来判断你的能力,不愁找不到工作,工作会来找你拉!
(5)你能熟练使用protel,可以找排线路板方面的工作,如设计PC机板卡等等。循规蹈矩,安安静静,与世无争,但不能干一辈子吧?
(6)你单片机熟,可以找单片机开发编程应用方面的工作。小企业,小产品多多,其中也自有一番乐趣。
(7)你对DSP有一定基础的话,你可以在人工智能、模式识别、图像处理或者数据采集、神经网络等领域谋求一个职位。将来一准是公司的栋梁之材啊!
(8)你若熟悉ARM,可以成为便携式通信产品、手持运算、多媒体和嵌入式解决方案等领域里的一名产品研发工程师。哈,一个新的IT精英诞生了!
(9)你熟悉EDA,能熟练应用HDL语言,熟悉各种算法,如FIR、FFT、CPU等等,同时掌握最新FPGA/CPLD器件的应用,把研制的自主知识产权的模块用于ASIC。恭喜你,你马上可找到月薪上万的工作了。
计算机,涵盖很广。 包括硬件,软件 软件里还分设计师和程序员等。 总之踏入这个领域才知道多么广泛。 中国现在不是计算机人才过剩,而是缺少好的人才。 中国每年向发达国家支付的知识产权专利费用多少? 中国软件行业为什么大部分只是做低层次的代码加工,而能够进行高层次设计人才就那么少呢?
这绝对是一个值得加入并为之付出努力的行业
发表在 计算机与 Internet | 留下评论

Memcache是什么

Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力。
它可以应对任意多个连接,使用非阻塞的网络IO。由于它的工作机制是在内存中开辟一块空间,然后建立一个HashTable,Memcached自管理这些HashTable。
Memcache官方网站:http://www.danga.com/memcached,更多详细的信息可以来这里了解 

为什么会有Memcache和memcached两种名称?
其实Memcache是这个项目的名称,而memcached是它服务器端的主程序文件名,知道我的意思了把~~~~。一个是项目名称,一个是主程序文件名,在网上看到了很多人不明白,于是混用了。

Memcache的安装
分为两个过程:memcache服务器端的安装和memcached客户端的安装。
所谓服务器端的安装就是在服务器(一般都是linux系统)上安装Memcache实现数据的存储
所谓客户端的安装就是指php(或者其他程序,Memcache还有其他不错的api接口提供)去使用服务器端的Memcache提供的函数,需要php添加扩展。

具体的配置大家可以参考:
Linux下的Memcache安装:http://www.ccvita.com/index.php/257.html
Windows下的Memcache安装:http://www.ccvita.com/index.php/258.html
Memcache基础教程:http://www.ccvita.com/index.php/259.html

PHP的Memcache

< ?php
//连接
$mem = new Memcache;
$mem->connect("192.168.0.200", 12000);

//保存数据
$mem->set(‘key1’, ‘This is first value’, 0, 60);
$val = $mem->get(‘key1’);
echo "Get key1 value: " . $val ."<br />";

//替换数据
$mem->replace(‘key1’, ‘This is replace value’, 0, 60);
$val = $mem->get(‘key1’);
echo "Get key1 value: " . $val . "<br />";

//保存数组
$arr = array(‘aaa’, ‘bbb’, ‘ccc’, ‘ddd’);
$mem->set(‘key2’, $arr, 0, 60);
$val2 = $mem->get(‘key2’);
echo "Get key2 value: ";
print_r($val2);
echo "<br />";

//删除数据
$mem->delete(‘key1’);
$val = $mem->get(‘key1’);
echo "Get key1 value: " . $val . "<br />";

//清除所有数据
$mem->flush();
$val2 = $mem->get(‘key2’);
echo "Get key2 value: ";
print_r($val2);
echo "<br />";

//关闭连接
$mem->close();
?>
如果正常的话,浏览器将输出:
Get key1 value: This is first value
Get key1 value: This is replace value
Get key2 value: Array ( [0] => aaa [1] => bbb [2] => ccc [3] => ddd )
Get key1 value:
Get key2 value:

程序代码分析

初始化一个Memcache的对象:
$mem = new Memcache;

连接到我们的Memcache服务器端,第一个参数是服务器的IP地址,也可以是主机名,第二个参数是Memcache的开放的端口:
$mem->connect("192.168.0.200", 12000);

保存一个数据到Memcache服务器上,第一个参数是数据的key,用来定位一个数据,第二个参数是需要保存的数据内容,这里是一个字符串,第三个参数是一个标记,一般设置为0或者MEMCACHE_COMPRESSED就行了,第四个参数是数据的有效期,就是说数据在这个时间内是有效的,如果过去这个时间,那么会被Memcache服务器端清除掉这个数据,单位是秒,如果设置为0,则是永远有效,我们这里设置了60,就是一分钟有效时间:
$mem->set(‘key1‘, ‘This is first value’, 0, 60);

从Memcache服务器端获取一条数据,它只有一个参数,就是需要获取数据的key,我们这里是上一步设置的key1,现在获取这个数据后输出输出:
$val = $mem->get(’key1′);
echo "Get key1 value: " . $val;

现在是使用replace方法来替换掉上面key1的值,replace方法的参数跟set是一样的,不过第一个参数key1是必须是要替换数据内容的key,最后输出了:
$mem->replace(‘key1′, ‘This is replace value’, 0, 60);
$val = $mem->get(‘key1′);
echo "Get key1 value: " . $val;

同样的,Memcache也是可以保存数组的,下面是在Memcache上面保存了一个数组,然后获取回来并输出
$arr = array(‘aaa’, ‘bbb’, ‘ccc’, ‘ddd’);
$mem->set(‘key2′, $arr, 0, 60);
$val2 = $mem->get(‘key2′);
print_r($val2);

现在删除一个数据,使用delte接口,参数就是一个key,然后就能够把Memcache服务器这个key的数据删除,最后输出的时候没有结果
$mem->delete(‘key1′);
$val = $mem->get(‘key1′);
echo "Get key1 value: " . $val . "<br>";

最后我们把所有的保存在Memcache服务器上的数据都清除,会发现数据都没有了,最后输出key2的数据为空,最后关闭连接
$mem->flush();
$val2 = $mem->get(‘key2′);
echo "Get key2 value: ";
print_r($val2);
echo "<br>";

Memcache的使用
使用Memcache的网站一般流量都是比较大的,为了缓解数据库的压力,让Memcache作为一个缓存区域,把部分信息保存在内存中,在前端能够迅速的进行存取。那么一般的焦点就是集中在如何分担数据库压力和进行分布式,毕竟单台Memcache的内存容量的有限的。我这里简单提出我的个人看法,未经实践,权当参考。

分布式应用
Memcache本来支持分布式,我们客户端稍加改造,更好的支持。我们的key可以适当进行有规律的封装,比如以user为主的网站来说,每个用户都有User ID,那么可以按照固定的ID来进行提取和存取,比如1开头的用户保存在第一台Memcache服务器上,以2开头的用户的数据保存在第二胎Mecache服务器上,存取数据都先按照User ID来进行相应的转换和存取。

但是这个有缺点,就是需要对User ID进行判断,如果业务不一致,或者其他类型的应用,可能不是那么合适,那么可以根据自己的实际业务来进行考虑,或者去想更合适的方法。

减少数据库压力
这个算是比较重要的,所有的数据基本上都是保存在数据库当中的,每次频繁的存取数据库,导致数据库性能极具下降,无法同时服务更多的用户,比如MySQL,特别频繁的锁表,那么让Memcache来分担数据库的压力吧。我们需要一种改动比较小,并且能够不会大规模改变前端的方式来进行改变目前的架构。

我考虑的一种简单方法:
后端的数据库操作模块,把所有的Select操作提取出来(update/delete/insert不管),然后把对应的SQL进行相应的hash算法计算得出一个hash数据key(比如MD5或者SHA),然后把这个key去Memcache中查找数据,如果这个数据不存在,说明还没写入到缓存中,那么从数据库把数据提取出来,一个是数组类格式,然后把数据在set到Memcache中,key就是这个SQL的hash值,然后相应的设置一个失效时间,比如一个小时,那么一个小时中的数据都是从缓存中提取的,有效减少数据库的压力。缺点是数据不实时,当数据做了修改以后,无法实时到前端显示,并且还有可能对内存占用比较大,毕竟每次select出来的数据数量可能比较巨大,这个是需要考虑的因素。

Memcache的安全
我们上面的Memcache服务器端都是直接通过客户端连接后直接操作,没有任何的验证过程,这样如果服务器是直接暴露在互联网上的话是比较危险,轻则数据泄露被其他无关人员查看,重则服务器被入侵,因为Mecache是以root权限运行的,况且里面可能存在一些我们未知的bug或者是缓冲区溢出的情况,这些都是我们未知的,所以危险性是可以预见的。为了安全起见,我做两点建议,能够稍微的防止黑客的入侵或者数据的泄露。

内网访问
最好把两台服务器之间的访问是内网形态的,一般是Web服务器跟Memcache服务器之间。普遍的服务器都是有两块网卡,一块指向互联网,一块指向内网,那么就让Web服务器通过内网的网卡来访问Memcache服务器,我们Memcache的服务器上启动的时候就监听内网的IP地址和端口,内网间的访问能够有效阻止其他非法的访问。
# memcached -d -m 1024 -u root -l 192.168.0.200 -p 11211 -c 1024 -P /tmp/memcached.pid
Memcache服务器端设置监听通过内网的192.168.0.200的ip的11211端口,占用1024MB内存,并且允许最大1024个并发连接

设置防火墙
防火墙是简单有效的方式,如果却是两台服务器都是挂在网的,并且需要通过外网IP来访问Memcache的话,那么可以考虑使用防火墙或者代理程序来过滤非法访问。
一般我们在Linux下可以使用iptables或者FreeBSD下的ipfw来指定一些规则防止一些非法的访问,比如我们可以设置只允许我们的Web服务器来访问我们Memcache服务器,同时阻止其他的访问。
# iptables -F
# iptables -P INPUT DROP
# iptables -A INPUT -p tcp -s 192.168.0.2 –dport 11211 -j ACCEPT
# iptables -A INPUT -p udp -s 192.168.0.2 –dport 11211 -j ACCEPT
上面的iptables规则就是只允许192.168.0.2这台Web服务器对Memcache服务器的访问,能够有效的阻止一些非法访问,相应的也可以增加一些其他的规则来加强安全性,这个可以根据自己的需要来做

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/canduecho/archive/2008/01/31/2074168.aspx

发表在 计算机与 Internet | 留下评论

How to create a setup project for a Windows Service application

发表在 计算机与 Internet | 留下评论

VB.NET and C# Comparison

VB.NET

Program Structure

C#
Imports System

Namespace Hello
   Class HelloWorld
      Overloads Shared Sub Main(ByVal args() As String)
         Dim name As String = "VB.NET"

         ‘See if an argument was passed from the command line
          If args.Length = 1 Then name = args(0)

          Console.WriteLine("Hello, " & name & "!")
      End Sub
   End Class
End Namespace

using System;

namespace Hello {
   public class HelloWorld {
      public static void Main(string[] args) {
         string name = "C#";

         // See if an argument was passed from the command line
         if (args.Length == 1)
            name = args[0];

         Console.WriteLine("Hello, " + name + "!");
      }
   }
}

VB.NET

Comments

C#
‘ Single line only
REM Single line only
”’ <summary>XML comments</summary>

// Single line
/* Multiple
    line  */
/// <summary>XML comments on single line</summary>
/** <summary>XML comments on multiple lines</summary> */

VB.NET

Data Types

C#

Value Types
Boolean
Byte, SByte
Char
Short, UShort, Integer, UInteger, Long, ULong
Single, Double
Decimal
Date

Reference Types
Object
String

Initializing
Dim correct As Boolean = True
Dim b As Byte = &H2A   ‘hex
Dim o As Byte = &O52   ‘octal
Dim person As Object = Nothing
Dim name As String = "Dwight"
Dim grade As Char = "B"c
Dim today As Date = #12/31/2007 12:15:00 PM#
Dim amount As Decimal = 35.99@
Dim gpa As Single = 2.9!
Dim pi As Double = 3.14159265
Dim lTotal As Long = 123456L
Dim sTotal As Short = 123S
Dim usTotal As UShort = 123US
Dim uiTotal As UInteger = 123UI
Dim ulTotal As ULong = 123UL

Type Information
Dim x As Integer
Console.WriteLine(x.GetType())          ‘ Prints System.Int32
Console.WriteLine(GetType(Integer))   ‘ Prints System.Int32
Console.WriteLine(TypeName(x))        ‘ Prints Integer

Type Conversion
Dim d As Single = 3.5
Dim i As Integer = CType(d, Integer)   ‘ set to 4 (Banker’s rounding)
i = CInt(d)  ‘ same result as CType
i = Int(d)    ‘ set to 3 (Int function truncates the decimal)

Value Types
bool
byte, sbyte
char
short, ushort, int, uint, long, ulong
float, double
decimal
DateTime   (not a built-in C# type)

Reference Types
object
string

Initializing
bool correct = true;
byte b = 0x2A;   // hex

object person = null;
string name = "Dwight";
char grade = ‘B’;
DateTime today = DateTime.Parse("12/31/2007 12:15:00");
decimal amount = 35.99m;
float gpa = 2.9f;
double pi = 3.14159265;
long lTotal = 123456L;
short sTotal = 123;
ushort usTotal = 123;
uint uiTotal = 123;
ulong ulTotal = 123;

Type Information
int x;
Console.WriteLine(x.GetType());              // Prints System.Int32
Console.WriteLine(typeof(int));               // Prints System.Int32
Console.WriteLine(x.GetType().Name);   // prints Int32

Type Conversion
float d = 3.5f;
int i = (int)d;   // set to 3  (truncates decimal)

VB.NET

Constants

C#
Const MAX_STUDENTS As Integer = 25

‘ Can set to a const or var; may be initialized in a constructor
ReadOnly MIN_DIAMETER As Single = 4.93

const int MAX_STUDENTS = 25;

// Can set to a const or var; may be initialized in a constructor
readonly float MIN_DIAMETER = 4.93f;

VB.NET

Enumerations

C#
Enum Action
  Start 
  [Stop]   ‘ Stop is a reserved word
  Rewind
  Forward
End Enum

Enum Status
  Flunk = 50
  Pass = 70
  Excel = 90
End Enum

Dim a As Action = Action.Stop
If a <> Action.Start Then _
   Console.WriteLine(a.ToString & " is " & a)     ‘ Prints "Stop is 1"

Console.WriteLine(Status.Pass)     ‘ Prints 70
Console.WriteLine(Status.Pass.ToString())     ‘ Prints Pass

enum Action {Start, Stop, Rewind, Forward};
enum Status {Flunk = 50, Pass = 70, Excel = 90};

Action a = Action.Stop;
if (a != Action.Start)
  Console.WriteLine(a + " is " + (int) a);    // Prints "Stop is 1"

Console.WriteLine((int) Status.Pass);    // Prints 70
Console.WriteLine(Status.Pass);      // Prints Pass

VB.NET

Operators

C#

Comparison
=  <  >  <=  >=  <>

Arithmetic
+  –  *  /
Mod
(integer division)
(raise to a power)

Assignment
=  +=  -=  *=  /=  \=  ^=  <<=  >>=  &=

Bitwise
And   Or   Xor   Not   <<   >>

Logical
AndAlso   OrElse   And   Or   Xor   Not

Note: AndAlso and OrElse perform short-circuit logical evaluations

String Concatenation
&

Comparison
==  <  >  <=  >=  !=

Arithmetic
+  –  *  /
(mod)
(integer division if both operands are ints)
Math.Pow(x, y)

Assignment
=  +=  -=  *=  /=   %=  &=  |=  ^=  <<=  >>=  ++  —

Bitwise
&   |   ^   ~   <<   >>

Logical
&&   ||   &   |   ^   !

Note: && and || perform short-circuit logical evaluations

String Concatenation
+

VB.NET

Choices

C#

greeting = IIf(age < 20, "What’s up?", "Hello")

‘ One line doesn’t require "End If"
If age < 20 Then greeting = "What’s up?"
If age < 20 Then greeting = "What’s up?" Else greeting = "Hello"

‘ Use : to put two commands on same line
If x <> 100 And y < 5 Then x *= 5 : y *= 2  

‘ Preferred
If x <> 100 And y < 5 Then
  x *= 5
  y *= 2
End If

‘ To break up any long single line use _
If whenYouHaveAReally < longLine And _
  itNeedsToBeBrokenInto2 > Lines Then _
  UseTheUnderscore(charToBreakItUp)

If x > 5 Then
  x *= y
ElseIf x = 5 Then
  x += y
ElseIf x < 10 Then
  x -= y
Else
  x /= y
End If

Select Case color   ‘ Must be a primitive data type
  Case "pink", "red"
    r += 1
  Case "blue"
    b += 1
  Case "green"
    g += 1
  Case Else
    other += 1
End Select

greeting = age < 20 ? "What’s up?" : "Hello";

if (age < 20)
  greeting = "What’s up?";
else
  greeting = "Hello";

// Multiple statements must be enclosed in {}
if (x != 100 && y < 5) {   
  x *= 5;
  y *= 2;
}

No need for _ or : since ; is used to terminate each statement.


if
(x > 5)
  x *= y;
else if (x == 5)
  x += y;
else if (x < 10)
  x -= y;
else
  x /= y;

// Every case must end with break or goto case
switch (color) {                          // Must be integer or string
  case "pink":
  case "red":    r++;    break;
  case "blue":   b++;   break;
  case "green": g++;   break;
  default:    other++;   break;       // break necessary on default
}

VB.NET

Loops

C#
Pre-test Loops:

While c < 10
  c += 1
End While

Do Until c = 10 
  c += 1
Loop

Do While c < 10
  c += 1
Loop

For c = 2 To 10 Step 2
  Console.WriteLine(c)
Next


Post-test Loops:

Do 
  c += 1
Loop While c < 10

Do 
  c += 1
Loop Until c = 10

‘  Array or collection looping
Dim names As String() = {"Fred", "Sue", "Barney"}
For Each s As String In names
  Console.WriteLine(s)
Next

‘ Breaking out of loops
Dim i As Integer = 0
While (True)
  If (i = 5) Then Exit While
  i += 1
End While

‘ Continue to next iteration
For i = 0 To 4
  If i < 4 Then Continue For
  Console.WriteLine(i)   ‘ Only prints 4
Next

Pre-test Loops:  

// no "until" keyword
while (c < 10)
  c++;

for (c = 2; c <= 10; c += 2)
  Console.WriteLine(c);

Post-test Loop:

do
  c++;
while (c < 10);

// Array or collection looping
string[] names = {"Fred", "Sue", "Barney"};
foreach (string s in names)
  Console.WriteLine(s);

// Breaking out of loops
int i = 0;
while (true) {
  if (i == 5)
    break;
  i++;
}

// Continue to next iteration
for (i = 0; i < 5; i++) {
  if (i < 4)
    continue;
  Console.WriteLine(i);   // Only prints 4
}

VB.NET

Arrays

C#

Dim nums() As Integer = {1, 2, 3} 
For i As Integer = 0 To nums.Length – 1
  Console.WriteLine(nums(i))
Next

‘ 4 is the index of the last element, so it holds 5 elements
Dim names(4) As String
names(0) = "David"
names(5) = "Bobby"  ‘ Throws System.IndexOutOfRangeException

‘ Resize the array, keeping the existing values (Preserve is optional)
ReDim Preserve names(6)

Dim twoD(rows-1, cols-1) As Single
twoD(2, 0) = 4.5

Dim jagged()() As Integer = { _
  New Integer(4) {}, New Integer(1) {}, New Integer(2) {} }
jagged(0)(4) = 5

int[] nums = {1, 2, 3};
for (int i = 0; i < nums.Length; i++)
  Console.WriteLine(nums[i]);

// 5 is the size of the array
string[] names = new string[5];
names[0] = "David";
names[5] = "Bobby";   // Throws System.IndexOutOfRangeException

// C# can’t dynamically resize an array.  Just copy into new array.
string[] names2 = new string[7];
Array.Copy(names, names2, names.Length);   // or names.CopyTo(names2, 0); 

float[,] twoD = new float[rows, cols];
twoD[2,0] = 4.5f; 

int[][] jagged = new int[3][] {
  new int[5], new int[2], new int[3] };
jagged[0][4] = 5;

VB.NET

Functions

C#

‘ Pass by value (in, default), reference (in/out), and reference (out) 
Sub TestFunc(ByVal x As Integer, ByRef y As Integer, ByRef z As Integer)
  x += 1
  y += 1
  z = 5
End Sub

Dim a = 1, b = 1, c As Integer   ‘ c set to zero by default 
TestFunc(a, b, c)
Console.WriteLine("{0} {1} {2}", a, b, c)   ‘ 1 2 5

‘ Accept variable number of arguments
Function Sum(ByVal ParamArray nums As Integer()) As Integer
  Sum = 0 
  For Each i As Integer In nums
    Sum += i
  Next
End Function   ‘ Or use Return statement like C#

Dim total As Integer = Sum(4, 3, 2, 1)   ‘ returns 10

‘ Optional parameters must be listed last and must have a default value
Sub SayHello(ByVal name As String, Optional ByVal prefix As String = "")
  Console.WriteLine("Greetings, " & prefix & " " & name)
End Sub

SayHello("Strangelove", "Dr.")
SayHello("Madonna")

// Pass by value (in, default), reference (in/out), and reference (out)
void TestFunc(int x, ref int y, out int z) {
  x++;  
  y++;
  z = 5;
}

int a = 1, b = 1, c;  // c doesn’t need initializing
TestFunc(a, ref b, out c);
Console.WriteLine("{0} {1} {2}", a, b, c);  // 1 2 5

// Accept variable number of arguments
int Sum(params int[] nums) {
  int sum = 0;
  foreach (int i in nums)
    sum += i;
  return sum;
}

int total = Sum(4, 3, 2, 1);   // returns 10

/* C# doesn’t support optional arguments/parameters.  Just create two different versions of the same function. */ 
void SayHello(string name, string prefix) {
  Console.WriteLine("Greetings, " + prefix + " " + name);

void SayHello(string name) {
  SayHello(name, "");
}

VB.NET

Strings

C#

Special character constants
vbCrLf, vbCr, vbLf, vbNewLine
vbNullString
vbTab
vbBack
vbFormFeed
vbVerticalTab
""

‘ String concatenation (use & or +)
Dim school As String = "Harding" & vbTab
school = school & "University" ‘ school is "Harding (tab) University"

‘ Chars
Dim letter As Char = school.Chars(0)   ‘ letter is H
letter = Convert.ToChar(65)                ‘ letter is A
letter = Chr(65)                                 ‘ same thing
Dim word() As Char = school.ToCharArray() ‘ word holds Harding

‘ No string literal operator 
Dim msg As String = "File is c:\temp\x.dat" 

‘ String comparison
Dim mascot As String = "Bisons"
If (mascot = "Bisons") Then   ‘ true
If (mascot.Equals("Bisons")) Then   ‘ true
If (mascot.ToUpper().Equals("BISONS")) Then  ‘ true
If (mascot.CompareTo("Bisons") = 0) Then   ‘ true

Console.WriteLine(mascot.Substring(2, 3)) ‘ Prints "son"

‘ String matching
If ("John 3:16" Like "Jo[Hh]? #:*") Then   ‘true

Imports System.Text.RegularExpressions   ‘ More powerful than Like
Dim r As New Regex("Jo[hH]. \d:*")
If (r.Match("John 3:16").Success) Then   ‘true

‘ My birthday: Oct 12, 1973
Dim dt As New DateTime(1973, 10, 12)
Dim s As String = "My birthday: " & dt.ToString("MMM dd, yyyy")

‘ Mutable string
Dim buffer As New System.Text.StringBuilder("two ")
buffer.Append("three ")
buffer.Insert(0, "one ")
buffer.Replace("two", "TWO")
Console.WriteLine(buffer)         ‘ Prints "one TWO three"

Escape sequences
\r    // carriage-return
\n    // line-feed
\t    // tab
\\    // backslash
\"    // quote

// String concatenation
string school = "Harding\t";
school = school + "University";   // school is "Harding (tab) University"

// Chars
char letter = school[0];            // letter is H
letter = Convert.ToChar(65);     // letter is A
letter = (char)65;                    // same thing
char[] word = school.ToCharArray();   // word holds Harding

// String literal
string msg = @"File is c:\temp\x.dat";
// same as
string msg = "File is c:\\temp\\x.dat";

// String comparison
string mascot = "Bisons";
if (mascot == "Bisons")    // true
if (mascot.Equals("Bisons"))   // true
if (mascot.ToUpper().Equals("BISONS"))   // true
if (mascot.CompareTo("Bisons") == 0)    // true

Console.WriteLine(mascot.Substring(2, 3));    // Prints "son"

// String matching
// No Like equivalent – use regular expressions

using System.Text.RegularExpressions;
Regex r = new Regex(@"Jo[hH]. \d:*");
if (r.Match("John 3:16").Success)   // true

// My birthday: Oct 12, 1973
DateTime dt = new DateTime(1973, 10, 12);
string s = "My birthday: " + dt.ToString("MMM dd, yyyy");

// Mutable string
System.Text.StringBuilder buffer = new System.Text.StringBuilder("two ");
buffer.Append("three ");
buffer.Insert(0, "one ");
buffer.Replace("two", "TWO");
Console.WriteLine(buffer);     // Prints "one TWO three"

VB.NET

Exception Handling

C#

‘ Throw an exception
Dim ex As New Exception("Something is really wrong.")
Throw  ex 

‘ Catch an exception
Try 
  y = 0
  x = 10 / y
Catch ex As Exception When y = 0 ‘ Argument and When is optional
  Console.WriteLine(ex.Message)
Finally
  Beep()
End Try

‘ Deprecated unstructured error handling
On Error GoTo MyErrorHandler

MyErrorHandler: Console.WriteLine(Err.Description)

// Throw an exception
Exception up = new Exception("Something is really wrong.");
throw up;  // ha ha

// Catch an exception
try
  y = 0;
  x = 10 / y;
}
catch (Exception ex) {   // Argument is optional, no "When" keyword 
  Console.WriteLine(ex.Message);
}
finally {
  // Requires reference to the Microsoft.VisualBasic.dll
  // assembly (pre .NET Framework v2.0)

  Microsoft.VisualBasic.Interaction.Beep();
}

VB.NET

Namespaces

C#

Namespace Harding.Compsci.Graphics 
  …
End Namespace

‘ or

Namespace Harding
  Namespace Compsci
    Namespace Graphics 
      …
    End Namespace
  End Namespace
End Namespace

Imports Harding.Compsci.Graphics

namespace Harding.Compsci.Graphics {
  …
}

// or

namespace Harding {
  namespace Compsci {
    namespace Graphics {
      …
    }
  }
}

using Harding.Compsci.Graphics;

VB.NET

Classes / Interfaces

C#

Accessibility keywords
Public
Private
Friend                   
Protected
Protected Friend
Shared

‘ Inheritance
Class FootballGame
  Inherits Competition
  …
End Class 

‘ Interface definition
Interface IAlarmClock 
  …
End Interface

// Extending an interface 
Interface IAlarmClock
  Inherits IClock
  …
End Interface

// Interface implementation
Class WristWatch 
  Implements IAlarmClock, ITimer 
   …
End Class 

Accessibility keywords
public
private
internal
protected
protected internal
static

// Inheritance
class FootballGame : Competition {
  …
}


// Interface definition

interface IAlarmClock {
  …
}

// Extending an interface 
interface IAlarmClock : IClock {
  …
}


// Interface implementation

class WristWatch : IAlarmClock, ITimer {
   …
}

VB.NET

Constructors / Destructors

C#
Class SuperHero
  Private _powerLevel As Integer

  Public Sub New()
    _powerLevel = 0
  End Sub

  Public Sub New(ByVal powerLevel As Integer)
    Me._powerLevel = powerLevel
  End Sub

  Protected Overrides Sub Finalize() 
   ‘ Desctructor code to free unmanaged resources
    MyBase.Finalize()
  End Sub
End Class

class SuperHero {
  private int _powerLevel;

  public SuperHero() {
     _powerLevel = 0;
  }

  public SuperHero(int powerLevel) {
    this._powerLevel= powerLevel; 
  }

  ~SuperHero() {
    // Destructor code to free unmanaged resources.
    // Implicitly creates a Finalize method

  }
}

VB.NET

Using Objects

C#

Dim hero As SuperHero = New SuperHero
‘ or
Dim hero As New SuperHero

With hero
  .Name = "SpamMan"
  .PowerLevel = 3
End With

hero.Defend("Laura Jones")
hero.Rest()     ‘ Calling Shared method
‘ or
SuperHero.Rest()

Dim hero2 As SuperHero = hero  ‘ Both reference the same object
hero2.Name = "WormWoman"
Console.WriteLine(hero.Name)   ‘ Prints WormWoman

hero = Nothing    ‘ Free the object

If hero Is Nothing Then _
  hero = New SuperHero

Dim obj As Object = New SuperHero
If TypeOf obj Is SuperHero Then _
  Console.WriteLine("Is a SuperHero object.")

‘ Mark object for quick disposal
Using reader As StreamReader = File.OpenText("test.txt")
  Dim line As String = reader.ReadLine()
  While Not line Is Nothing
    Console.WriteLine(line)
    line = reader.ReadLine()
  End While
End Using

SuperHero hero = new SuperHero();

// No "With" construct
hero.Name = "SpamMan";
hero.PowerLevel = 3;

hero.Defend("Laura Jones");
SuperHero.Rest();   // Calling static method

SuperHero hero2 = hero;   // Both reference the same object
hero2.Name = "WormWoman";
Console.WriteLine(hero.Name);   // Prints WormWoman

hero = null ;   // Free the object

if (hero == null)
  hero = new SuperHero();

Object obj = new SuperHero(); 
if (obj is SuperHero)
  Console.WriteLine("Is a SuperHero object."); // Mark object for quick disposal
using (StreamReader reader = File.OpenText("test.txt")) {
  string line;
  while ((line = reader.ReadLine()) != null)
    Console.WriteLine(line);
}

VB.NET

Structs

C#

Structure StudentRecord
  Public name As String
  Public gpa As Single

  Public Sub New(ByVal name As String, ByVal gpa As Single)
    Me.name = name
    Me.gpa = gpa
  End Sub
End Structure

Dim stu As StudentRecord = New StudentRecord("Bob", 3.5)
Dim stu2 As StudentRecord = stu  

stu2.name = "Sue"
Console.WriteLine(stu.name)    ‘ Prints Bob
Console.WriteLine(stu2.name)  ‘ Prints Sue

struct StudentRecord {
  public string name;
  public float gpa;

  public StudentRecord(string name, float gpa) {
    this.name = name;
    this.gpa = gpa;
  }
}

StudentRecord stu = new StudentRecord("Bob", 3.5f);
StudentRecord stu2 = stu;  

stu2.name = "Sue";
Console.WriteLine(stu.name);    // Prints Bob
Console.WriteLine(stu2.name);   // Prints Sue

VB.NET

Properties

C#

Private _size As Integer

Public Property Size() As Integer
  Get
    Return _size
  End Get
  Set (ByVal Value As Integer)
    If Value < 0 Then
      _size = 0
    Else
      _size = Value
    End If
  End Set
End Property

foo.Size += 1

private int _size;

public int Size {
  get {
    return _size;
  }
  set {
    if (value < 0)
      _size = 0;
    else
      _size = value;
  }
}

foo.Size++;

VB.NET

Delegates / Events

C#

Delegate Sub MsgArrivedEventHandler(ByVal message As String)

Event MsgArrivedEvent As MsgArrivedEventHandler

‘ or to define an event which declares a delegate implicitly
Event MsgArrivedEvent(ByVal message As String)

AddHandler MsgArrivedEvent, AddressOf My_MsgArrivedCallback
‘ Won’t throw an exception if obj is Nothing
RaiseEvent MsgArrivedEvent("Test message")
RemoveHandler MsgArrivedEvent, AddressOf My_MsgArrivedCallback

Imports System.Windows.Forms

Dim WithEvents MyButton As Button   ‘ WithEvents can’t be used on local variable
MyButton = New Button

Private Sub MyButton_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyButton.Click
  MessageBox.Show(Me, "Button was clicked", "Info", _
    MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

delegate void MsgArrivedEventHandler(string message);

event MsgArrivedEventHandler MsgArrivedEvent;

// Delegates must be used with events in C#

MsgArrivedEvent += new MsgArrivedEventHandler(My_MsgArrivedEventCallback);
MsgArrivedEvent("Test message");    // Throws exception if obj is null
MsgArrivedEvent -= new MsgArrivedEventHandler(My_MsgArrivedEventCallback);

using System.Windows.Forms;

Button MyButton = new Button(); 
MyButton.Click += new System.EventHandler(MyButton_Click);

private void MyButton_Click(object sender, System.EventArgs e) {
  MessageBox.Show(this, "Button was clicked", "Info",
    MessageBoxButtons.OK, MessageBoxIcon.Information);
}

VB.NET

Console I/O

C#

Console.Write("What’s your name? ")
Dim name As String = Console.ReadLine()
Console.Write("How old are you? ")
Dim age As Integer = Val(Console.ReadLine())
Console.WriteLine("{0} is {1} years old.", name, age) 
‘ or
Console.WriteLine(name & " is " & age & " years old.")

Dim c As Integer
c = Console.Read()    ‘ Read single char
Console.WriteLine(c)   ‘ Prints 65 if user enters "A"

Console.Write("What’s your name? ");
string name = Console.ReadLine();
Console.Write("How old are you? ");
int age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("{0} is {1} years old.", name, age);
// or
Console.WriteLine(name + " is " + age + " years old.");

int c = Console.Read();  // Read single char
Console.WriteLine(c);    // Prints 65 if user enters "A"

VB.NET

File I/O

C#

Imports System.IO

‘ Write out to text file
Dim writer As StreamWriter = File.CreateText("c:\myfile.txt")
writer.WriteLine("Out to file.")
writer.Close()

‘ Read all lines from text file
Dim reader As StreamReader = File.OpenText("c:\myfile.txt")
Dim line As String = reader.ReadLine()
While Not line Is Nothing
  Console.WriteLine(line)
  line = reader.ReadLine()
End While
reader.Close()

‘ Write out to binary file
Dim str As String = "Text data"
Dim num As Integer = 123
Dim binWriter As New BinaryWriter(File.OpenWrite("c:\myfile.dat")) 
binWriter.Write(str) 
binWriter.Write(num) 
binWriter.Close()

‘ Read from binary file
Dim binReader As New BinaryReader(File.OpenRead("c:\myfile.dat"))
str = binReader.ReadString()
num = binReader.ReadInt32()
binReader.Close()

using System.IO;

// Write out to text file
StreamWriter writer = File.CreateText("c:\\myfile.txt");
writer.WriteLine("Out to file.");
writer.Close();

// Read all lines from text file
StreamReader reader = File.OpenText("c:\\myfile.txt");
string line = reader.ReadLine();
while (line != null) {
  Console.WriteLine(line);
  line = reader.ReadLine();
}
reader.Close();

// Write out to binary file
string str = "Text data";
int num = 123;
BinaryWriter binWriter = new BinaryWriter(File.OpenWrite("c:\\myfile.dat"));
binWriter.Write(str);
binWriter.Write(num);
binWriter.Close();

// Read from binary file
BinaryReader binReader = new BinaryReader(File.OpenRead("c:\\myfile.dat"));
str = binReader.ReadString();
num = binReader.ReadInt32();
binReader.Close();

发表在 计算机与 Internet | 留下评论

AppLocale之烦恼

今天在单位安装一个日文软件的时候,居然出现了日文乱码的情况,很是令人费解,日文安装日文居然乱码?
仔细想想,今天是第三次遇到这个问题了,只是以前没有注意罢了,看来欠下的帐早晚是要还的啊,决定牺牲一下宝贵的睡眠时间来研究一下原因,呵呵
可怜我的新本本,成了这次的试验品,罪过!!!
报告如下:
前言:
在使用日文系统的时候,如果想用中文软件的话,一般都会选择AppLocale,
AppLocale是微软的工具, 可以为非Unicode应用软件转换临时的系统区域语言,也就是所谓的内码转换,
 但是在日文系统里使用之后, 会令某些日文的setup,MSI形式的安装程序显示乱码(例如: OFFICE2003).
分析:
刚开始怀疑是系统区域语言设置的问题,但是试验了一下,发现思路不对,不是所有的都这样,那就只能找找别的问题了,回想着三次的共同之处,就想到了可爱的AppLocale,上网艘了一下确实如此。
解决方法:
方法一: 卸载AppLocale即可解决;
    卸载这个软件比较困难,关联的进程较多,建议用工具卸载
方法二: 删除AppLocale安装目录下的AppLoc.tmp文件, 无需卸载AppLocale;
    此方法不能长久,只要使用AppLocale以后还会出现
方法三: AppLocale刚安装好的时候, 是没有AppLoc.tmp这个文件的. 自己在AppLocale的安装目录内, 新建一个AppLoc.tmp文件, 并把它设为只读属性,。
   这三个方法对已经安装的软件没有任何效果,我也没找到更有效的办法,只能卸载后重新安装,
文件夹选项中的乱码:
  这里的乱码一般是因为你安装了乱码的Offices软件导致的,重新安装即可解决。
最后的建议:
  如果你的反D版情节不是很重的话,建议用虚拟机,装一个中文的系统,一了百了 哈哈
发表在 计算机与 Internet | 留下评论

不能打开文件*.chm文件

不能打开文件*.chm文件
提示“不能打开文件:mk:@…………”
总结:
1、协议问题
是“regsvr32 /u %windir%\system32\itss.dll”卸载了its协议,没有此协议CHM帮助文件打不开,需要重新加载一下,命令如下:regsvr32 %windir%\system32\itss.dll 如果显示注册成功就行了!
2、关联问题
winxp中系统打开我的电脑,点工具(win98点查看),点文件夹选项,找到CHM项      
  点高级,点编辑项,看用于操作的应用程序是不是:     "C:\WINDOWS\hh.exe     "     %1      
  不是就改过来吧(win98操作类似)
3、语言问题
在控制面板中修改一下语言设置
发表在 计算机与 Internet | 留下评论

[转]ado如何取得表的所有字段信息

ado如何取得表的所有字段信息?  
   
 方法一:(无需编程)  
     
   工具   ->   分析   ->   文档管理器  

 方法二:  
   
  function   GetFieldDescription()  
          Dim   MyTableName   As   String  
          Dim   MyFieldName   As   String  
           
           
          Dim   MyDB   As   New   ADOX.Catalog  
          Dim   MyTable   As   ADOX.Table  
          Dim   MyField   As   ADOX.Column  
          Dim   pro  
           
           
          On   Error   GoTo   Err_GetFieldDescription  
           
          MyDB.ActiveConnection   =   CurrentProject.Connection  
           
                 
          For   Each   MyTable   In   MyDB.Tables  
                  For   Each   MyField   In   MyTable.Columns  
                          Debug.Print   "FieldName:"   &   FieldType(MyField.Type)   &   "     FieldSize:"   &   MyField.DefinedSize               ‘FieldType(pro.Type)  
                          For   Each   pro   In   MyField.Properties  
                                  Debug.Print   MyTable.Name   &   "   :   "   &   MyField.Name   &   "   :   "   &   pro.Name   &   "   :   "   &   pro.Value  
                          Next  
                  Next  
          Next  
           
           
           
          Set   MyDB   =   Nothing  
   
  Bye_GetFieldDescription:  
          Exit   Function  
   
  Err_GetFieldDescription:  
          Beep  
          MsgBox   Err.Description,   vbExclamation  
          GetFieldDescription   =   Null  
          Resume   Bye_GetFieldDescription  
   
  End   Function  
   
   
  Function   FieldType(n   As   Long)   As   String  
          Dim   p   As   String  
           
          Select   Case   n  
                  ‘case常量   值   说明  
                  ‘Case   0x2000  
                  ‘       p   =   AdArray           ‘(不适用于   ADOX。)   0x2000             一个标志值,通常与另一个数据类型常量组合,指示该数据类型的数组。  
                  Case   20  
                          p   =   "adBigInt       20   指示一个八字节的有符号整数   (DBTYPE_I8)。"  
                  Case   128  
                          p   =   "adBinary       128   指示一个二进制值   (DBTYPE_BYTES)。"  
                  Case   11  
                          p   =   "adBoolean     指示一个布尔值   (DBTYPE_BOOL)。"  
                  Case   8  
                          p   =   "adBSTR     8   指示以   Null   终止的字符串   (Unicode)   (DBTYPE_BSTR)。"  
                  Case   136  
                          p   =   "adChapter     136   指示一个四字节的子集值,标识子行集合中的行   (DBTYPE_HCHAPTER)。"  
                  Case   129  
                          p   =   "adChar129   指示一个字符串值   (DBTYPE_STR)。"  
                  Case   6  
                          p   =   "adCurrency   6   指示一个货币值   (DBTYPE_CY)。货币是一个定点数字,小数点右侧有四位数字。该值存储为八字节、范围为   10,000   的有符号整数。"  
                  Case   7  
                          p   =   "adDate   7   指示日期值   (DBTYPE_DATE)。日期保存为双精度数,数字的整数部分是从   1899   年   12   月   30   日算起的天数,小数部分是一天当中的片段时间。"  
                  Case   133  
                          p   =   "adDBDate   133   指示日期值   (yyyymmdd)   (DBTYPE_DBDATE)。"  
                  Case   134  
                          p   =   "adDBTime   134   指示时间值   (hhmmss)   (DBTYPE_DBTIME)。"  
                  Case   135  
                          p   =   "adDBTimeStamp   135   指示日期/时间戳(yyyymmddhhmmss   加十亿分之一的小数)(DBTYPE_DBTIMESTAMP)。"  
                  Case   14  
                          p   =   "adDecimal   14   指示具有固定精度和范围的确切数字值   (DBTYPE_DECIMAL)。"  
                  Case   5  
                          p   =   "adDouble   5   指示一个双精度浮点值   (DBTYPE_R8)。"  
                  Case   0  
                          p   =   "adEmpty   0   指定没有值   (DBTYPE_EMPTY)。"  
                  Case   10  
                          p   =   "adError   10   指示一个   32   位的错误代码   (DBTYPE_ERROR)。"  
                  Case   64  
                          p   =   "adFileTime   64   指示一个   64   位的值,表示从   1601   年   1   月   1   日开始的   100   个十亿分之一秒间隔的数量   (DBTYPE_FILETIME)。"  
                  Case   72  
                          p   =   "adGUID   72   指示全局唯一标识符   (GUID)   (DBTYPE_GUID)。"  
                  Case   9  
                          p   =   "adIDispatch   9   指示指向   COM   对象上   IDispatch   接口的指针   (DBTYPE_IDISPATCH)。"  
                  ‘注意       ADO   目前不支持这种数据类型。使用它可能导致不可预料的结果。  
                  Case   3  
                          p   =   "   adInteger   3   指示一个四字节的有符号整数   (DBTYPE_I4)。"  
                  Case   13  
                          p   =   "adIUnknown     13   指示指向   COM   对象上   IUnknown   接口的指针   (DBTYPE_IUNKNOWN)。"   ‘注意       ADO   目前不支持这种数据类型。使用它可能导致不可预料的结果。  
                  Case   205  
                          p   =   "adLongVarBinary   205   指示一个长二进制值(仅限于   Parameter   对象)。"  
                  Case   201  
                          p   =   "   adLongVarChar   201   指示一个长字符串值(仅限于   Parameter   对象)。"  
                  Case   203  
                          p   =   "adLongVarWChar   203   指示一个以   Null   终止的长   Unicode   字符串值(仅限于   Parameter   对象)。"  
                  Case   131  
                          p   =   "adNumeric   131   指示具有固定精度和范围的确切数字值   (DBTYPE_NUMERIC)。"  
                  Case   138  
                          p   =   "adPropVariant   138   指示一个   Automation   PROPVARIANT   (DBTYPE_PROP_VARIANT)。"  
                  Case   4  
                          p   =   "adSingle   4   指示一个单精度浮点值   (DBTYPE_R4)。"  
                  Case   2  
                          p   =   "adSmallInt   2   指示一个双字节的有符号整数   (DBTYPE_I2)。"  
                  Case   16  
                          p   =   "adTinyInt   16   指示一个单字节的有符号整数   (DBTYPE_I1)。"  
                  Case   21  
                          p   =   "   adUnsignedBigInt   21   指示一个八字节的无符号整数   (DBTYPE_UI8)。"  
                  Case   19  
                          p   =   "adUnsignedInt   19   指示一个四字节的无符号整数   (DBTYPE_UI4)。"  
                  Case   18  
                          p   =   "adUnsignedSmallInt   18   指示一个双字节的无符号整数   (DBTYPE_UI2)。"  
                  Case   17  
                          p   =   "adUnsignedTinyInt   17   指示一个单字节的无符号整数   (DBTYPE_UI1)。"  
                  Case   132  
                          p   =   "adUserDefined   132   指示一个用户定义的变量   (DBTYPE_UDT)。"  
                  Case   204  
                          p   =   "adVarBinary   204   指示一个二进制值(仅限于   Parameter   对象)。"  
                  Case   200  
                          p   =   "adVarChar   200   指示一个字符串值(仅限于   Parameter   对象)。"  
                  Case   12  
                          p   =   "adVariant   12   指示一个   Automation   Variant   (DBTYPE_VARIANT)。"   ‘注意       ADO   目前不支持这种数据类型。使用它可能导致不可预料的结果。  
                  Case   139  
                          p   =   "adVarNumeric   139   指示一个数字值(仅限于   Parameter   对象)。"  
                  Case   202  
                          p   =   "adVarWChar   202   指示一个以   Null   终止的   Unicode   字符串(仅限于   Parameter   对象)。"  
                  Case   130  
                          p   =   "adWChar   130   指示一个以   Null   终止的   Unicode   字符串   (DBTYPE_WSTR)。"  
          End   Select  
           
           
           
          FieldType   =   p  
   
  End   Function  
     
   
   
   
  asp的代码如下,你只要懂得原来用dim   …   as   声明的,现在要用   server.createobject   就可以了  
   
  <!–#include   file="../Adovbs.inc"–>  
  <!–#include   file="../conn.asp"–>  
  <!–#include   file="../s_inc.asp"–>  
  <!–#include   file="../md5.asp"–>  
  <%  
          Dim   MyTableName    
          Dim   MyFieldName    
           
          Dim   MyDB  
          set   mydb=server.createobject("adox.catalog")  
          Dim   MyTable  
          set   mytable=server.createobject("adox.table")  
          Dim   MyField    
          set   myfield   =server.createobject("adox.column")  
          Dim   pro  
           
          On   Error   resume   next  
           
          MyDB.ActiveConnection   =conn  
          ‘adodb.connection   怎么做出来的我就不用写了吧?如果这也不会建议你先  
          ‘去看看DVBBS的免费论坛代码吧  
                 
          For   Each   MyTable   In   MyDB.Tables  
                  For   Each   MyField   In   MyTable.Columns  
                          response.write   "FieldName:"   &   FieldType(MyField.Type)   &   "     FieldSize:"   &   MyField.DefinedSize               ‘FieldType(pro.Type)  
                          For   Each   pro   In   MyField.Properties  
                                  response.write   MyTable.Name   &   "   :   "   &   MyField.Name   &   "   :   "   &   pro.Name   &   "   :   "   &   pro.Value  
                          Next  
                  Next  
          Next  
  %>    
   
   
   
   
     
   
     
   
   
方法三:  
   
  应网友要求,再提供   DAO   的相关代码:  
  Function   DisplayFieldInfor_DAO()  
  ‘请先引用   DAO   3.6  
  ‘本函数调用   DAO   列出数据库中所有表的所有字段的所有属性的值  
   
          Dim   tdf   As   DAO.TableDef  
          Dim   fld   As   DAO.Field  
          Dim   p   As   DAO.Property  
          For   Each   tdf   In   CurrentDb.TableDefs  
                  For   Each   fld   In   tdf.Fields  
                          For   Each   p   In   fld.Properties  
                                  On   Error   Resume   Next  
                                  Debug.Print   "表名:"   &   tdf.Name   &   _  
                                                          ";   字段名:"   &   fld.Name   &   _  
                                                          ";   属性名:"   &   p.Name   &   _  
                                                          ";   属性值:"   &   p.Value  
                          Next  
                  Next  
          Next  
  End   Function

发表在 VBA | 留下评论

[转]取得access表的属性

首先添加引用   Project-Reference-Microsoft   DAO   3.6   Object   Library  
   
  Function   AppendCaption()  
      Dim   TestDB   As   Database   ‘需打开的数据库  
          Dim   Tbf         As   DAO.TableDef  
          Dim   fld         As   DAO.Field  
          Dim   P             As   DAO.Property  
          Dim   cp           As   DAO.Property  
           
          On   Error   Resume   Next  
          Dim   i   As   Integer  
           
          Dim   TableName   As   String  
          Dim   FieldName   As   String  
          FieldName   =   "Content"’需取得属性的字段名  
          TableName   =   "AgeType"’需取得字段的表名  
   
            ‘打开数据库  
          Set   TestDB   =   DBEngine(0).OpenDatabase("D:\测试新.mdb")   ‘   修改需打开的数据库名称  
          For   Each   Tbf   In   TestDB.TableDefs  
              If   Tbf.Name   =   TableName   Then’判断表名  
                  For   Each   P   In   Tbf.Properties  
                      If   P.Name   =   "Description"   Then  
                            Debug.Print   P.Name   &   "-"   &   P.Value’取得属性中的说明内容  
                      End   If  
                  Next  
              End   if  
          Next  
  End   Function  
另外,如需取得表中对应字段的说明内容,则增加循环:  
          For   Each   Tbf   In   TestDB.TableDefs  
                  For   Each   fld   In   Tbf.Fields                          
                      If   fld.Name   =   FieldName   And   Tbf.Name   =   TableName   Then’取得表中对应的字段  
                          Set   cp   =   fld.CreateProperty("Caption",   12,   "aa")  
                          fld.Properties.Append   cp  
                          Set   cp   =   fld.CreateProperty("Description",   10,   "aa")   ‘更改显示的Title  
                          fld.Properties.Append   cp  
                      End   If  
                      For   Each   P   In   fld.Properties  
                          If   P.Name   =   "Description"   Then  
                                Debug.Print   Tbf.Name   &   ":"   &   fld.Name   &   ":"   &   "pro:";   P.Name   &   "–"   &   P.Value’列出字段的说明属性  
                          End   If  
                    Next  
              Next  
          Next  
   
  以上代码都已调试通过了

发表在 VBA | 留下评论