Welcome to Gaia! ::

Thank you for the original help. Now I'm running into a different problem. I am using the streamwriter object to copy the contents of an array into a txt file. The problem is that it doesnt write the user's input, it writes "WindowsApplication1.Form1 + Person" Person is a structure that I am using. If you need any more info to help me out please ask.

here's the code for the program:

Option Explicit On
Option Infer Off
Option Strict On
Public Class Form1
Structure Person
Public strName As String
Public strHeight As String
Public strweight As String
End Structure


Dim Persons(49) As Person
Dim incoming(49) As String
Dim inthighestrowsub As Integer = 0
Dim outfile As IO.StreamWriter
Dim infile As IO.StreamReader


Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Persons(inthighestrowsub).strName = CStr(txtName.Text.PadRight(15))
Persons(inthighestrowsub).strHeight = CStr(txtHeight.Text.PadRight(15))
Persons(inthighestrowsub).strweight = CStr(txtWeight.Text)
inthighestrowsub = inthighestrowsub + 1
txtName.Text = ""
txtHeight.Text = ""
txtWeight.Text = ""
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim y As Integer = 0
If IO.File.Exists("records.txt") Then
outfile = IO.File.AppendText("records.txt")
'write array into file'
Do Until y = inthighestrowsub
outfile.WriteLine(Persons(y))
y = y + 1
Loop
outfile.Close()
Else : outfile = IO.File.CreateText("records.txt")
Do Until y = inthighestrowsub
outfile.WriteLine(Persons(y))
y = y + 1
Loop
outfile.Close()
End If




'this section goes last'
Dim x As Integer = 0
Do Until x = 49
Persons(x).strName = ""
Persons(x).strHeight = ""
Persons(x).strweight = ""
x = x + 1
Loop
End Sub

Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
Dim x As Integer = 0
Dim y As Integer = 0
Dim read1 As String

If IO.File.Exists("records.txt") Then
infile = IO.File.OpenText("records.txt")
Do While infile.Peek <> -1
read1 = read1 & infile.ReadLine & ControlChars.NewLine
Loop


lblResults.Text = CStr("Name:").PadRight(15) & CStr("Height:").PadRight(15) & CStr("Weight:").PadRight(15) & ControlChars.NewLine & read1

Else
MessageBox.Show("There is no file to read. Please press save to create the file.")
End If
infile.Close()

End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lblResults.Text = ""
Dim stream As New IO.StreamWriter("G:COMP9LAB2COMP9LAB2binDebugrecords.txt", False)
stream.WriteLine("")
stream.Close()

End Sub

End Class
Bloodhail
I am working on my homework assignment and I was wondering what the easiest way would be to display a full array in one label. Thanks!

i didnt use vb for long of time but here is the solution. i hope it works, because i forgot the vb codes
dim a
a = array.length - 1' getting the total array length. -1 because array starts from 0
for i = 1 to a
label1.text = label1.text & " " & array(i)
next

this code will display all array with a space
Sorry for my bad english
Sitwon's avatar
  • 50
  • 100
  • 150
hassan47477
Bloodhail
I am working on my homework assignment and I was wondering what the easiest way would be to display a full array in one label. Thanks!

i didnt use vb for long of time but here is the solution. i hope it works, because i forgot the vb codes
dim a
a = array.length - 1' getting the total array length. -1 because array starts from 0
label1.text = array(0)
for i = 1 to a
label1.text = label1.text & " " & array(i)
next

this code will display all array with a space
Sorry for my bad english
Don't forget the first element of the array.

DISCLAIMER: I've never programmed in VB so I can't warrant the correctness of hassan47477's solution. However, in principal, it looks correct.
bump for new question
You may want to put your code into paste bin or similar as the gaia parser sucks.
Disconsented
You may want to put your code into paste bin or similar as the gaia parser sucks.


I accidentally hit quote instead of code. redface
Sitwon
hassan47477
Bloodhail
I am working on my homework assignment and I was wondering what the easiest way would be to display a full array in one label. Thanks!

i didnt use vb for long of time but here is the solution. i hope it works, because i forgot the vb codes
dim a
a = array.length - 1' getting the total array length. -1 because array starts from 0
label1.text = array(0)
for i = 1 to a
label1.text = label1.text & " " & array(i)
next

this code will display all array with a space
Sorry for my bad english
Don't forget the first element of the array.

DISCLAIMER: I've never programmed in VB so I can't warrant the correctness of hassan47477's solution. However, in principal, it looks correct.

your right
i m not good at vb to understand your code but at last lines
Dim stream As New IO.StreamWriter("G:COMP9LAB2COMP9LAB2binDebugrecords.txt", False)
stream.WriteLine("")
stream.Close()

G:COMP9LAB2COMP9LAB2binDebugrecords.txt is not correct.
G:COMP9LAB2COMP9LAB2binDebugrecords.txt is correct
maybe this is the problem. but if you are looking for a program that save array and loads it. then i can make you a class file. which you will include and use it. for example
class_name.savearray(array1,"c:file.txt")

and i use vb 2008. i dont know if vb 2010 will open vb 2008.
hassan47477
i m not good at vb to understand your code but at last lines
Dim stream As New IO.StreamWriter("G:COMP9LAB2COMP9LAB2binDebugrecords.txt", False)
stream.WriteLine("")
stream.Close()

