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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieving number from file, adding 1 to it and saving new number to f

Status
Not open for further replies.

Nugget1

Technical User
Apr 9, 2003
3
AU
Hello everyone!

I've created a for loop to save a lab and it's variable to file and the number of students in that lab (initially set to 0) to a text file...like this

<% dim varStudNumb, varNumberNabs, varLineCounter, lab, tfrom, tto
lab = CInt(lab)
tfrom = CDbl(tfrom)
tto = CDbl(tto)
varStudNumb = CInt(varStudNumb)
varStudNumb = 0

'assign variable to hold number submitted
varNumberLabs = Request.Form(&quot;LabNumbs&quot;)

For varLineCounter = 1 to varNumberLabs
Response.Write &quot;Lab:&quot;
lab = Request.Form(&quot;Labs&quot; & varLineCounter)
Response.Write lab
WriteToFile &quot;Lab:&quot;
WriteToFile Request.Form(&quot;Labs&quot; & varLineCounter)
WriteToFile &quot;Students:&quot;
WriteToFile varStudNumb
WriteToFile vbCrLf
Response.Write &quot;<br/>&quot;
Next
CloseTextFile
%>

i can read the text from file also. like this:

<% 'more code above

'Read the file line by line
Do While Not TextStream.AtEndOfStream
line = textStream.readline

' Do something with &quot;Line&quot;
Response.Write Line %>
<input name=&quot;labSubmit&quot; type=&quot;Submit&quot; value=&quot;Submit&quot;><br/>
<%loop

however, how can i extract a particular variable from file (for this, i need to extract the '0' of students, add 1 to it and then overwrite the 0 with the new number in the text file?). All this must be done when a particular submit button is pressed, according to the lab number chosen...by this i mean:

lab: 1 students: 0 [submit] <---button
lab: 2 studnets: 0 [submit]

when user presses submit button, 1 should be added to students and the new number of students should be saved to file

lab: 1 students: 1 [submit]
lab: 2 students: 0 [submit]
if anyone can help me, i'd really really appreciate it. thankyou! anticipating your reply!

 
You can't change a part of a text file, you must read the whole text file into a variable or array and write the whole array back to a file changing the number of studends as you do it.

To extract a particular variable from the file you must test each line in a loop and match it to a set of rules.

For example, get the 6th character in the line using

Mid(line,6,1)

Test the follownig character to see if it a space or a number in case lab is 10 or more.

Do the same for the number of students which will be after &quot;students:&quot;

StartNo = InStr(line,&quot;students:&quot;)+10
Mid(line,StartNo,1)

Again test the following character for double figures.

For string manipulation functions go here


Hope this helps,

BDC.
 
Indeed that was very useful.

thankyou for your help.

will let you know how i went as i am still working on it, along with other things.

regards,
n
 
thread333-485850 may give you some direction

_________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top