iran_sky
دوشنبه 27 اردیبهشت 1389, 18:02 عصر
سلام دوستان
مشکل این کد چیه؟
من میخوام اطلاعات فایل رو به صورت تصادفی بخونم و در grid قرار بدم ولی این پیغام خطا زو میده
البته مشکل در خوندن اطلاعات هست نه در ذخیره
Conversion from string "" to type 'Long' is not valid.
PublicClass Form1
Structure person
<VBFixedString(10)> Dim name AsString
<VBFixedString(15)> Dim lastname AsString
<VBFixedString(7)> Dim tel AsString
<VBFixedString(15)> Dim addressas AsString
EndStructure
Dim p As person
Dim s AsString = ""
Dim sa AsString
PrivateSub btn_exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_exit.Click
Me.Close()
EndSub
PrivateSub btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_save.Click
Dim f AsInteger = FreeFile()
p.name = txt_name.Text
p.lastname = txt_lastname.Text
p.tel = txt_telephone.Text
p.addressas = txt_address.Text
Dim le AsInteger = Len(p)
FileOpen(f, "e:\test.txt", OpenMode.Random, OpenAccess.Write, OpenShare.LockWrite, Len(p))
Dim l AsLong = LOF(f) / Len(p)
FilePut(f, p, l + 1)
FileClose()
MsgBox(" ")
txt_name.Text = ""
txt_lastname.Text = ""
txt_telephone.Text = ""
txt_address.Text = ""
txt_name.Select()
EndSub
PrivateSub btn_read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_read.Click
Dim bol AsBoolean = False
Dim i AsInteger
Dim j AsInteger
Dim le AsInteger = Len(p)
Dim fn AsByte = FreeFile()
FileOpen(fn, "e:\test.txt", OpenMode.Random, OpenAccess.Read, , Len(p))
WhileNot EOF(fn)
FileGet(fn, p, (txt_name.Text))
FileGet(fn, p, (txt_lastname.Text))
FileGet(fn, p, (txt_telephone.Text))
FileGet(fn, p, (txt_address.Text))
If s = vbNewLine Then DataGridView1.Rows.Add()
EndWhile
FileClose(fn)
FileOpen(fn, "e:\test.txt", OpenMode.Random, OpenAccess.Read, , Len(p))
WhileNot EOF(fn)
OnErrorResumeNext
FileGet(fn, p, Str(txt_name.Text))
FileGet(fn, p, Str(txt_lastname.Text))
FileGet(fn, p, Str(txt_telephone.Text))
FileGet(fn, p, Str(txt_address.Text))
If s <> vbNewLine Then
DataGridView1.Item(j, i).Value = s
j += 1
Else
i += 1
j = 0
EndIf
EndWhile
FileClose(fn)
EndSub
EndClass
ممنون میشم کمکم کنید
مشکل این کد چیه؟
من میخوام اطلاعات فایل رو به صورت تصادفی بخونم و در grid قرار بدم ولی این پیغام خطا زو میده
البته مشکل در خوندن اطلاعات هست نه در ذخیره
Conversion from string "" to type 'Long' is not valid.
PublicClass Form1
Structure person
<VBFixedString(10)> Dim name AsString
<VBFixedString(15)> Dim lastname AsString
<VBFixedString(7)> Dim tel AsString
<VBFixedString(15)> Dim addressas AsString
EndStructure
Dim p As person
Dim s AsString = ""
Dim sa AsString
PrivateSub btn_exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_exit.Click
Me.Close()
EndSub
PrivateSub btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_save.Click
Dim f AsInteger = FreeFile()
p.name = txt_name.Text
p.lastname = txt_lastname.Text
p.tel = txt_telephone.Text
p.addressas = txt_address.Text
Dim le AsInteger = Len(p)
FileOpen(f, "e:\test.txt", OpenMode.Random, OpenAccess.Write, OpenShare.LockWrite, Len(p))
Dim l AsLong = LOF(f) / Len(p)
FilePut(f, p, l + 1)
FileClose()
MsgBox(" ")
txt_name.Text = ""
txt_lastname.Text = ""
txt_telephone.Text = ""
txt_address.Text = ""
txt_name.Select()
EndSub
PrivateSub btn_read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_read.Click
Dim bol AsBoolean = False
Dim i AsInteger
Dim j AsInteger
Dim le AsInteger = Len(p)
Dim fn AsByte = FreeFile()
FileOpen(fn, "e:\test.txt", OpenMode.Random, OpenAccess.Read, , Len(p))
WhileNot EOF(fn)
FileGet(fn, p, (txt_name.Text))
FileGet(fn, p, (txt_lastname.Text))
FileGet(fn, p, (txt_telephone.Text))
FileGet(fn, p, (txt_address.Text))
If s = vbNewLine Then DataGridView1.Rows.Add()
EndWhile
FileClose(fn)
FileOpen(fn, "e:\test.txt", OpenMode.Random, OpenAccess.Read, , Len(p))
WhileNot EOF(fn)
OnErrorResumeNext
FileGet(fn, p, Str(txt_name.Text))
FileGet(fn, p, Str(txt_lastname.Text))
FileGet(fn, p, Str(txt_telephone.Text))
FileGet(fn, p, Str(txt_address.Text))
If s <> vbNewLine Then
DataGridView1.Item(j, i).Value = s
j += 1
Else
i += 1
j = 0
EndIf
EndWhile
FileClose(fn)
EndSub
EndClass
ممنون میشم کمکم کنید