bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

java代碼撤銷,Java刪除代碼

vb計算器進制轉換程序

VB

德保ssl適用于網站、小程序/APP、API接口等需要進行數據傳輸應用場景,ssl證書未來市場廣闊!成為創新互聯的ssl證書銷售渠道,可以享受市場價格4-6折優惠!如果有意向歡迎電話聯系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!

二進制,八進制,十進制,十六進制轉換

-

程序開發

-

ASP.NET教程

Public

Function

D_To_B(ByVal

Dec

As

Long)

As

String

Do

D_To_B

=

Dec

Mod

2

D_To_B

Dec

=

Dec

\

2

Loop

While

Dec

End

Function

Public

Function

B_To_D(ByVal

Bin

As

String)

As

Integer

Dim

i

As

Long

For

i

=

1

To

Len(Bin)

B_To_D

=

B_To_D

*

2

+

Val(Mid(Bin,

i,

1))

Next

i

End

Function

Public

Function

H_To_B(ByVal

Hex

As

String)

As

String

Dim

i

As

Long

Dim

B

As

String

Hex

=

UCase(Hex)

For

i

=

1

To

Len(Hex)

Select

Case

Mid(Hex,

i,

1)

Case

"0":

B

=

B

"0000"

Case

"1":

B

=

B

"0001"

Case

"2":

B

=

B

"0010"

Case

"3":

B

=

B

"0011"

Case

"4":

B

=

B

"0100"

Case

"5":

B

=

B

"0101"

Case

"6":

B

=

B

"0110"

Case

"7":

B

=

B

"0111"

Case

"8":

B

=

B

"1000"

Case

"9":

B

=

B

"1001"

Case

"A":

B

=

B

"1010"

Case

"B":

B

=

B

"1011"

Case

"C":

B

=

B

"1100"

Case

"D":

B

=

B

"1101"

Case

"E":

B

=

B

"1110"

Case

"F":

B

=

B

"1111"

End

Select

Next

i

While

Left(B,

1)

=

"0"

B

=

Right(B,

Len(B)

-

1)

Wend

H_To_B

=

B

End

Function

Public

Function

B_To_H(ByVal

Bin

As

String)

As

String

Dim

i

As

Long

Dim

H

As

String

If

Len(Bin)

Mod

4

Then

Bin

=

String(4

-

Len(Bin)

Mod

4,

"0")

Bin

End

If

For

i

=

1

To

Len(Bin)

Step

4

Select

Case

Mid(Bin,

i,

4)

Case

"0000":

H

=

H

"0"

Case

"0001":

H

=

H

"1"

Case

"0010":

H

=

H

"2"

Case

"0011":

H

=

H

"3"

Case

"0100":

H

=

H

"4"

Case

"0101":

H

=

H

"5"

Case

"0110":

H

=

H

"6"

Case

"0111":

H

=

H

"7"

Case

"1000":

H

=

H

"8"

Case

"1001":

H

=

H

"9"

Case

"1010":

H

=

H

"A"

Case

"1011":

H

=

H

"B"

Case

"1100":

H

=

H

"C"

Case

"1101":

H

=

H

"D"

Case

"1110":

H

=

H

"E"

Case

"1111":

H

=

H

"F"

End

Select

Next

i

B_To_H

=

H

End

Function

VB.NET 怎么讀寫二進制文件,類似Open

