PDA

View Full Version : سوال: مشکل در کد برنامه



iran_sky
دوشنبه 27 اردیبهشت 1389, 17: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


ممنون میشم کمکم کنید

Peyman.Gh
دوشنبه 27 اردیبهشت 1389, 17:58 عصر
مشکل در تبدیل String به Long میباشد در صورت امکان پروژه را ضمیمه کنید.

iran_sky
دوشنبه 27 اردیبهشت 1389, 18:13 عصر
اینم برنامه

Peyman.Gh
دوشنبه 27 اردیبهشت 1389, 18:32 عصر
این قسمت را :

FileGet(fn, p, (txt_name.Text))
FileGet(fn, p, (txt_lastname.Text))
FileGet(fn, p, (txt_telephone.Text))
FileGet(fn, p, (txt_address.Text))

به این صورت بنویسید و امتحان نمایید.
FileGet(fn, p, (System.Convert.ToInt64(txt_name.Text)))
FileGet(fn, p, (System.Convert.ToInt64(txt_lastname.Text)))
FileGet(fn, p, (System.Convert.ToInt64(txt_telephone.Text)))
FileGet(fn, p, (System.Convert.ToInt64(txt_address.Text)))

iran_sky
دوشنبه 27 اردیبهشت 1389, 18:35 عصر
دوست عزیز این خطا رو میده


Input string was not in a correct format.

iran_sky
دوشنبه 27 اردیبهشت 1389, 20:00 عصر
کسی نیست کمکم کنه

Open-Source
سه شنبه 28 اردیبهشت 1389, 09:21 صبح
خوب از پیغام خطایی که میده معلوم هستش رشته ورودی قتبلیت تبدیل به عدد رو نداره .
مثلا به این صورت هستش:
1254a36