资讯

精准传达 • 有效沟通

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

vb.net整理代码,vb在线编程

求VB.NET2010操作ACCESS数据库的完整代码

Imports System.Data.OleDb

成都创新互联公司-专业网站定制、快速模板网站建设、高性价比思茅网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式思茅网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖思茅地区。费用合理售后完善,10年实体公司更值得信赖。

Public Class Parking

Private Sub Parking_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Now_Timer.Enabled = True

End Sub

Private Sub Now_Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Now_Timer.Tick

Now_Time_Label.Text = "当前时间:" Date.Now

End Sub

Private Sub Enter_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Enter_Button.Click

'定义一个OLEDB连接字符串

Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=F:\test\test.mdb"

'实例化OLEDB连接

Dim con As OleDbConnection = New OleDbConnection(conStr)

Dim sql As New System.Text.StringBuilder

'定义数据库插入语句

sql.Append("insert into Time_billing([Car_Num],[Enter_Time])")

sql.Append("values('" Trim(Car_Num_Text.Text) "','" Date.Now "')")

'打开数据库链接

con.Open()

'定义执行命令

Dim cmd As New System.Data.OleDb.OleDbCommand(sql.ToString, con)

'执行命令

cmd.ExecuteNonQuery()

'关闭数据库链接

con.Close()

MsgBox("提交成功!")

End Sub

Private Sub Leave_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Leave_Button.Click

Dim Time_Length As Double

Dim Pack_Fee As Double

Dim Enter_time As Date

Dim Leave_time As Date

Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=F:\test\test.mdb"

Dim con As OleDbConnection = New OleDbConnection(conStr)

Dim selSql As New System.Text.StringBuilder

Dim inSql As New System.Text.StringBuilder

Dim upSql As New System.Text.StringBuilder

Dim delSql As New System.Text.StringBuilder

Dim dr As OleDbDataReader

con.Open()

'SQL拼接过程中最后不需要有分号

'在赋值时,读取字段值时必须使用在数据库客户端查询时显示的字段名

selSql.Append("select")

selSql.Append(" Enter_Time")

selSql.Append(" from [Time_billing]")

selSql.Append("where Car_Num = '").Append(Trim(Car_Num_Text.Text)).Append("'")

Dim selcmd As New OleDb.OleDbCommand(selSql.ToString, con)

dr = selcmd.ExecuteReader()

If dr.Read() Then

Enter_time = dr("Enter_Time")

Leave_time = Date.Now

Else

MsgBox("木有数据!")

End If

Enter_Time_Text.Text = Enter_time

Leave_Time_Text.Text = Leave_time

'求时间差

Time_Length = Math.Round(DateDiff(DateInterval.Minute, Enter_time, Leave_time) / 60, 2)

Pack_Fee = Time_Length * 5

Pack_Fee_Text.Text = Pack_Fee

inSql.Append("update [Time_billing]")

inSql.Append(" set [Leave_Time] = '").Append(Trim(Leave_Time_Text.Text)).Append("'")

inSql.Append(" ,[Packing_Fee] = '").Append(Pack_Fee).Append("'")

inSql.Append("where Car_Num = '").Append(Trim(Car_Num_Text.Text)).Append("'")

Dim incom As New OleDb.OleDbCommand(inSql.ToString, con)

incom.ExecuteNonQuery()

'con.Close()

MsgBox("结算完成!")

'con.Open()

upSql.Append("insert into Time_billing_History([Car_Num],[Enter_Time],[Leave_Time],[Packing_Fee])")

upSql.Append(" select")

upSql.Append(" [Car_Num]")

upSql.Append(",[Enter_Time]")

upSql.Append(",[Leave_Time]")

upSql.Append(",[Packing_Fee]")

upSql.Append(" from [Time_billing]")

upSql.Append("where [Car_Num] = '").Append(Trim(Car_Num_Text.Text)).Append("'")

Dim upcom As New OleDb.OleDbCommand(upSql.ToString, con)

upcom.ExecuteNonQuery()

delSql.Append("delete")

delSql.Append(" from")

delSql.Append(" [Time_billing]")

delSql.Append(" where [Car_Num] = '").Append(Trim(Car_Num_Text.Text)).Append("'")

Dim delcom As New OleDb.OleDbCommand(delSql.ToString, con)

delcom.ExecuteNonQuery()

con.Close()

End Sub

Private Sub Clear_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear_Button.Click

Car_Num_Text.Clear()

Enter_Time_Text.Clear()

Leave_Time_Text.Clear()

Pack_Fee_Text.Clear()

End Sub

End Class

VB.net 代码问题

checklogin = "select 用户名 from 用户表"

最好改为:

checklogin = "select * from 用户表 where 用户名 = '" textbox1.text "'"

在后面判断reader是否有记录就可以知道用户名是否存在

用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编程代码,不要C语言的,我看不懂啊?

Imports System

Module Program

Sub Main()

Dim n As Integer

n=6

Console.WriteLine("{0}!={1}",n,fact(n))

n=10

For i As Integer=1 To n