本示例闡釋二進制文件的基本輸入和輸出(使用 BinaryReader、BinaryWriter 和 FileStream 類。 在如何創建日志文件標題下面有一個類似的主題。讀寫二進制信息使您可以創建和使用通過其他輸入和輸出方法無法訪問的文件。本示例還展示寫入非字符串數據,并展示二進制 I/O 的功能。

盡管計算機上的文件可以不同的類型和文件存儲,但是,二進制格式是文件的較常用格式之一。此處對創建二進制文件的簡短介紹使用基類 BinaryReader 和 BinaryWriter 從文件獲取信息,并將信息放入文件。這些類中的每個類均封裝一個信息流,因此,在進一步操作之前,需要創建一個可用于來回寫信息的流。因為要創建文件,所以可使用 FileStream 來公開特定文件,在此情況下,如果該文件已存在,則可以修改該文件,或者如果該文件尚不存在,則可以創建該文件。在有 FileStream 之后,可以使用它來構造 BinaryReader 和 BinaryWriter

在讀入信息之后,可以對信息進行所需的任何操作。但是,在某些時候,您可能想要將信息寫回文件,因此需要 BinaryWriter。在本示例中,您將使用 Seek 方法將信息追加到文件結尾,因此,在開始寫入之前,請確保指向文件的指針位于文件結尾。在使用 BinaryWriter 寫入信息時有多個選項。因為 Write 方法有足夠的重載用于您能夠寫入的所有信息類型,所以,可以使用 Write 方法向您的編寫器封裝的流寫入任何標準形式的信息。本情況下,還可以使用 WriteString 方法向流中寫入長度預先固定的字符串。

VB Source: VB\ReadWrite.aspx

%@ Import Namespace="System.Text" %

%@ Import Namespace="System.IO" %

script language="VB" runat=server

Class TestBinary

Public Shared Function ReadFile(selection As String) As String

Dim output As StringBuilder = New StringBuilder()

Dim fs As FileStream = New FileStream("data.bin", FileMode.OpenOrCreate)

Dim r As BinaryReader = New BinaryReader(fs)

Try

r.BaseStream.Seek(0,SeekOrigin.Begin) ' 將文件指針設置到文件開始

' 因為不同數據類型之間的很多轉換結果都是不可解釋的,

' 所以當在其他類型與二進制數據之間進行轉換時,

' 必須捕捉可能引發的任何潛在的異常...

' 能夠正確讀取數據依賴于如何寫入信息...

' 這與寫日志文件時不同。

Do While r.BaseStream.Position r.BaseStream.Length ' 當未到達文件結尾時

Select Case selection

Case "Boolean"

output.Append( r.ReadBoolean().ToString() )

Case "String"

output.Append( r.ReadString() )

Case "Integer"

output.Append( r.ReadInt32().ToString() )

End Select

Loop

Finally

fs.Close()

End Try

return output.ToString()

End Function

Public Shared Function WriteFile(output As Object, selection As String) As String

Dim fs As FileStream = New FileStream("data.bin", FileMode.Create)

Dim w As BinaryWriter = New BinaryWriter(fs)

Dim strOutput As String = ""

w.BaseStream.Seek(0, SeekOrigin.End) ' 將文件指針設置到文件結尾

' 因為正在寫的信息可能不適合于所選擇用于寫入的特定樣式

' (例如,單詞“Hello”作為整數?),所以我們必須捕捉寫入

' 錯誤,并通知用戶未能執行該任務

Try

Select Case selection

Case "Boolean"

Dim b As Boolean = Convert.ToBoolean(output)

w.Write( b )

Case "String"

Dim s As String = Convert.ToString(output)

w.Write( s )

Case "Integer"

Dim i As Int32 = Convert.ToInt32(output)

w.Write(i)

End Select

Catch E As Exception

' 讓用戶知道未能寫入該信息

strOutput = "寫異常:" chr(13) _

"無法以所請求的格式寫入要寫入的信息。" _

chr(13) "請輸入嘗試寫入的數據類型的有效值"

End Try

fs.Close()

return strOutput

End Function

End Class

Sub btnAction_Click(src As Object, E As EventArgs)

Dim s As String = ""

' 寫出文件

s = TestBinary.WriteFile(txtInput.Text, lstDataIn.SelectedItem.Text)

If s = "" Then

Try

' 讀回信息,顯示信息...

txtOutput.Text = TestBinary.ReadFile(lstDataIn.SelectedItem.Text)

Catch Exc As Exception

' 讓用戶知道未能寫入信息

s = "讀異常:" chr(13) _

"無法以所請求的格式讀取要寫入的信息。" _

chr(13) "請輸入嘗試寫入的數據類型的有效值"

End Try

Else

txtOutput.Text = s

End If

End Sub

/script

html

head

link rel="stylesheet" href="intro.css"

/head

body style="background-color:f6e4c6"

form method=post runat="server"

p

table

tr

tdb

下面的示例使用 BinaryWriter 對象創建一個二進制文件,然后使用 BinaryReader 讀取該信息。/b可以選擇不同的對象來將所需的信息寫入文件

此演示用于強調您需要知道如何讀取已寫入的二進制文件。一旦以某種格式寫入數據,就只能以該格式讀取該信息。但是,可以將多種不同的數據類型寫入文件。在此演示中,輸入任意字符串并將它們作為字符串讀取,對于整型,僅輸入整型數值項(試試浮點數字,然后看看會發生什么...);對于布爾型項,僅輸入詞“false”和“true”。

p

hr

/td

/tr

/table

asp:Table id="basetable" runat="server" border="0" cellspacing="0" cellpadding="5"

asp:tablerow

asp:tablecell verticalalign="top"

請選擇要保存到二進制文件的數據類型...

/asp:tablecell

asp:tablecell verticalalign="top"

asp:listbox id="lstDataIn" runat="server"

asp:listitemBoolean/asp:listitem

asp:listitem selected="true"String/asp:listitem

asp:listitemInteger/asp:listitem

/asp:listbox

/asp:tablecell

asp:tablecell verticalalign="top"

asp:button id="btnAction" onclick="btnAction_Click" Text="寫入/讀取文件" runat="server"/

/asp:tablecell

/asp:tablerow

用VB.NET編的計算器程序!

Public Class SimpleCalculator

Inherits System.Windows.Forms.Form

#Region " Windows 窗體設計器生成的代碼 "

Public Sub New()

MyBase.New()

'該調用是 Windows 窗體設計器所必需的。

InitializeComponent()

'在 InitializeComponent() 調用之后添加任何初始化

End Sub

'窗體重寫處置以清理組件列表。

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Windows 窗體設計器所必需的

Private components As System.ComponentModel.IContainer

'注意:以下過程是 Windows 窗體設計器所必需的

'可以使用 Windows 窗體設計器修改此過程。

'不要使用代碼編輯器修改它。

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents Button2 As System.Windows.Forms.Button

Friend WithEvents Button3 As System.Windows.Forms.Button

Friend WithEvents Button4 As System.Windows.Forms.Button

Friend WithEvents Button5 As System.Windows.Forms.Button

Friend WithEvents Button6 As System.Windows.Forms.Button

Friend WithEvents Button7 As System.Windows.Forms.Button

Friend WithEvents Button8 As System.Windows.Forms.Button

Friend WithEvents Button9 As System.Windows.Forms.Button

Friend WithEvents Button10 As System.Windows.Forms.Button

Friend WithEvents Button11 As System.Windows.Forms.Button

Friend WithEvents Button12 As System.Windows.Forms.Button

Friend WithEvents Button13 As System.Windows.Forms.Button

Friend WithEvents Button14 As System.Windows.Forms.Button

Friend WithEvents Button15 As System.Windows.Forms.Button

Friend WithEvents Button16 As System.Windows.Forms.Button

System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()

Me.Label1 = New System.Windows.Forms.Label

Me.TextBox1 = New System.Windows.Forms.TextBox

Me.Button1 = New System.Windows.Forms.Button

Me.Button2 = New System.Windows.Forms.Button

Me.Button3 = New System.Windows.Forms.Button

Me.Button4 = New System.Windows.Forms.Button

Me.Button5 = New System.Windows.Forms.Button

Me.Button6 = New System.Windows.Forms.Button

Me.Button7 = New System.Windows.Forms.Button

Me.Button8 = New System.Windows.Forms.Button

Me.Button9 = New System.Windows.Forms.Button

Me.Button10 = New System.Windows.Forms.Button

Me.Button11 = New System.Windows.Forms.Button

Me.Button12 = New System.Windows.Forms.Button

Me.Button13 = New System.Windows.Forms.Button

Me.Button14 = New System.Windows.Forms.Button

Me.Button15 = New System.Windows.Forms.Button

Me.Button16 = New System.Windows.Forms.Button

Me.SuspendLayout()

'

'Label1

'

Me.Label1.Location = New System.Drawing.Point(16, 16)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(48, 16)

Me.Label1.TabIndex = 0

Me.Label1.Text = "結果:"

'

'TextBox1

'

Me.TextBox1.Location = New System.Drawing.Point(64, 8)

Me.TextBox1.Name = "TextBox1"

Me.TextBox1.Size = New System.Drawing.Size(120, 21)

Me.TextBox1.TabIndex = 1

Me.TextBox1.Text = ""

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(200, 8)

Me.Button1.Name = "Button1"

Me.Button1.Size = New System.Drawing.Size(56, 24)

Me.Button1.TabIndex = 2

Me.Button1.Text = "清空"

'

'Button2

'

Me.Button2.Location = New System.Drawing.Point(48, 56)

Me.Button2.Name = "Button2"

Me.Button2.Size = New System.Drawing.Size(24, 24)

Me.Button2.TabIndex = 3

Me.Button2.Text = "1"

'

'Button3

'

Me.Button3.Location = New System.Drawing.Point(88, 56)

Me.Button3.Name = "Button3"

Me.Button3.Size = New System.Drawing.Size(24, 24)

Me.Button3.TabIndex = 4

Me.Button3.Text = "2"

'

'Button4

'

Me.Button4.Location = New System.Drawing.Point(136, 56)

Me.Button4.Name = "Button4"

Me.Button4.Size = New System.Drawing.Size(24, 24)

Me.Button4.TabIndex = 5

Me.Button4.Text = "3"

'

'Button5

'

Me.Button5.Location = New System.Drawing.Point(48, 88)

Me.Button5.Name = "Button5"

Me.Button5.Size = New System.Drawing.Size(24, 24)

Me.Button5.TabIndex = 6

Me.Button5.Text = "4"

'

'Button6

'

Me.Button6.Location = New System.Drawing.Point(88, 88)

Me.Button6.Name = "Button6"

Me.Button6.Size = New System.Drawing.Size(24, 24)

Me.Button6.TabIndex = 7

Me.Button6.Text = "5"

'

'Button7

'

Me.Button7.Location = New System.Drawing.Point(136, 88)

Me.Button7.Name = "Button7"

Me.Button7.Size = New System.Drawing.Size(24, 24)

Me.Button7.TabIndex = 8

Me.Button7.Text = "6"

'

'Button8

'

Me.Button8.Location = New System.Drawing.Point(48, 120)

Me.Button8.Name = "Button8"

Me.Button8.Size = New System.Drawing.Size(24, 24)

Me.Button8.TabIndex = 9

Me.Button8.Text = "7"

'

'Button9

'

Me.Button9.Location = New System.Drawing.Point(88, 120)

Me.Button9.Name = "Button9"

Me.Button9.Size = New System.Drawing.Size(24, 24)

Me.Button9.TabIndex = 10

Me.Button9.Text = "8"

'

'Button10

'

Me.Button10.Location = New System.Drawing.Point(136, 120)

Me.Button10.Name = "Button10"

Me.Button10.Size = New System.Drawing.Size(24, 24)

Me.Button10.TabIndex = 11

Me.Button10.Text = "9"

'

'Button11

'

Me.Button11.Location = New System.Drawing.Point(48, 152)

Me.Button11.Name = "Button11"

Me.Button11.Size = New System.Drawing.Size(24, 24)

Me.Button11.TabIndex = 12

Me.Button11.Text = "0"

'

'Button12

'

Me.Button12.Location = New System.Drawing.Point(176, 56)

Me.Button12.Name = "Button12"

Me.Button12.Size = New System.Drawing.Size(24, 24)

Me.Button12.TabIndex = 13

Me.Button12.Text = "+"

'

'Button13

'

Me.Button13.Location = New System.Drawing.Point(176, 88)

Me.Button13.Name = "Button13"

Me.Button13.Size = New System.Drawing.Size(24, 24)

Me.Button13.TabIndex = 14

Me.Button13.Text = "-"

'

'Button14

'

Me.Button14.Location = New System.Drawing.Point(176, 120)

Me.Button14.Name = "Button14"

Me.Button14.Size = New System.Drawing.Size(24, 24)

Me.Button14.TabIndex = 15

Me.Button14.Text = "*"

'

'Button15

'

Me.Button15.Location = New System.Drawing.Point(176, 152)

Me.Button15.Name = "Button15"

Me.Button15.Size = New System.Drawing.Size(24, 24)

Me.Button15.TabIndex = 16

Me.Button15.Text = "/"

'

'Button16

'

Me.Button16.Location = New System.Drawing.Point(88, 152)

Me.Button16.Name = "Button16"

Me.Button16.Size = New System.Drawing.Size(72, 24)

Me.Button16.TabIndex = 17

Me.Button16.Text = "計算"

'

'SimpleCalculator

'

Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)

