INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

simple loop ( my memory is not good)

simple loop ( my memory is not good)

(OP)
I can't think how to do this..
FOR i= 1 to 24
Strtofile((cEntry+STR(i)) +' ' +cPath+Chr(013)+Chr(10),('garble.log'),.T.)
readpwini(inifile,'write',cSection,(cEntry+STR(i)),cPath)

endfor

Thanks

Gendev

RE: simple loop ( my memory is not good)

What exactly is your question? What are you trying to achieve?

Please give us some more information to work on.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: simple loop ( my memory is not good)

That is a tiny bit obtuse, what are you hoping to achieve?

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

RE: simple loop ( my memory is not good)

(OP)
Mike,

Sorry!
I have 24 lines like
Strtofile((cEntry1 +' ' +cPath+Chr(013)+Chr(10),('garble.log'),.T.)
readpwini(inifile,'write',cSection,(cEntry1,cPath)
to cover the variables cEntry1 to cEntry24

I need to concatenate the i value with cEntry to run them in the for next loop.

What I came up with gives me an error.

Is this clearer?

GenDev

RE: simple loop ( my memory is not good)

So, you've got 24 separate variables, named cEntry1, cEntry2, and so on up to cEntry24?

And you want each line to contain the contents of each of those variables in turn?

If that's right, then instead of cEntry+STR(i)), you should use EVAL("cEntry" + TRANSFORM(i)).

At first glance, the rest of your syntax looks OK (although I can't speak for the call to Readpwin(), as I don't know anything about that function).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: simple loop ( my memory is not good)

By the way, it will be more efficient to do something like this:

CODE -->

lcLine = ""
FOR lnI = 1 to 24
  lcI = TRANSFORM(lnI)
  lcLine = EVAL("cEntry) + lcI) + " " + cPath + CHR(13) + CHR(10))
ENDFOR
STRTOFILE(lcLine, "garble.log") 

Again, I haven't addressed the call to Readpwin(). But it looks like you've got a syntax error in that line - possibly a spuious left parenthesis just before cEntry1.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: simple loop ( my memory is not good)

I assume those are fields. Well, look into AFIELDS() and even simpler FCOUNT() and FIELD(n).

Bye, Olaf.


RE: simple loop ( my memory is not good)

(OP)
Hi all,

Just to clarify
the 23 standard line pairs in my code are for cEntry1 to cEntry24
as an example cEntry1 might be a path statement -
cPath = ' '
1 - readpwini(inifile,'write',cSection,cEntry1,cPath)
2 - Strtofile(cEntry1 +' ' +cPath+Chr(013)+Chr(10),'garble.log'),.T.)

I am trying to do better code by putting these actions in a for next loop
- the first line writes a new value (cPath) to the ini file for the each entry cEntryn
- the second line writes to my log file which saves a record of the action.
As is the code works perfectly for the 24 variables.
I'm sorry I didn't say this before.
Now to the code offers

CODE

lcLine = ""
FOR lnI = 1 to 24
  lcI = TRANSFORM(lnI)
  lcLine = EVAL("cEntry) + lcI) + " " + cPath + CHR(13) + CHR(10))
ENDFOR
STRTOFILE(lcLine, "garble.log") 

I believe the strtofile should be within the for next as I want a line in my log for each action.

so

CODE

lcLine = ""
FOR lnI = 1 to 24
  lcI = TRANSFORM(lnI)
  lcLine = EVAL("cEntry) + lcI) + " " + cPath + CHR(13) + CHR(10))
STRTOFILE(lcLine, "garble.log")
ENDFOR 
this leaves the code to write to the ini file which also belongs in the for next loop.
readpwini(inifile,'write',cSection,cEntry1,cPath)

I need to get the content of each cEntry
Mike,
Unfortunately the line
lcLine = EVAL("cEntry) + lcI) + " " + cPath + CHR(13) + CHR(10))
compiles with an error
GenDev

RE: simple loop ( my memory is not good)

CODE

* Simplify the above same code so you may be able to see the syntax error
lcCrlf = CHR(13) + CHR(10)
lcLine = ""
FOR lnI = 1 to 24
   lcI = TRANSFORM(lnI)
   lcLine = "CENTRY" + lcI
   lcLine = EVAL(lcLine)
   lcLine = lcLine + " "
   lcLine = lcLine + lcCrLf
   STRTOFILE(lcLine, "garble.log",1)  && To append to the file
ENDFOR 

RE: simple loop ( my memory is not good)

Quote:

I believe the strtofile should be within the for next as I want a line in my log for each action.

No, that's not correct.

In my code, I am creating all 24 log entries in a single variable. There's nothing wrong with that. The fact that each entry is on a separate physical line makes no difference. Having created that variable, I am writing it to the file in a single action - outside the loop.

The effect is the same as in your original code, but my method is more efficient as it only required one disk access, not 24.

That said, it occures to me that you are not creating a new log file from scratch, but rather that you want to append these 24 entries to an existing log file. If that's correct, my code will still work, but you will need to pass .T. as the third parameter to STRTOFILE().

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: simple loop ( my memory is not good)

(OP)
Thanks Mike,

I couldn't run your code due to the error I mentioned in my previous post so I missed your building of the string.

I quote

'Unfortunately the line
lcLine = EVAL("cEntry) + lcI) + " " + cPath + CHR(13) + CHR(10))
compiles with an error.'

and I haven't been able to sort out this staement

readpwini(inifile,'write',cSection,cEntry1,cPath)

I need to get the actual contents of each string in here eg cEntry1. etc.

Thanks
GenDev

RE: simple loop ( my memory is not good)

I just noticed that there is a double-quotes missing, immediately after "cEntry. In other words, instead of this"

"cEntry

you need this:

"cEntry"

This was my fault, as it was an error my earlier post. But a glance at the code would have told you what was wrong. In general, it's always a good idea to try to figure out any incorrect syntax for yourself before you rush to post a message. It also helps if you could tell us what the error message says, rather than simply saying there is an error.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close