伊莉討論區

標題: VS 2010 FileStream 問題 (蠻復雜的) [打印本頁]

作者: n4chen    時間: 2011-1-21 03:28 PM     標題: VS 2010 FileStream 問題 (蠻復雜的)

我想要讓VB.NET 存檔為 .DAT
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim s, d, f, g, h As String
  3.         s = "REG_SZ"
  4.         d = "REG_DWORD"
  5.         f = "REG_BINARY"
  6.         g = "REG_MULTI_SZ"
  7.         h = "REG_EXPAND_SZ"
  8.         '------------------RegClass--------------------
  9.         '------------------Create Record------------------
  10.         If Dir("C:\Reg Record") = "" Then
  11.             System.IO.Directory.CreateDirectory("C:\Reg Record")
  12.         End If
  13.         '------------------Create Record------------------
  14.         '------------Create VB6 Object "Wshshell"-----------
  15.         Dim WshShell
  16.         WshShell = CreateObject("WScript.Shell")
  17.         '------------Create VB6 Object "Wshshell"-----------
  18.         '------------Declare Some Variable------------
  19.         Dim a, b, c As String
  20.         a = TextBox1.Text
  21.         b = TextBox2.Text
  22.         c = TextBox3.Text
  23.         '------------Declare Some Variable------------
  24.         '----------------Create Reg With RegClass Option----------------
  25.         If RadioButton1.Checked = True Then
  26.             WshShell.RegWrite("" & a, "" & b, "" & s)
  27.             My.Computer.Registry.SetValue("" & a, "" & b, "" & c.ToString)
  28.             Dim Y As String = Now.Year.ToString, M As String = Now.Month.ToString, DD As String = Now.Day.ToString, AllDateStr As String = Y & " Year " & M & " Mouth " & DD & " DAY"
  29.             Dim IntDatWithStr As Integer
  30.             AllDateStr = CInt(IntDatWithStr)
  31.             Dim Buffrtr(100000) As Byte
  32.             Dim CreateRegPath As String = AllDateStr & "  Create" & a & "\" & c
  33.             Dim record As New FileStream("C:\Reg Record\CreatRegRecord.dat", FileMode.Create)
  34.             Dim Writer As IAsyncResult = record.BeginWrite(Buffrtr, 0, CreateRegPath, Nothing, Nothing)
  35.         End If
複製代碼

它已經產生 .DAT檔了
問題來了
  1.        If RadioButton1.Checked = True Then
  2.             WshShell.RegWrite("" & a, "" & b, "" & s)
  3.             My.Computer.Registry.SetValue("" & a, "" & b, "" & c.ToString)
  4.             Dim Y As String = Now.Year.ToString, M As String = Now.Month.ToString, DD As String = Now.Day.ToString, AllDateStr As String = Y & " Year " & M & " Mouth " & DD & " DAY"
  5.             Dim IntDatWithStr As Integer
  6.             AllDateStr = CInt(IntDatWithStr)
  7.             Dim Buffrtr(100000) As Byte
  8.             Dim CreateRegPath As String = AllDateStr & "  Create" & a & "\" & c
  9.             Dim record As New FileStream("C:\Reg Record\CreatRegRecord.dat", FileMode.Create)
  10.             Dim Writer As IAsyncResult = record.BeginWrite(Buffrtr, 0, CreateRegPath, Nothing, Nothing)
  11.         End If
複製代碼

我想將 今天的 "年 月 日  新增登入檔的名稱 " 都寫入 .DAT 檔裡面
但都沒寫成功 都擲回 System.InvalidCastException
FileStream    http://msdn.microsoft.com/zh-tw/library/t7e3td2c.aspx
 
 
 
 




歡迎光臨 伊莉討論區 (http://a401.file-static.com/) Powered by Discuz!