Me.ClientSize = New System.Drawing.Size(264, 190)

Me.Controls.Add(Me.Button16)

Me.Controls.Add(Me.Button15)

Me.Controls.Add(Me.Button14)

Me.Controls.Add(Me.Button13)

Me.Controls.Add(Me.Button12)

Me.Controls.Add(Me.Button11)

Me.Controls.Add(Me.Button10)

Me.Controls.Add(Me.Button9)

Me.Controls.Add(Me.Button8)

Me.Controls.Add(Me.Button7)

Me.Controls.Add(Me.Button6)

Me.Controls.Add(Me.Button5)

Me.Controls.Add(Me.Button4)

Me.Controls.Add(Me.Button3)

Me.Controls.Add(Me.Button2)

Me.Controls.Add(Me.Button1)

Me.Controls.Add(Me.TextBox1)

Me.Controls.Add(Me.Label1)

Me.Name = "SimpleCalculator"

Me.Text = "簡單計算器"

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub TextBox1_TabStopChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim btn As Button '按鈕類型的變量

btn = sender '把產生該事件的按鈕對象賦值給btn

TextBox1.Text = TextBox1.Text + btn.Text '把該按鈕的Text屬性值連接到TextBox1中

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click

Dim btn As Button

btn = sender

'在文本框的Text屬性后連接一個空格、本按鈕的Text屬性值和一個空格