Console.Write("{0}{1}",fibo(i),IIF(n=i,vbCrLf,","))

Next

Console.Write("按任意键继续。。。 ")

Console.ReadKey(True)

End Sub

' 递归算阶乘

Function fact(n As Long) As Long

If 0=n OrElse 1=n Then Return 1

Return n*fact(n-1)

End Function

' 递归算斐波那契数列

Function fibo(n As Long) As Long

If 1=n OrElse 2=n Then Return 1

Return fibo(n-1)+fibo(n-2)

End Function

End Module

vb.net问题,求代码

又碰你了……

好吧,这回代码改进了:

Code:

'我们需要几个基本控件:

'TextBox1 、TextBox2、TextBox3 、TextBox4分别为“原文”、“输入”、“准确率”、“用时”的显示文本框。

'Button1、Button2、Button3分别为“生成原文”、“开始输入”、“结束”三个功能性按钮。

'Timer1是计时器(Timer)组件。

'有几个为了不出错,需要把Enabled属性设为False的组件:TextBox1、TextBox2、Button3。

'下面是整体代码:(整个Form1.vb)

Public Class Form1

'声明几个需要的变量和随机器。

Dim i As Random = New Random '随即器

Dim TimeDate As Double = 0 '计时变量

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '生成原文按钮。

Dim k As Integer

Dim pText As String = ""

For si As Int16 = 1 To 30 '随即生成字符,添加到前面已声明的pText变量内。

k = i.Next(1, 26)

Select Case k '获取对应的字符。

Case 1

pText += "a"

Case 2

pText += "b"

Case 3

pText += "c"

Case 4

pText += "d"

Case 5

pText += "e"

Case 6

pText += "f"

Case 7

pText += "g"

Case 8

pText += "h"

Case 9

pText += "i"

Case 10

pText += "j"

Case 11

pText += "k"

Case 12

pText += "l"

Case 13

pText += "m"

Case 14

pText += "n"

Case 15

pText += "o"

Case 16

pText += "p"

Case 17

pText += "q"

Case 18

pText += "r"

Case 19

pText += "s"

Case 20

pText += "t"

Case 21

pText += "u"

Case 22

pText += "v"

Case 23

pText += "w"

Case 24

pText += "x"

Case 25

pText += "y"

Case 26

pText += "z"

End Select

Next

TextBox1.Text = pText

TextBox2.Text = ""

TextBox3.Text = ""

TextBox4.Text = ""

'处理文本内容。

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click '开始输入按钮。

If TextBox1.Text = "" Then

MsgBox("还未生成原文!") '如果前面未生成原文时的警告。

Else

'如果原文已有,将执行这些动作(即开始输入和准备)

TextBox2.Enabled = True

TextBox2.Select()

Timer1.Enabled = True

Button3.Enabled = True

Button1.Enabled = False

Button2.Enabled = False

End If

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick '计时器如果开始时的动作。

TimeDate += 1 / 10

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click '结束按钮。

Timer1.Enabled = False

Dim t As Double = TimeDate

TimeDate = 0

TextBox3.Text = t "秒"

Dim x As String, y As String

Dim i As Integer, s As Integer

s = 0

For i = 1 To Len(TextBox1.Text)

x = Mid(TextBox1.Text, i, 1)

y = Mid(TextBox2.Text, i, 1)

If x y Then

s = s + 1

End If

Next '寻找有几个错误。

'下面为计算正确率,使用Integer类型来约值。

Dim xi As Double = 1 - (s / 30)

Dim xiInt As Integer = xi * 100

TextBox4.Text = xiInt "%"

Button3.Enabled = False

Button1.Enabled = True

Button2.Enabled = True

End Sub

End Class

'到此结束,可以开始测试了。

'可以改进改代码后控件样式,以更方便使用。

VB.NET 列举组合的代码如何写?急!

基本的算法如下:

Class Program

Shared Sub Main()

Combine(Enumerable.Range(1, 8).ToArray(), 5)

End Sub

Private Shared Sub Combine(a() As Integer, n As Integer)

combine(a, 0, n, New Integer(n - 1){})

End Sub

Private Shared Sub combine(a() As Integer, m As Integer, n As Integer, b() As Integer)

If n=0 Then

For Each i As Integer In b

Console.Write(i  " ")

Next i

Console.WriteLine()

Return

End If

For i As Integer = m To a.Length-n

b(b.Length-n) = a(i)

combine(a, i+1, n-1, b)

Next i

End Sub

End Class

你的题目中排列的是字符串,那吧Integer数组改成String数组就可以了,通过InputBox输入后可以用"xxx,xxx".Split(",")来分隔成String数组,结果要在TextBox显示,可以把这个代码中的Console.Write换成追加到全局变量,再显示到TextBox就行。自己改造一下吧。


文章标题:vb.net整理代码,vb在线编程
URL标题:http://cdkjz.cn/article/hegjgi.html
多年建站经验

多一份参考,总有益处

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

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

大客户专线   成都:13518219792   座机:028-86922220