for endfor numeric increment turns to character after 9
for endfor numeric increment turns to character after 9
(OP)
Here is the code
PARAMETERS fn,numflds
CREATE TABLE (fn) (A c(15))
i = 1
FOR i = 2 TO iif(numflds > 26,25,numflds)
thisfld = CHR(i + 65) && B etc.
ALTER table (fn) ADD column(thisfld) C(15)
ENDFOR
IF numflds > 26
FOR i = 27 TO numflds
thisfld = CHR(65 + INT(i/65) + char(64 + i)
ENDFOR
ENDIF
Note: this is all to create a table to append to from an xls, since import no longer works claiming an invalid header or something. )*&%^*)&*()*&
Very strange that trying crashes fox every time regardless of what filetype I try.
PARAMETERS fn,numflds
CREATE TABLE (fn) (A c(15))
i = 1
FOR i = 2 TO iif(numflds > 26,25,numflds)
thisfld = CHR(i + 65) && B etc.
ALTER table (fn) ADD column(thisfld) C(15)
ENDFOR
IF numflds > 26
FOR i = 27 TO numflds
thisfld = CHR(65 + INT(i/65) + char(64 + i)
ENDFOR
ENDIF
Note: this is all to create a table to append to from an xls, since import no longer works claiming an invalid header or something. )*&%^*)&*()*&
Very strange that trying crashes fox every time regardless of what filetype I try.
RE: for endfor numeric increment turns to character after 9
RE: for endfor numeric increment turns to character after 9
Thanks a bunch.
RE: for endfor numeric increment turns to character after 9
It's always tempting to use i, but it would be clearer if you used m.index
Regards
ing
Griff
Keep
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
There is no place like G28 X0 Y0 Z0
RE: for endfor numeric increment turns to character after 9
Creating the field does not create the variable. It is the line i = 1 that actually creates the variable. And if you omitted that line - which, in any case, seems to be redundant - then the following line (FOR i = 2 ... ) would create the variable.
As Griff say, you can use m. to distinguish variables that have the same names as fields. But it's better to avoid the situation completely. Personally, I always use so-called Hungarian notation for variable names, so in this case the variable would be lnI.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: for endfor numeric increment turns to character after 9
Further i starts at 2. 2+65 is 67 which is C. Seems you missed B as a column.
You should be free to use i as the variable, but you must write so the compiler understands, and that requires mdots.
Mike Yearwood - Former Microsoft Visual FoxPro MVP award winner. TWICE
RE: for endfor numeric increment turns to character after 9
loops, better to use a variable with a more meaningful name. It would avoid this kind of potential problem:
CODE
Better, clearer at least (in my opinion).
CODE
Regards
Griff
Keep
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
There is no place like G28 X0 Y0 Z0
RE: for endfor numeric increment turns to character after 9
You have better import options, for example one of these:
https://support.microsoft.com/en-us/topic/importin...
http://praisachion.blogspot.com/2017/08/importfrom...
http://praisachion.blogspot.com/2022/05/import-fro...
Chriss
RE: for endfor numeric increment turns to character after 9
CODE
And this is a questionable logic for the upper limit of the first loop
CODE
MIN(numflds ,26) would be much easier for that.
And in the end you only have the table for import, no code to actually import. How about looking for solutions online, if you get that XLS problem? It's a 13 year old problem and there are already solutions to it, see my first answer.
Chriss
RE: for endfor numeric increment turns to character after 9
Will check out the resources. You are great.
RE: for endfor numeric increment turns to character after 9
CODE
Could easily be adapted to create field names A-Z, AA-AZ, etc. up to ZZ, it always pays to first look for already existing solutions. Here's a function to convert column number to name from Luis Maria Guayan from https://fox.wikis.com/wc.dll?Wiki~FindExcelColumnL...:
CODE -->
To create a table or cursor it's much better to first generate the whole CREATE statement and not ALTER a table n times. Do you realize an ALTER TABLE is creating a new table and then appends the previous one's data into it? Even if you want to alter an already existing table with data in it, you'd want to do this in one step only. One statement to CREATE or one to ALTER, not a series.
Chriss
RE: for endfor numeric increment turns to character after 9
RE: for endfor numeric increment turns to character after 9
Mike Yearwood - Former Microsoft Visual FoxPro MVP award winner. TWICE
RE: for endfor numeric increment turns to character after 9
If you are referring to my statement about using so-called Hungarian notation (above), it certainly doesn't imply not using mdots. (I did make it clear that it's my personal preference. I don't insist on anyone else using it or any other convention.)
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: for endfor numeric increment turns to character after 9
Mike Yearwood - Former Microsoft Visual FoxPro MVP award winner. TWICE
RE: for endfor numeric increment turns to character after 9
Mike Yearwood - Former Microsoft Visual FoxPro MVP award winner. TWICE
RE: for endfor numeric increment turns to character after 9
RE: for endfor numeric increment turns to character after 9
I skipped the constant declarations to highlight the mdot usage. That's the way I do it because then even the debugger will show me the content of the variable instead of the field.
This is from gendbc.prg
CODE
Then GenDBCX which is more technically accurate, but even they still did:
CODE
The manual got an important mdot distinction wrong, but gendbc and gendbcx both use mdots because they cannot guarantee what the user will name their tables and fields.
CODE
As I said, even though they do have a convention, they used mdot because it is enforced by the compiler.
Mike Yearwood - Former Microsoft Visual FoxPro MVP award winner. TWICE