关于vb.net的语法格式的信息

VB.NET 写日期到access 格式不对

因为Access日期格式设置了,在写入中会出现格式不对,可以根据情况自定义修改日期格式写入Access中。

创新互联是一家专注网站建设、网络营销策划、小程序定制开发、电子商务建设、网络推广、移动互联开发、研究、服务为一体的技术型公司。公司成立十年以来,已经为成百上千家OPP胶袋各业的企业公司提供互联网服务。现在,服务的成百上千家客户与我们一路同行,见证我们的成长;未来,我们一起分享成功的喜悦。

语法如下:format([日期],"YYYY-MM-DD")

示例:

 Format(#2003/10/1#, "aaaa")     '星期三

 Format(#2003/10/1#, "dddd")    'Wednesday

 Format(#2003/10/1#, "ww")      '40    2003年的第40周

 Format(#2003/10/1#, "mmmm") 'October

 Format(#2003/10/1#, "oooo")    '十月

 Format(#2003/10/1#, "q")     '4   2003年的第4季

日期时间扩展:

(:):  时间分隔符。在一些区域,可能用其他符号来当时间分隔符。格式化时间值时,时间分隔符可以分隔时、分、秒。时间分隔符的真正字符在格式输出时取决于系统的设置。 

(/) :  日期分隔符。在一些区域,可能用其他符号来当日期分隔符。格式化日期数值时,日期分隔符可以分隔年、月、日。日期分隔符的真正字符在格式输出时取决于系统设置。 

c :  以 ddddd 来显示日期并且以 ttttt 来显示时间。如果想显示的数值无小数部分,则只显示日期部分,如果想显示的数值无整数部分,则只显示时间部分。 

d :  以没有前导零的数字来显示日 (1 – 31)。 

dd :  以有前导零的数字来显示日 (01 – 31)。 

ddd :  以简写来表示日 (Sun –Sat)。 

dddd :  以全称来表示日 (Sunday –Saturday)。 

ddddd :  以完整日期表示法显示(包括年、月、日),日期的显示要依系统的短日期格式设置而定。缺省的短日期格式为 m/d/yy。 

dddddd :  以完整日期表示法显示日期系列数(包括年、月、日),日期的显示要依系统识别的长日期格式而定。缺省的长日期格式为 mmmm dd, yyyy。 

aaaa :  与dddd 一样,它只是该字符串的本地化版本。 

w :  将一周中的日期以数值表示(1 表星期日~ 7表星期六)。 

ww :  将一年中的星期以数值表示 (1 – 54)。 

m :  以没有前导零的数字来显示月 (1 – 12)。如果 m 是直接跟在 h 或 hh 之后,那么显示的将是分而不是月。 

mm :  以有前导零的数字来显示月 (01 – 12)。如果m是直接跟在h或hh之后,那么显示的将是分而不是月。 

mmm :  以简写来表示月 (Jan –Dec)。 

mmmm :  以全称来表示月 (January –December)。 

oooo :  与mmmm一样,它只是该字符串的本地化版本。 

q :  将一年中的季以数值表示 (1 – 4)。 

y :  将一年中的日以数值表示 (1 – 366)。 

yy :  以两位数来表示年 (00 – 99)。 

yyyy :  以四位数来表示年 (00 – 99)。 

h :  以没有前导零的数字来显示小时 (0 – 23)。 

Hh :  以有前导零的数字来显示小时 (00– 23)。 

N :  以没有前导零的数字来显示分 (0 – 59)。 

Nn :  以有前导零的数字来显示分 (00 – 59)。

S :  以没有前导零的数字来显示秒 (0 – 59)。 

Ss :  以有前导零的数字来显示秒 (00 – 59)。 

t t t t t :  以完整时间表示法显示(包括时、分、秒),用系统识别的时间格式定义的时间分隔符进行格式化。如果选择有前导零并且时间是在 10:00 A.M. 或 P.M.之前,那么将显示有前导零的时间。缺省的时间格式为 h:mm:ss。 

AM/PM :  在中午前以 12 小时配合大写 AM 符号来使用;在中午和 11:59 P.M.间以 12 小时配合大写 PM 来使用。 

am/pm :  在中午前以 12 小时配合小写 am 符号来使用;在中午和 11:59 P.M.间以 12 小时配合小写 pm 来使用。 

A/P :  在中午前以 12 小时配合大写A符号来使用;在中午和 11:59 P.M.间以12 小时配合大写P来使用。 

a/p :  在中午前以 12 小时配合小写a符号来使用;在中午和 11:59 P.M.间以 12 小时配合小写p来使用。 

AMPM :  在中午前以 12 小时配合系统设置的 AM字符串文字来使用;在中午和 11:59 P.M. 间以 12 小时配合系统设置的 PM 字符串文字来使用。AMPM 可以是大写或小写,但必须和您的系统设置相配。其缺省格式为 AM/PM。 

完整的VB.NET的语法解析程序

  比较长 不过支持全部的关键字 直接就可以用了 using System;using System Text;using System Text RegularExpressions;

namespace Com OSLeague Component{/// summary/// 语法分析器 将所有Code根据语法进行变色/// list type= VB 支持VB NET/list/// list type= CS 支持CS/list/// author掉掉/author/// date 年 月 日/date/// Memo/// 练习正则表达式/// /Memo/// /summarypublic class CodeAnalysis{

////定义HTML开始和结束的语句 用于语法变色//

const string TAG_FNTRED = @ font color= red ;const string TAG_FNTBLUE = @ font color= blue ;const string TAG_FNTGRN = @ font color= green ;const string TAG_FNTMRN = @ font color= maroon ;const string TAG_FNTBLACK = @ font color= black ;const string TAG_EFONT = @ /font ;const string TAG_SPNYELLOW = @ span style= background color: yellow; ;const string TAG_ESPAN = @ /span ;const string TAG_B = @ b ;const string TAG_EB = @ /b ;const string TAG_MENT = @ font colr=# ;const string TAG_EMENT = @ /font ;

//

public CodeAnalysis(){//// TODO: 在此处添加构造函数逻辑//}

/// summary/// 处理VB NET代码 彩色化 /// /summary/// param name= Code 传入的Code/param/// returns处理过后的代码/returnspublic string ParseVB(string Code){////定义VB NET中关键字 将其存为数组//

string[] VB_Keyword = new string[]{ AddHandler AddressOf AndAlso Alias And Ansi As Assembly Auto Boolean ByRef Byte ByVal Call Case Catch CBool CByte CChar CDate CDec CDbl Char CInt Class CLng CObj Const CShort CSng CStr CType Date Decimal Declare Default Delegate Dim DirectCast Do Double Each Else ElseIf End Enum Erase Error Event Exit False Finally For Friend Function Get GetType GoTo Handles If Implements Imports In Inherits Integer Interface Is Let Lib Like Long Loop Me Mod Module MustInherit MustOverride MyBase MyClass Namespace New Next Not Nothing NotInheritable NotOverridable Object On Option Optional Or OrElse Overloads Overridable Overrides ParamArray Preserve Private Property Protected Public RaiseEvent ReadOnly ReDim RemoveHandler Resume Return Select Set Shadows Shared Short Single Static Step Stop String Structure Sub SyncLock Then Throw To True Try TypeOf Unicode Until Variant When While With WithEvents WriteOnly Xor };

////设定转换代码颜色//

lishixinzhi/Article/program/net/201311/14615

VB.NET编程语法

你这是vb.net的代码,vb中不允许那么写:

Dim

strdx()

As

String

=

{"0",

"0",

"0"}

'定义个数组,从后面的值能看的出最大下标是2,也就是strdx(0),strdx(1)和strdx(2),3个的默认值都为0

Dim

calcount1

As

String

=

"0"

'定义个字符串变量

Dim

calcount2

As

String

=

"0"

Dim

strvalue

As

Boolean

=

False

'定义strvalue为bool值,改类型变量只有true和false

2种值

If

strdx(0)

=

"0"

Then

TextBox1.Text

=

strdx(0)

"."

这是字符串连接符号,和"+"的区别是,他把左右2边的内容直接连接的,而"+"可能会编程运算符,例如

2

3

=

"23"

2

+

3

=

5

ElseIf

strvalue

=

False

Then

strdx(0)

=

strdx(0)

"0"

TextBox1.Text

=

strdx(0)

"."

strvalue

=

True

Else

strdx(0)

=

strdx(0)

"0"

TextBox1.Text

=

strdx(0)

Select

Case

calcount1

'

这里开始是分支语句

Case

"+"

TextBox1.Text

=

Str(Val(strdx(1))

+

Val(strdx(0)))

vb.net中如何用事件和委托,会C#中的事件和委托,但不知VB.net中的语法,望给个简单的例子熟悉语法。

一委托:此示例演示如何将方法与委托关联然后通过委托调用该方法。

创建委托和匹配过程

创建一个名为 MySubDelegate 的委托。

Delegate Sub MySubDelegate(ByVal x As Integer)

声明一个类,该类包含与该委托具有相同签名的方法。

Class class1

Sub Sub1(ByVal x As Integer)

MsgBox("The value of x is: " CStr(x))

End Sub

End Class

定义一个方法,该方法创建该委托的实例并通过调用内置的 Invoke 方法调用与该委托关联的方法。

Protected Sub DelegateTest()

Dim c1 As New class1

' Create an instance of the delegate.

Dim msd As MySubDelegate = AddressOf c1.Sub1

' Call the method.

msd.Invoke(10)

End Sub

二、事件

下面的示例程序阐释如何在一个类中引发一个事件,然后在另一个类中处理该事件。AlarmClock 类定义公共事件 Alarm,并提供引发该事件的方法。AlarmEventArgs 类派生自 EventArgs,并定义 Alarm 事件特定的数据。WakeMeUp 类定义处理 Alarm 事件的 AlarmRang 方法。AlarmDriver 类一起使用类,将使用 WakeMeUp 的 AlarmRang 方法设置为处理 AlarmClock 的 Alarm 事件。

该示例程序使用事件和委托和引发事件中详细说明的概念。

示例

' EventSample.vb.

'

Option Explicit

Option Strict

Imports System

Imports System.ComponentModel

Imports Microsoft.VisualBasic

Namespace EventSample

' Class that contains the data for

' the alarm event. Derives from System.EventArgs.

'

Public Class AlarmEventArgs

Inherits EventArgs

Private _snoozePressed As Boolean

Private nrings As Integer

'Constructor.

'

Public Sub New(snoozePressed As Boolean, nrings As Integer)

Me._snoozePressed = snoozePressed

Me.nrings = nrings

End Sub

' The NumRings property returns the number of rings

' that the alarm clock has sounded when the alarm event

' is generated.

'

Public ReadOnly Property NumRings() As Integer

Get

Return nrings

End Get

End Property

' The SnoozePressed property indicates whether the snooze

' button is pressed on the alarm when the alarm event is generated.

'

Public ReadOnly Property SnoozePressed() As Boolean

Get

Return _snoozePressed

End Get

End Property

' The AlarmText property that contains the wake-up message.

'

Public ReadOnly Property AlarmText() As String

Get

If _snoozePressed Then

Return "Wake Up!!! Snooze time is over."

Else

Return "Wake Up!"

End If

End Get

End Property

End Class

' Delegate declaration.

'

Public Delegate Sub AlarmEventHandler(sender As Object, _

e As AlarmEventArgs)

' The Alarm class that raises the alarm event.

'

Public Class AlarmClock

Private _snoozePressed As Boolean = False

Private nrings As Integer = 0

Private stopFlag As Boolean = False

' The Stop property indicates whether the

' alarm should be turned off.

'

Public Property [Stop]() As Boolean

Get

Return stopFlag

End Get

Set

stopFlag = value

End Set

End Property

' The SnoozePressed property indicates whether the snooze

' button is pressed on the alarm when the alarm event is generated.

'

Public Property SnoozePressed() As Boolean

Get

Return _snoozePressed

End Get

Set

_snoozePressed = value

End Set

End Property

' The event member that is of type AlarmEventHandler.

'

Public Event Alarm As AlarmEventHandler

' The protected OnAlarm method raises the event by invoking

' the delegates. The sender is always this, the current instance

' of the class.

'

Protected Overridable Sub OnAlarm(e As AlarmEventArgs)

RaiseEvent Alarm(Me, e)

End Sub

' This alarm clock does not have

' a user interface.

' To simulate the alarm mechanism it has a loop

' that raises the alarm event at every iteration

' with a time delay of 300 milliseconds,

' if snooze is not pressed. If snooze is pressed,

' the time delay is 1000 milliseconds.

'

Public Sub Start()

Do

nrings += 1

If stopFlag Then

Exit Do

Else

If _snoozePressed Then

System.Threading.Thread.Sleep(1000)

If (True) Then

Dim e As New AlarmEventArgs(_snoozePressed, nrings)

OnAlarm(e)

End If

Else

System.Threading.Thread.Sleep(300)

Dim e As New AlarmEventArgs(_snoozePressed, nrings)

OnAlarm(e)

End If

End If

Loop

End Sub

End Class

' The WakeMeUp class has a method AlarmRang that handles the

' alarm event.

'

Public Class WakeMeUp

Public Sub AlarmRang(sender As Object, e As AlarmEventArgs)

Console.WriteLine((e.AlarmText + ControlChars.Cr))

If Not e.SnoozePressed Then

If e.NumRings Mod 10 = 0 Then

Console.WriteLine(" Let alarm ring? Enter Y")

Console.WriteLine(" Press Snooze? Enter N")

Console.WriteLine(" Stop Alarm? Enter Q")

Dim input As String = Console.ReadLine()

If input.Equals("Y") Or input.Equals("y") Then

Return

Else

If input.Equals("N") Or input.Equals("n") Then

CType(sender, AlarmClock).SnoozePressed = True

Return

Else

CType(sender, AlarmClock).Stop = True

Return

End If

End If

End If

Else

Console.WriteLine(" Let alarm ring? Enter Y")

Console.WriteLine(" Stop Alarm? Enter Q")

Dim input As String = Console.ReadLine()

If input.Equals("Y") Or input.Equals("y") Then

Return

Else

CType(sender, AlarmClock).Stop = True

Return

End If

End If

End Sub

End Class

' The driver class that hooks up the event handling method of

' WakeMeUp to the alarm event of an Alarm object using a delegate.

' In a forms-based application, the driver class is the

' form.

'

Public Class AlarmDriver

Public Shared Sub Main()

' Instantiates the event receiver.

Dim w As New WakeMeUp()

' Instantiates the event source.

Dim clock As New AlarmClock()

' Wires the AlarmRang method to the Alarm event.

AddHandler clock.Alarm, AddressOf w.AlarmRang

clock.Start()

End Sub

End Class

End Namespace


网页名称:关于vb.net的语法格式的信息
分享链接:http://ybzwz.com/article/ddosppo.html