TextBox1.Text = TextBox1.Text + " " + btn.Text + " "

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

TextBox1.Text = "" '清空文本框

End Sub

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click

Dim btn As Button

btn = sender

TextBox1.Text = TextBox1.Text + " " + btn.Text + " "

End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click

Dim btn As Button

btn = sender

TextBox1.Text = TextBox1.Text + " " + btn.Text + " "

End Sub

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click

Dim btn As Button

btn = sender

TextBox1.Text = TextBox1.Text + " " + btn.Text + " "

End Sub

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click

'發生錯誤轉移到標號“ErrorPro”指定的行去執行錯誤處理程序

On Error GoTo ErrorPro

Dim r As Decimal '保存計算結果的變量

Dim t As String = TextBox1.Text '用于保存文本框中的算術表達式

Dim space As Integer = t.IndexOf(" ") '搜索空格位置,如果沒有空格,返回值為0

'字符串的取子符方法,第二個參數小于0,則將產生錯誤號為5的異常,即過程參數不正確

Dim s1 As String = t.Substring(0, space) '通過取子串方法獲得第一個運算數

Dim op As String = t.Substring(space + 1, 1) '通過取子串方法獲得運算符

Dim s2 As String = t.Substring(space + 3) '通過取子串方法獲得第二個運算數

