资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

关于vb.net代码编写模式的信息

vb.net vs2008中,如何把常用代码编写成一个模块,然后在不同的窗体中调用?

我的思路是,新建一个“类库”项目,在项目里编写一个类,然后生成,就会得到dll文件。在别的项目里,添加对这个dll文件的引用,就可以使用我们编写的类了。

创新互联服务项目包括济源网站建设、济源网站制作、济源网页制作以及济源网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,济源网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到济源省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

vb.net属于什么编程模式

Net 是一个编程框架。

与函数库不同,编程框架指的是一种更高层的抽象,它使使用它的开发人员可以在不用掌握太多基础编程理论时(当然最好是懂一些)就可以开发产品。.Net Framework 的意义是指 .Net 框架。.NET Framework 是可以用来开发应用软件与托管类库的一个平台;它为你提供在生成、调试以及执行托管应用程序时所需要的编译器及工具。可以说 .NET Framework 为你提供了在 Windows 上开发和运行托管应用程序所需的一切条件。因此 .Net 框架也是一种高层次的抽象,它是一种全面支持以面向对象编程的编程方式来进行开发的运行于 Windows NT 系列操作系统上的高层编程框架。

之所以说应用程序是托管的是因为它们的执行过程是由 .NET Framework 管理的。实际上,.NET Framework 通过提供一个可控的运行时环境来管理这些执行过程,此运行时环境提供众多的服务,比如在应用程序运行时载入应用程序、管理内存、监视和维护安全和资源完整性。

在 .NET(以及Java)之前,应用程序未被托管,因为它们不是由可控的运行时环境来执行的。比如之前提到的 C++、VB6 编程语言所提供的编程环境中,操作系统中没有其他组件来提供 .Net 提供的这些服务,应用程序需要自己管理它们的服务,这在有些时候就导致了错误的代码、安全漏洞,以及数据的丢失。

.NET Framework 提供了众多的工具,比如编译器、调试器、编程语言、执行引擎(名为 Common Language Runtime,CLR,公共语言运行时),开发工具,以及大量的预定义的“功能模块”类库。这些类库被称作 Framework Class Libraries(FCLs)。

.Net 支持众多的编程语言,所有的编程语言编写的代码都将最终交给 CLR 来执行,因此 .Net 是“语言无关”的。目前微软推出的用于 .Net 开发的语言有:VB.NET J# C# F#,现在的 VC++ 也支持托管 .Net 编程。

.Net 编程可应用于很多方面,比如桌面应用程序、WEB应用程序、便携设备应用程序、游戏开发、用户界面开发、富互联网开发等。

通过安装一些插件,也可以在 Linux 等操作系统上运行 .Net 程序。

用VB.NET程序编写代码

Delphi代码如下:

procedure TForm1.Button1Click(Sender: TObject);

var

购物总价:Integer;

折扣:Extended;

begin

购物总价:=StrToInt(Edit1.Text);

if 购物总价250 then

begin

折扣:=0;

end

else if 购物总价500 then

begin

折扣:=0.05;

end

else if 购物总价1000 then

begin

折扣:=0.075;

end

else if 购物总价2000 then

begin

折扣:=0.1;

end

{

此段的折扣是多少?

else if 购物总价3000 then

begin

折扣:=0.05;

end

}

else if 购物总价=3000 then

begin

折扣:=0.15;

end;

ShowMessage('您享受的折扣是:'+FloatToStr(折扣)

+' 原价:'+IntToStr(购物总价)

+' 折后总价:'+FloatToStr(购物总价*(1-折扣)));

end;

用vb.net编写记事本源代码

Dim sFileName As String

Dim Search

Private Sub dateTimeMenu_Click()

Text1.Text = Now

End Sub

Private Sub deleteMenu_Click()

Text1.Text = Left(Text1.Text, Text1.SelStart) + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1)

End Sub

Private Sub findMenu_Click()

Search = InputBox("请输入要查找的字词:")

Dim Where1 '获取需要查找的字符串变量

Text1.SetFocus '文本框获得焦点,以显示所找到的内容Search = InputBox("请输入要查找的字词:")

Where1 = InStr(Text1.Text, Search) '在文本中查找字符串

If Where1 Then

'若找到则设置选定的起始位置并使找到的字符串高亮

Text1.SelStart = Where1 - 1

Text1.SelLength = Len(Search)

' Me.Caption = Where1 '测试用

'否则给出提示

Else: MsgBox "未找到所要查找的字符串。", vbInformation, "提示"

End If

End Sub

Private Sub findNextMenu_Click()

Dim Where2

Dim StartMe As Integer '查找的起始位置变量

Text1.SetFocus '文本框获得焦点

StartMe = Text1.SelLength + Text1.SelStart + 1 '给变量赋值

Where2 = InStr(StartMe, Text1.Text, Search) '令其从上次找到的地方找起

If Where2 Then

Text1.SelStart = Where2 - 1

Text1.SelLength = Len(Search)

Else: MsgBox "未找到所要查找的字符串.", vbInformation, "提示"

End If

End Sub

Private Sub aboutMenu_Click()

MsgBox Space(2) "文本编辑器版本号1.0" Chr(13) "由西南财经大学天府学院" Chr(13) Space(5) "肖忠 开发" Chr(13) Space(2) "copyright:天府学院"

End Sub

Private Sub allMenu_Click()

Text1.SelStart = 0

Text1.SelLength = Len(Text1.Text)

End Sub

Private Sub backcolorMenu_Click() '设置背景色代码

Form1.CommonDialog1.Action = 3

Text1.BackColor = Form1.CommonDialog1.Color

End Sub

Private Sub colorMenu_Click() '改变文字颜色代码

