Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load/Save

Status
Not open for further replies.

Alanukdude

Technical User
Nov 13, 2002
20
GB
hi, i've got the below code saving various txt boxes saving values from 0-254 to a text file to a users choice.

CDMain.CancelError = True
On Error GoTo ErrHandler

CDMain.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt"
CDMain.FilterIndex = 2
CDMain.ShowSave

Dim save1
save1 = CDMain.FileName
Open save1 For Output As #1
Write #1, txtBase1.Text, txtBase2.Text
Write #1, txtShoulder1.Text, txtShoulder2.Text
Write #1, txtElbow1.Text, txtElbow2.Text
Write #1, txtWrist1.Text, txtWrist2.
Write #1, txtGripper1.Text, txtGripper2.Text
Close #1
Exit Sub

ErrHandler:
Exit Sub

How would i go about loading this back up into the software. everything is seperated by a comma.

This is a bit of software im atempting to write for my students robotic arm, it came with rubbish software so i decided to write my own.

thanks in advance
 
You could read everything back to a string. Then, since its comma seperated you could use the split function:

FileString = Read.WholeString

Array = split(Filestring, ",")

The above will create an array starting from 0 where Array[0] would be you first line!

Nick
 
hi,

sorry my programming knowledge is extremly limited, how do i apply this into my code.

many thanks
 
Somthing like:

CDMain.CancelError = True
On Error GoTo ErrHandler

CDMain.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt"
CDMain.FilterIndex = 2
CDMain.ShowOpen

Dim open1
open1 = CDMain.FileName
Open open1 For Input As #1
Read InputString, #1
Close #1

Array = split(InputStrin, ",")

txtBase1.Text = Array[0]
txtBase2.Text = Array[1]
txtShoulder1.Text = Array[2]
txtShoulder2.Text = Array[3]

etc etc
Exit Sub

ErrHandler:
Exit Sub


I would check how to open the file for input...i don;t have MSDN here...so it may be incorrect!

Hope this helps

Nick
 
i can't get this to work. any update on this please.


thank you
 
if you are certain that this is excaly how the file is ALWAYS written, then simply 'reverse' it to read the data back.

Dim save1
save1 = CDMain.FileName
Open save1 For Output As #1
Write #1, txtBase1.Text, txtBase2.Text
Write #1, txtShoulder1.Text, txtShoulder2.Text
Write #1, txtElbow1.Text, txtElbow2.Text
Write #1, txtWrist1.Text, txtWrist2.text
Write #1, txtGripper1.Text, txtGripper2.Text
Close #1

becomes

Dim load1
load1= CDMain.FileName
Open load1 For input As 1
input #1, txtBase1.Text, txtBase2.Text
input #1, txtShoulder1.Text, txtShoulder2.Text
input #1, txtElbow1.Text, txtElbow2.Text
input #1, txtWrist1.Text, txtWrist2.text
input #1, txtGripper1.Text, txtGripper2.Text
Close #1


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top