Dim arg1, arg2 As Integer

arg1 = Val(s1) : arg2 = Val(s2)

Select Case op

Case "+" : r = arg1 + arg2

Case "-" : r = arg1 - arg2

Case "*" : r = arg1 * arg2

Case "/" : r = arg1 / arg2

Case Else

MsgBox("輸入的運算符有誤!")

Exit Sub

End Select

TextBox1.Text = CStr(r) '顯示結果

Exit Sub '退出過程

ErrorPro: '錯誤處理程序塊

Select Case Err.Number

Case 6 '除數為零時,或運算溢出時的錯誤號

MsgBox("算術運算溢出!", , "溢出提示")

TextBox1.Focus()

Exit Sub

Case 5 ' Substring過程的參數不符合要求的錯誤號

MsgBox("必須輸入運算符和第二個運算數!", , "運算數少")

Exit Sub

Case Else

'其它情況顯示錯誤號和錯誤原因

MsgBox("錯誤號為" Err.Number Chr(10) Chr(13) "錯誤原因:" Err.Description)

Exit Sub

End Select

End Sub

End Class

vb.net 將文件轉化成二進制

首先引入System.IO命名空間

Imports System.IO

然后使用文件流來讀入數組:

Dim bytes() As Byte

Using fs As New FileStream(文件路徑,FileMode.Open)

ReDim bytes(fs.Length-1)

fs.Read(bytes,0,fs.Length)

fs.Close()

End Using

這樣bytes就是整個文件的所有字節了

從字節生成Image:

Dim img As Image = Image.FromStream(New MemoryStream(bytes))

