vb.net读本地文件 vba本地窗口

VB.net窗体设计中,如何读取.txt文件中的数据?

1、新建一个标准的VB EXE工程,只有一个Form,Form上有两个按钮:Command1和Command2。

按需求定制设计可以根据自己的需求进行定制,做网站、成都网站制作构思过程中功能建设理应排到主要部位公司做网站、成都网站制作的运用实际效果公司网站制作网站建立与制做的实际意义

2、双击Command1添加如下代码

Private Sub Command1_Click()

Dim strFile     As String

Dim intFile     As Integer

Dim strData     As String

strFile = "c:\学生成绩.txt"

intFile = FreeFile

Open strFile For Input As intFile

strData = StrConv(InputB(FileLen(strFile), intFile), vbUnicode)

Debug.Print strData

Close intFile

End Sub

3、按F8开始单步调试代码,点击Command1,进入单步调试功能,

4、多次按下F8或直接按下F5运行完成,就完成了读取文本文件内容并输出到立即窗口。

vb.net二进制怎么读取文件?

一、二进制文件读写

1、写二进制数据到指定目录

==将barray字节数组中的数据创建在strFilename目录文件下,存储格式为二进制,False表示不添加,直接覆盖创建。

2、从指定路径下读取二进制数据到数组

==将目录中的文件读取到barry字节数组中,即读取二进制文件。

二、字符文件的读写

1、 将txtFile控件中的字符写到srtFileName指定目录,以创建方式。

2、从srtFileName目录中的文件读取到txtFile控件

vb.net 怎样读取文件

imports System.IO

读取指定文件

'

'读取指定文本文件

Public Function readtext(ByVal path As String)

If path = "" Then

readtext = "操作失败!"

Exit Function

End If

Try

If File.Exists(path) = True Then

Dim fs As New FileStream(path, FileMode.Open)

Dim sr As New StreamReader(fs)

Dim str As String

str = sr.ReadToEnd.ToString

sr.Close()

fs.Close()

readtext = str

Else

readtext = "操作失败!"

End If

Catch ex As Exception

readtext = "操作失败!"

End Try

End Function

'向指定文件写入数据

Public Function writetext(ByVal path As String, ByVal opi As Integer, ByVal msg As String)

If path = "" Then

writetext = "操作失败!"

Exit Function

End If

Dim op As FileMode

Select Case opi

Case 1

op = FileMode.Append

Case 2

op = FileMode.Create

Case Else

op = FileMode.Create

End Select

Try

If File.Exists(path) = True Then

Dim fs As New FileStream(path, op)

Dim sr As New StreamWriter(fs)

sr.WriteLine(msg)

sr.Close()

fs.Close()

writetext = "操作完成!"

Else

writetext = "操作失败!"

End If

Catch ex As Exception

writetext = "操作失败!"

End Try

End Function

VB.net 读取文本文件?

1、实现上传按钮方法代码。

2、判断图片对象是否为空代码。

3、取得数据库字段 dt.Rows(0)("Pic")方法代码。

4、字节数组转换为Image类型方法代码。

5、处理SQL中操作Image类型方法代码。

6、实现的上传结果。

vb.net开发一款软件,需要读取本地数据,请问将本地数据存在什么文件里面,用什么方法读取较快,万

Option Explicit On

Option Strict On

Imports System

Imports System.Data

Imports System.Data.SqlClient

Public Class Program

Public Shared Sub Main()

Dim connectionString As String = _

"Data Source=(local);Initial Catalog=Northwind;" _

"Integrated Security=true"

' Provide the query string with a parameter placeholder.

Dim queryString As String = _

"SELECT ProductID, UnitPrice, ProductName from dbo.Products " _

"WHERE UnitPrice @pricePoint " _

"ORDER BY UnitPrice DESC;"

' Specify the parameter value.

Dim paramValue As Integer = 5

' Create and open the connection in a using block. This

' ensures that all resources will be closed and disposed

' when the code exits.

Using connection As New SqlConnection(connectionString)

' Create the Command and Parameter objects.

Dim command As New SqlCommand(queryString, connection)

command.Parameters.AddWithValue("@pricePoint", paramValue)

' Open the connection in a try/catch block.

' Create and execute the DataReader, writing the result

' set to the console window.

Try

connection.Open()

Dim dataReader As SqlDataReader = _

command.ExecuteReader()

Do While dataReader.Read()

Console.WriteLine( _

vbTab "{0}" vbTab "{1}" vbTab "{2}", _

dataReader(0), dataReader(1), dataReader(2))

Loop

dataReader.Close()

Catch ex As Exception

Console.WriteLine(ex.Message)

End Try

Console.ReadLine()

End Using

End Sub

End Class

这是我在vs2010中微软自带的MSDN示例代码里面拷的,是关于ADO.net连接sql的操作。

希望对你有帮助。 如果你还需要其他的,我也可以再拷给你看。


分享名称:vb.net读本地文件 vba本地窗口
文章URL:http://myzitong.com/article/doospos.html