G:COMP9LAB2COMP9LAB2binDebugrecords.txt is not correct.
G:COMP9LAB2COMP9LAB2binDebugrecords.txt is correct
maybe this is the problem. but if you are looking for a program that save array and loads it. then i can make you a class file. which you will include and use it. for example
class_name.savearray(array1,"c:file.txt")

and i use vb 2008. i dont know if vb 2010 will open vb 2008.


actually, I don't think the class file is what I'm supposed to use as we have not even gone over that chapter yet in my class... maybe I'm making this program more complex than it needs to be.
Bloodhail
hassan47477
i m not good at vb to understand your code but at last lines
Dim stream As New IO.StreamWriter("G:COMP9LAB2COMP9LAB2binDebugrecords.txt", False)
stream.WriteLine("")
stream.Close()

G:COMP9LAB2COMP9LAB2binDebugrecords.txt is not correct.
G:COMP9LAB2COMP9LAB2binDebugrecords.txt is correct
maybe this is the problem. but if you are looking for a program that save array and loads it. then i can make you a class file. which you will include and use it. for example
class_name.savearray(array1,"c:file.txt")

and i use vb 2008. i dont know if vb 2010 will open vb 2008.


actually, I don't think the class file is what I'm supposed to use as we have not even gone over that chapter yet in my class... maybe I'm making this program more complex than it needs to be.

then you can use public sub! you can search on google. "save and load array vb.net code" and use it in you project. just make a public sub. it makes it easy.

public sub save_arr(filepath as string)
'array save code from google.
end sub
' you can use sub as
save_arr ("c:a.txt")
'with this you can make your project easy. i just put these sub in class and it will make project simple and easy to understand and use


Edit : why dont i just make you public sub? you just copy that code and paste in your project and use it. if you want.
sorry for my bad english
hassan47477
Bloodhail
hassan47477
i m not good at vb to understand your code but at last lines
Dim stream As New IO.StreamWriter("G:COMP9LAB2COMP9LAB2binDebugrecords.txt", False)
stream.WriteLine("")
stream.Close()

G:COMP9LAB2COMP9LAB2binDebugrecords.txt is not correct.
G:COMP9LAB2COMP9LAB2binDebugrecords.txt is correct
maybe this is the problem. but if you are looking for a program that save array and loads it. then i can make you a class file. which you will include and use it. for example
class_name.savearray(array1,"c:file.txt")

and i use vb 2008. i dont know if vb 2010 will open vb 2008.


actually, I don't think the class file is what I'm supposed to use as we have not even gone over that chapter yet in my class... maybe I'm making this program more complex than it needs to be.

then you can use public sub! you can search on google. "save and load array vb.net code" and use it in you project. just make a public sub. it makes it easy.

public sub save_arr(filepath as string)
'array save code from google.
end sub
' you can use sub as
save_arr ("c:a.txt")
'with this you can make your project easy. i just put these sub in class and it will make project simple and easy to understand and use


Edit : why dont i just make you public sub? you just copy that code and paste in your project and use it. if you want.
sorry for my bad english


If I don't do it myself I likely won't learn anything!
Bloodhail
hassan47477
Bloodhail
hassan47477
i m not good at vb to understand your code but at last lines
Dim stream As New IO.StreamWriter("G:COMP9LAB2COMP9LAB2binDebugrecords.txt", False)
stream.WriteLine("")
stream.Close()

G:COMP9LAB2COMP9LAB2binDebugrecords.txt is not correct.
G:COMP9LAB2COMP9LAB2binDebugrecords.txt is correct
maybe this is the problem. but if you are looking for a program that save array and loads it. then i can make you a class file. which you will include and use it. for example
class_name.savearray(array1,"c:file.txt")

and i use vb 2008. i dont know if vb 2010 will open vb 2008.


actually, I don't think the class file is what I'm supposed to use as we have not even gone over that chapter yet in my class... maybe I'm making this program more complex than it needs to be.

then you can use public sub! you can search on google. "save and load array vb.net code" and use it in you project. just make a public sub. it makes it easy.

public sub save_arr(filepath as string)
'array save code from google.
end sub
' you can use sub as
save_arr ("c:a.txt")
'with this you can make your project easy. i just put these sub in class and it will make project simple and easy to understand and use


Edit : why dont i just make you public sub? you just copy that code and paste in your project and use it. if you want.
sorry for my bad english


If I don't do it myself I likely won't learn anything!

i dont use vb 2010 now. when i will get more ram then i will. and you could provide the whole source code so i can check. but i dont think vb 2008 can open vb 2010 files
this is what im working on.
http://www.mediafire.com/?g53e9n6sm5v37i5
try to keep it on the dl. my friends would kill me if i lost all our work
Acarnagie122
this is what im working on.
http://www.mediafire.com/?g53e9n6sm5v37i5
try to keep it on the dl. my friends would kill me if i lost all our work

what is this? is this Bloodhail's project source?
hassan47477
Acarnagie122
this is what im working on.
http://www.mediafire.com/?g53e9n6sm5v37i5
try to keep it on the dl. my friends would kill me if i lost all our work

what is this? is this Bloodhail's project source?

No it's my own work. It's done now all that is left is minor things such as an FAQ guide and debug at the bottom. It still works tho :p try it out if you want

Quick Reply

Submit
Manage Your Items
Other Stuff
Get Items
Get Gaia Cash
Where Everyone Hangs Out
Other Community Areas
Virtual Spaces
Fun Stuff