img就是圖片了

vb.net 二進制讀取文件

VB.NET打開二進制文件用fileopen完成,打開二進制文件的形式為:openmode.binary

讀取二進制文件用的是fileget方法,寫入二進制文件用的是fileput方法。

應用示例:將一批隨機數保存在一個dat文件中,然后再將其提取到文本框中。

二進制文件的讀寫一批隨機數的存取,程序為:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim x, i, fn As Integer

Dim s As String = ""

fn = FreeFile()

FileOpen(fn, "d:\data.dat", OpenMode.Binary)

For i = 1 To 8

x = Int(Rnd() * 100)

s = s + Str(x)

FilePut(fn, x)

Next

FileClose(fn)

TextBox1.Text = s

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim x, fn As Integer

Dim s As String = ""

fn = FreeFile()

FileOpen(fn, "d:\data.dat", OpenMode.Binary)

Do While Not EOF(fn)

FileGet(fn, x)

s = s + Str(x) + " "

Loop

FileClose(fn)

TextBox1.Text = s

End Sub

vb.net如何讀寫二進制文件? 有各種類型的變量

open函數用來打開一個文件,其調用的一般形式為:

文件指針名=fopen(文件名,使用文件方式);

其中,

“文件指針名”必須是被說明為FILE

類型的指針變量;

“文件名”是被打開文件的文件名;

“使用文件方式”是指文件的類型和操作要求。

“文件名”是字符串常量或字符串數組。

例如:

FILE

*fp;

fp=("file

a","r");

其意義是在當前目錄下打開文件file

a,只允許進行“讀”操作,并使fp指向該文件。

又如:

FILE

*fphzk

fphzk=("c:\\hzk16","rb")

其意義是打開C驅動器磁盤的根目錄下的文件hzk16,這是一個二進制文件,只允許按二進制方式進行讀操作。兩個反斜線“\\

”中的第一個表示轉義字符,第二個表示根目錄。

使用文件的方式共有12種,下面給出了它們的符號和意義。

文件使用方式

意義

“rt”

只讀打開一個文本文件,只允許讀數據

“wt”

只寫打開或建立一個文本文件,只允許寫數據

“at”

追加打開一個文本文件,并在文件末尾寫數據

“rb”

只讀打開一個二進制文件,只允許讀數據

“wb”

只寫打開或建立一個二進制文件,只允許寫數據

“ab”

追加打開一個二進制文件,并在文件末尾寫數據

“rt+”

讀寫打開一個文本文件,允許讀和寫

“wt+”

讀寫打開或建立一個文本文件,允許讀寫

“at+”

讀寫打開一個文本文件,允許讀,或在文件末追加數據

“rb+”

讀寫打開一個二進制文件,允許讀和寫

“wb+”

讀寫打開或建立一個二進制文件,允許讀和寫

“ab+”

讀寫打開一個二進制文件,允許讀,或在文件末追加數據

對于文件使用方式有以下幾點說明:

1)

文件使用方式由r,w,a,t,b,+六個字符拼成,各字符的含義是:

r(read):

w(write):

a(append):

追加

t(text):

文本文件,可省略不寫

b(banary):

二進制文件

+:

讀和寫

2)

凡用“r”打開一個文件時,該文件必須已經存在,且只能從該文件讀出。

3)

用“w”打開的文件只能向該文件寫入。若打開的文件不存在,則以指定的文件名建立該文件,若打開的文件已經存在,則將該文件刪去,重建一個新文件。

4)

若要向一個已存在的文件追加新的信息,只能用“a”方式打開文件。但此時該文件必須是存在的,否則將會出錯。

5)

在打開一個文件時,如果出錯,fopen將返回一個空指針值NULL。在程序中可以用這一信息來判別是否完成打開文件的工作,并作相應的處理。因此常用以下程序段打開文件:

6)

if((fp=fopen("c:\\hzk16","rb")==NULL)

{

printf("\nerror

on

open

c:\\hzk16

file

當前題目:java代碼撤銷,Java刪除代碼
文章位置:http://vcdvsql.cn/article20/hspjco.html

成都網站建設公司_創新互聯,為您提供全網營銷推廣網站營銷營銷型網站建設建站公司網站建設搜索引擎優化

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

營銷型網站建設