Form1.CommonDialog1.Action = 3

Text1.ForeColor = Form1.CommonDialog1.Color

End Sub

Private Sub cutMenu_Click()

Clipboard.SetText Text1.SelText

Text1.Text = Left(Text1.Text, Text1.SelStart) + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1)

End Sub

Private Sub exitMenu_Click()

End

End Sub

Private Sub fontMenu_Click() '字体菜单代码

Form1.CommonDialog1.Flags = 3 Or 256

Form1.CommonDialog1.Action = 4

If Len(Form1.CommonDialog1.FontName) = 0 Then

Form1.Text1.FontName = "宋体"

Else

Form1.Text1.FontName = Form1.CommonDialog1.FontName

End If

Form1.Text1.FontSize = Form1.CommonDialog1.FontSize

If Form1.CommonDialog1.FontBold = True Then

Form1.Text1.FontBold = True

Else

Form1.Text1.FontBold = False

End If

If Form1.CommonDialog1.FontItalic = True Then

Form1.Text1.FontItalic = True

Else

Form1.Text1.FontItalic = False

End If

Text1.ForeColor = Form1.CommonDialog1.Color

End Sub

Private Sub Form_Load()

Form1.Text1.Width = Form1.Width - 130

Form1.Text1.Height = Form1.Height

End Sub

Private Sub Form_Resize()

Form1.Text1.Width = Form1.Width - 130

Form1.Text1.Height = Form1.Height

End Sub

Private Sub help1Menu_Click()

Form1.CommonDialog1.HelpCommand = cdlHelpForceFile

Form1.CommonDialog1.HelpFile = "c:\windows\system32\winhelp.hlp"

CommonDialog1.ShowHelp

End Sub

Private Sub newMenu_Click()

If Len(Trim(Text1.Text)) = 0 Then

Form1.Caption = "我的记事本" "--" "未命名"

sFileName = "未命名"

Text1.FontSize = 15

Text1.FontName = "宋体"

Text1.Text = ""

Else

Call saveAsMenu_Click

Form1.Caption = "我的记事本" "--" "未命名"

sFileName = "未命名"

Text1.FontSize = 15

Text1.FontName = "宋体"

Text1.Text = ""

End If

End Sub

Private Sub openMenu_Click() '打开文件代码

If Len(Trim(Text1.Text)) = 0 Then

Form1.Caption = "我的记事本"

Form1.CommonDialog1.Filter = "文本文件|*.txt"

Form1.CommonDialog1.Flags = 4096

Form1.CommonDialog1.Action = 1

If Len(Form1.CommonDialog1.FileName) 0 Then

sFileName = Form1.CommonDialog1.FileName

Form1.Caption = Form1.Caption "--" Form1.CommonDialog1.FileTitle

Open sFileName For Input As #1

Text1.FontSize = 15

Text1.FontName = "宋体"

Do While Not EOF(1)

Line Input #1, Text$

All$ = All$ + Text$ + Chr(13) + Chr(10)

Loop

Text1.Text = All

Close #1

End If

Else

Call saveAsMenu_Click

Form1.Caption = "我的记事本"

Form1.CommonDialog1.Filter = "文本文件|*.txt"

Form1.CommonDialog1.Flags = 4096

Form1.CommonDialog1.Action = 1

If Len(Form1.CommonDialog1.FileName) 0 Then

sFileName = Form1.CommonDialog1.FileName

Form1.Caption = Form1.Caption "--" Form1.CommonDialog1.FileTitle

Open sFileName For Input As #1

Text1.FontSize = 15

Text1.FontName = "宋体"

Do While Not EOF(1)

Line Input #1, Text$

All$ = All$ + Text$ + Chr(13) + Chr(10)

Loop

Text1.Text = All

Close #1

End If

End If

End Sub

Private Sub pasteMenu_Click() '粘贴菜单代码

Text1.Text = Left(Text1.Text, Text1.SelStart) + Clipboard.GetText() + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1)

End Sub

Private Sub printMenu_Click()

Form1.CommonDialog1.ShowPrinter

For i = 1 To CommonDialog1.Copies

Printer.Print Text1.Text

Printer.Print Text1.Text

Next

Printer.EndDoc

End Sub

Private Sub saveAsMenu_Click() '另存为菜单代码

If Len(Trim(Text1.Text)) 0 Then

Form1.CommonDialog1.DialogTitle = "保存文件"

Form1.CommonDialog1.InitDir = "D:\"

Form1.CommonDialog1.Filter = "文本文件|*.txt"

Form1.CommonDialog1.Flags = 2

Form1.CommonDialog1.ShowSave

If Len(Form1.CommonDialog1.FileName) 0 Then

sFileName = Form1.CommonDialog1.FileName

Open sFileName For Output As #1

whole$ = Text1.Text

Print #1, whole

Close #1

End If

End If

End Sub

Private Sub saveMenu_Click()

If Len(Trim(Text1.Text)) 0 Then

Form1.CommonDialog1.DialogTitle = "保存文件"

Form1.CommonDialog1.InitDir = "D:\"

Form1.CommonDialog1.FileName = "新建文本"

Form1.CommonDialog1.Filter = "文本文件|*.txt"

Form1.CommonDialog1.Flags = 2

Form1.CommonDialog1.ShowSave

If Len(Form1.CommonDialog1.FileName) 0 Then

sFileName = Form1.CommonDialog1.FileName

Open sFileName For Output As #1

whole$ = Text1.Text

Print #1, whole

Close #1

End If

End If

End Sub

Private Sub statusMenu_Click()

End Sub


名称栏目:关于vb.net代码编写模式的信息
转载来源:http://cdkjz.cn/article/hsceih.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220