# Help with a Loop



## des000 (May 30, 2008)

I'm working on a program to save and restore the network configuration. This part is a program to save the network configuration. It's still incomplete, but at this time, I'm having trouble designing a loop. This loop is supposed to generate the IP Address information. I'll include the minimum files needed for the task.

Test is a test profile. I manually generated that one when I was creating restore netstate. The other package contains the code I'm working on. The loop is in save netstate. At the very end, in the last big loop you see is the loop(s) I am intending to write. These are encased in that big loop so that I generate the information for all network cards simultaniously. The loop should exist in that loop.


----------



## Squashman (Apr 4, 2003)

What language?


----------



## des000 (May 30, 2008)

The loop needs to be in Windows XP style batch file code.

Now if you look at the other code, most of the controlling code is written in that language too, but some is written in AutoIt code because it can't be written purely in batch code. In other words, some code makes use of autoit to compute certain tasks, like reading from GUI's and such.

But mainly the controlling program is in a batch file. Therefore, the same should be done in the other code.


----------



## Squashman (Apr 4, 2003)

So what part do you want us too look at. This is a whole lot of code, and will probably take me a while to understand what you are doing.


----------



## des000 (May 30, 2008)

Line #360 to Line #512 is the rough line numbers, given by notepad. The end loop's Line #415 to that end is the code I'm trying to revise.


----------



## TheOutcaste (Aug 8, 2007)

Finally got a chance to take a look.


des000 said:


> I'm having trouble designing a loop.


What trouble? Is it not outputting the correct info, or is it generating an error?


des000 said:


> This loop is supposed to generate the IP Address information. I'll include the minimum files needed for the task.


You didn't include *OUT2COM* or *FREGSTRVALUE*, or any files those two may call, so we can't run the loop, let alone the entire file.
Without those files, or a description/sample of the data they return, there is no way to tell if the problem is in *save_netstate* or in the data those files return.

The data (all zeros) in the *net0_IP_Address_Info.ncnf* and *net1_IP_Address_Info.ncnf* files are what you would expect if DHCP is enabled. The loop sets *ADDRESSES*, *NETMASKS*, and *GATEWAYS* to 0 if DHCP is enabled, and *METRIC*S will be 0 if *OUT2COM* returns an error, or will be whatever *OUT2COM* returns in the *OUTCMD* variable. If you need the actual values, you need to call a routine that will get them.

Did find the following errors:

```
Line 482     SET SUBINDEX2=!SUBINDEX2!+1
Line 489     SET SUBINDEX2=!SUBINDEX2!+1
Line 496     SET SUBINDEX2=!SUBINDEX2!+1
Line 503     SET SUBINDEX2=!SUBINDEX2!+1
Line 510     SET SUBINDEX1=!SUBINDEX1!+1
```
You forgot the /A switch for the Set command.
Also, might be easier to use this format for incrementing a variable:

```
Set /A SUBINDEX2+=1
```
The number of times the Echo statement in line 507 will be executed depends on the value of *INDEX3*. If *INDEX3* is zero, it will be executed just once. The first time it will use the current value of these variables:
*ADDRESS
NETMASK
GATEWAY
METRIC*
These values are set in the preceding For loops only if SUBINDEX2 and SUBINDEX1 are not equal, which only happens if *INDEX3* is 1 or more.
And SUBINDEX2 will _*always*_ be zero when the If statement is executed.
So the first time it outputs the current Echo setting to the file (unless they have been defined someplace previously).
The 2nd and subsequent times, it will use the _first_ value it parses from these variables in the For loop in line 457:
*ADDRESSES
NETMASKS
GATEWAYS
METRICS*

Without knowing the format of the data in these 4 variables, there is no way to accurately troubleshoot this section, but, for example, if *ADDRESSES* is a list of comma/space delimited values, *ADDRESS* will be set to the first item *only*, it will never be set to any other value in *ADDRESSES*.

So no matter what the value of *INDEX3*, it will only return the first value from those 4 variables.

So, to troubleshoot this we need either all the files it will call, or the values these variables have at line 457:
*ADDRESS
NETMASK
GATEWAY
METRIC
**ADDRESSES
NETMASKS
GATEWAYS
METRICS*

And the value of *INDEX3* at line 476.

I don't have any systems with a multi-homed NIC, so a sample for those variables from a system that does would be useful. I'm assuming the whole point is to keep the data aligned, for example a NIC with multiple IPs/Gateways; you might have 3 addresses but only 1 or two Gateways.

Another suggestion. For the usage sections I would use *%~n0* rather than just *%0*. *%0* returns the batch file name _as called_, not just the base name as *%~n0* does. So if someone calls the file like *C:\Scripts\save_network.cmd*, usage will display:
*
Usage: **C:\Scripts\save_network.cmd** [Profile Name]*, not just
*Usage: **save_network** [Profile Name]*

Jerry


----------



## des000 (May 30, 2008)

OK, so the incrementing tip helps a lot. I used the other form so much, I don't think I'll change it, but I'll start now to use the *+=* form. I would've preferred the equivelant of *++* if it existed, as in *i++*. C++ has those capabillities, and so does C. Obviously though, this is a different language. But if it happened to have those operators, I'd use them instead, as that's more appropriate. I think I tried and found it doesn't though. I'm glad it does have the *+=* operator though.

The other sugesstion, the *%~n0*, is good to know in my bag of tricks. But if it returns the extension with it, it's NOT what I want. I only wanted to display the usage using the name, but NOT the extension, because I want to emphasize the name so that the user get's the idea of the function, but I don't want them to see the extension. But that helps, because I didn't know that one existed either.

So basically, the loop is only returning the first values, huh? I wondered if that was why the output was going on so wacky. I want to use all the values, and they are seperated by commas. One thing that threw me off though, is Windows XP allows you to have different numbers of gateways and metrics, then it does IP Addresses and Netmasks. So IP Addresses and Netmasks, are synchronized in the number, and then gateways and metrics are synchronized in number, though there may not be the same number of both of those two. But it can be. Well, that's to do with multiple information for the same network card. Windows XP supports it, therefore my programs should too.

Yes, I've got multiple cards on this system, and that's a lot of what the need for this program is. I only have one card so far per type of card. But I've got one wired card, and one wireless card, and one firewire card. That's not counting virtual cards I may later install.

So you need to run the program huh? Well, it seems obvious that you might, but I didn't want to send the rest unless I had to. For one, it's turned into a bigger package than I origionally planned. But I'll get it there then. I'll attach it.

Looks like it's not working. It's probably too big. So for the remainder of this thread, here's what I'll do. I'll put it up on my NAS (a handy thing), and then give the user name and password.

The username is *forumhelp*, and the password is *guest*. The share name is *forumhelp*. So you can access the relevant files on ftp://sunraysvillanet.dyndns.org/disk1/forumhelp. It's only read only. And it will only stay up long enough for me to figure this out. But maybe that's the easiest way, because these files seem to calculate to too big.


----------



## des000 (May 30, 2008)

There, data should be up now. This is a wireless link, so sometimes it has trouble functioning. But right now, it's up (mostly) 24/7. Please only copy it from there to your local machine before reading or viewing it.

You'd have to install using the setup batch file for the standard scripts to get it to work. (It will put out a folder named C:\BATCH, and MUST BE IN THIS FOLDER!) Then the included autoexec.bat will most likely be at least partially needed, so that the programs execute. I would be careful in not replacing anything of yours that's important, if you've got stuff named like that.

Now, the network folder contains the files, now as I've been working on them since, trying at both ends therefore to debug this somehow. The copy before is the copy it was before. Either copy the most recent (which just has those lines changed), or the copy I sent is fine to work on. I "think" that if you install the standard scripts, it will work just fine. If some parts don't work just fine, it's only because that these files might rely on other programs I'd forgotten about, because I hadn't documented it yet, because I found that there was some little pieces missing. But just post any errors if you need to run a program that isn't working for these purposes, and then I'll try to find the dependency or point you to what it's dependent on, where I downloaded it and how to install it.

Now also after you install the standard scripts, you have to copy the binaries from the network folder to the installed folder copy of the standard scripts (C:\BATCH). Some of those things expect to run from ONLY there. The binaries, are basically, all the .exes (which are just the compiled autoit's pretty much), plus all the batch files, plus the Profiles folder, which includes the Test profile, which was manually generated, and is an example of the language I'm generating to, though it does NOT show it's complete capabillities or anything, and then copy all the stuff from inside the modified folder to C:\BATCH as well. DO NOT just copy the modified folder, it won't work. It expects to have the contents, not the modified folder. That folder was just there to show me what I modified when I was creating stuff, due to different bugs.

Once you install those, you should be able to run the program now, that is, unless I forgot to include anything. It has also occasionally failed due to some code. So if it fails with things like "Bad access value" or something like that it was, then just wait and run it again. I don't know why it does that yet.

The syntax name, is save_netstate [Profile Name].


----------



## TheOutcaste (Aug 8, 2007)

des000 said:


> The other sugesstion, the *%~n0*, is good to know in my bag of tricks. But if it returns the extension with it, it's NOT what I want.


*%~n* will return just the name. *%~nx* will return name and extension. Type *Call /?* or *For /?* into a command prompt to see the complete list of modifiers

Might be easier to just add a couple of echo statements to capture the variables into a file and post that, rather than make sure nothing is missing, or in a wrong folder. But I'll see if I can get it working. Put it in a virtual machine with a couple of virtual cards and see what happens.

To capture the variables, in the save_netstate file, put this in Line 475 (right after INDEX3 is set):

```
For %%a In (1 2 3) Do Echo INDEX%%a=!INDEX%%a!>>forumhelpdata.txt
```
And this in Line 456, (Right before the For statement):

```
For %%a In (ADDRESSES NETMASKS GATEWAYS METRICS ADDRESS NETMASK GATEWAY METRIC) Do Echo %%a=!%%a!>>forumhelpdata.txt
```
There *must not* be a space between the *!* and the *>>*
Then just attach the *forumhelpdata.txt* file to a post
Edit the IP Addresses in the file if needed so the first two numbers are 192.168, or similar if you want to keep the real ones private.

Try this though, if the data is formatted the way I expect, this should do the trick:

```
For %%I In (ADDRESSES NETMASKS GATEWAYS METRICS) Do (
Set _count=0
Set _tmp=!%%I!
FOR %%A IN ("!_tmp:,=","!") DO (
Set /A _count+=1
Set _tmp=%%A                   .
Set _%%I!_count!=!_tmp:~0,19!
))
Echo.IP Address       NetMask          Gateway          Metric>>!CARD_CARD_IP!_Address_Info.ncnf
For /L %%I In (1,1,!_count!) Do Echo !_ADDRESSES%%I:"=!!_NETMASKS%%I:"=!!_GATEWAYS%%I:"=!!_METRICS%%I:"=!>>!CARD_CARD_IP!_Address_Info.ncnf
```
Will produce this output:

```
IP Address       NetMask          Gateway          Metric
192.168.100.100  255.255.255.128  192.168.100.1    1                
192.168.200.150  255.255.255.0                                      
1.2.3.4          255.0.0.0        1.2.3.1          3
```
If the data looks like this:

ADDRESSES=192.168.100.100,192.168.200.150,1.2.3.4
NETMASKS=255.255.255.128,255.255.255.0,255.0.0.0
GATEWAYS=192.168.100.1,,1.2.3.1
METRICS=1,,3

Blank values must be represented by consecutive commas or there is no way to insure the values will match up.

HTH

Jerry


----------



## TheOutcaste (Aug 8, 2007)

Haven't got it installed yet, but was able to follow the chain to see how the data for the loop is generated. This should work better.
This parses the data and puts it into temp variables. If there are unequal numbers of Addresses/NetMasks vs Gateways/Metrics, it will create dummy entries to "fill the blanks" so the output will look OK.

```
Set _pad=                   .
For %%I In ([COLOR=Red]ADDRESSES NETMASKS[/COLOR]) Do Call :_parse1 %%I [COLOR=Red]_AddCount[/COLOR]
For %%I In ([COLOR=Red]GATEWAYS METRICS[/COLOR]) Do Call :_parse1 %%I [COLOR=Red]_GateCount[/COLOR]
If !_AddCount! EQU !_GateCount! (
  Set _max=!_AddCount!
  ) Else (
  If !_AddCount! GTR !_GateCount! (
    Call :_parse2 [COLOR=Red]GATEWAYS METRICS[/COLOR] !_GateCount! !_AddCount!
    ) Else (
    Call :_parse2 [COLOR=Red]ADDRESSES NETMASKS[/COLOR] !_AddCount! !_GateCount!
))  
Echo.IP Address       NetMask          Gateway          Metric>>!CARD_CARD_IP!_Address_Info.ncnf
For /L %%I In (1,1,!_max!) Do Echo !_ADDRESSES%%I:"=!!_NETMASKS%%I:"=!!_GATEWAYS%%I:"=!!_METRICS%%I:"=!>>!CARD_CARD_IP!_Address_Info.ncnf
Goto done
::Subroutines to parse Addresses, Netmasks, Gateways, and Metrics for proper Display
:_parse1
Set _count=0
Set _tmp=!%1!
FOR %%A IN ("!_tmp:,=","!") DO (
  Set /A _count+=1
  Set _tmp=%%A%_pad%
  Set _%1!_count!=!_tmp:~0,19!
)
Set %2=!_Count!&Goto :EOF
:_parse2
Set _max=%4
Set /A _tmp=%3+1
For /L %%I In (!_tmp!,1,%4) Do (
  Set _%1%%I=%_pad:~0,17%
  Set _%2%%I=%_pad:~0,17%
  )
Goto :EOF
```
EDIT Color coded variable names that are being used as strings rather than values. The should not have ! or % around them.
Also added missing output line.
Jerry


----------



## des000 (May 30, 2008)

Thanks. I'm checking it to see if it's working. I had to change a few things to the correct syntax first, as the variable names needed ! around them. ! means delayed variable expansion which all of these needed.


----------



## TheOutcaste (Aug 8, 2007)

All the variables that need the ! for delayed expansion are already set.
If you are referring to these lines for example:

```
For %%I In ([B]ADDRESSES NETMASKS[/B]) Do Call :_parse1 %%I _AddCount
For %%I In ([B]GATEWAYS METRICS[/B]) Do Call :_parse1 %%I _GateCount
```
*ADDRESSES NETMASKS* *GATEWAYS METRICS* are _text strings_, not variables. The routine needs to pass the _name_ of the variable, not the value.
If you put the ! marks around them it will not work


----------



## TheOutcaste (Aug 8, 2007)

Just noticed I left out the line that actually outputs the data.

I've added it back in, and color coded the variable names in those locations where they are being used as names rather than values.


----------



## des000 (May 30, 2008)

OK. Thanks. I'll take a look at that modification then.


----------



## des000 (May 30, 2008)

Thanks. I'm checking it.


----------



## des000 (May 30, 2008)

Oops! I posted the same statement twice!


----------



## des000 (May 30, 2008)

So it's been close to working. I found some issues with it though. One, the code uses a bunch of spaces instead of one tab inbetween the elements. Two, it fills things with "nothing". I want to fill things with 0's. I'm closer to figuring this out so far, but not there yet. I'm away from my normal Internet access right now, but will be back to it, so I hadn't posted a lot more yet.


----------



## TheOutcaste (Aug 8, 2007)

I used spaces because tabs won't always line up. It will depend on what the tab stops are set to in whatever program is used to view the resulting file. Notepad defaults to multiples of 8, but Notepad++ defaults to multiples of 4, and Notetab is multiples of 6.
Spaces will line up in the Command Prompt, or any editor using a mono-spaced font, like the ones mentioned above. Using spaces just seemed easier.
Of course, spaces _won't_ line up if it's viewed with a proportional font, like in Wordpad (tabs in multiples of 6 as well).
Example if using Notepad:
IP Address of xxx.xxx.xxx.xxx with one tab will work, there will be one space after the IP Address
IP Address of x.x.x.x needs two tabs (three in Notepad++)
At some point in between Notepad++ would need two tabs
If you put just a 0 in there, you need two (four in Notepad++)

You could check the length to determine how many tabs to add, but you would need to keep track of the length of the first three values.

If you want zeros instead of blanks, change these two lines:


```
[COLOR=Blue]29[/COLOR] Set _%1%%I=%_pad:~0,17%
[COLOR=Blue]30[/COLOR] Set _%2%%I=%_pad:~0,17%
```
To this

```
[COLOR=Blue]29[/COLOR] Set _%1%%I=[COLOR=Red]0[/COLOR]%_pad:~0,1[COLOR=Red]6[/COLOR]%
[COLOR=Blue]30[/COLOR] Set _%2%%I=[COLOR=Red]0[/COLOR]%_pad:~0,1[COLOR=Red]6[/COLOR]%
```
If you want 0.0.0.0, put that in and use 10 instead of 16. You'd then have to special case Metrics or it would also show as 0.0.0.0 if not present:

```
[COLOR=Blue]29[/COLOR] Set _%1%%I=[COLOR=Red]0.0.0.0[/COLOR]%_pad:~0,1[COLOR=Red]0[/COLOR]%[COLOR=Blue]
30[/COLOR] If %2==METRICS (Set _%2%%I=[COLOR=Red]0[/COLOR]%_pad:~0,1[COLOR=Red]6[/COLOR]%) Else (Set _%2%%I=[COLOR=Red]0.0.0.0[/COLOR]%_pad:~0,1[COLOR=Red]0[/COLOR]%)
```
If you want to use tabs, then change these lines:

```
[COLOR=Blue]01[/COLOR] Set _pad=                   .
[COLOR=Blue]22[/COLOR] Set _%1!_count!=!_tmp:~0,19!
[COLOR=Blue]29[/COLOR] Set _%1%%I=%_pad:~0,17%
[COLOR=Blue]30[/COLOR] Set _%2%%I=%_pad:~0,17%
```
.

```
[COLOR=Blue]01[/COLOR] Set _pad=[COLOR=Red]{TAB}[/COLOR]  [COLOR=Blue][B]<-- type a tab character for[/B][/COLOR] [COLOR=Red]{TAB}[/COLOR].
[COLOR=Blue]22[/COLOR] Set _%1!_count!=!_tmp!%_pad%
[COLOR=Blue]29[/COLOR] Set _%1%%I=0%_pad%
[COLOR=Blue]30[/COLOR] Set _%2%%I=0%_pad%
```
and remove this line:

```
[COLOR=Blue]21[/COLOR] Set _tmp=%%A%_pad%
```
The Line Numbers refer to code in post #10; could be off, but will get you the the right part at least.

For the zero lines (29,30) add another *%_pad%* for two tabs

```
Set _%1%%I=0%_pad%%_pad%
```
more if needed.

You could also create several variables (*_pad1*, *_pad2*, *_pad3*, *_pad4*) each with a different number of tabs, then select the correct one based on length.

Jerry


----------



## des000 (May 30, 2008)

Thanks. I'll try that. I agree, tabs won't always line up for pretty printing. The only reason to use tabs instead is because this is machine generated output to be read back in by the machine. Though if someone wants to generate these manually, they certainly may, and they may use comments to make it look prettier. But the machine will simply use one tab inbetween the stuff.


----------



## TheOutcaste (Aug 8, 2007)

Gotcha:up:

Don't know if a trailing tab would be a problem, depends on how the data is parsed when read in.
If so, you can use this to skip adding a tab for the Metrics value, as it's last on the line:

```
[COLOR=Blue]30[/COLOR] If %2==METRICS (Set _%2%%I=0) Else (Set _%2%%I=0%_pad%)
```
Jerry


----------



## des000 (May 30, 2008)

Since you've refferred to line numbers in the origional code, I'm going to repost that code verbatem, but add line numbers into that. Here it is:


```
[COLOR=green][1][/COLOR]Set _pad=                   .
[COLOR=green][2][/COLOR]For %%I In (ADDRESSES NETMASKS) Do Call :_parse1 %%I _AddCount
[COLOR=green][3][/COLOR]For %%I In (GATEWAYS METRICS) Do Call :_parse1 %%I _GateCount
[COLOR=green][4][/COLOR]If !_AddCount! EQU !_GateCount! (
[COLOR=green][5][/COLOR]  Set _max=!_AddCount!
[COLOR=green][6][/COLOR]  ) Else (
[COLOR=green][7][/COLOR]  If !_AddCount! GTR !_GateCount! (
[COLOR=green][8][/COLOR]    Call :_parse2 GATEWAYS METRICS !_GateCount! !_AddCount!
[COLOR=green][9][/COLOR]    ) Else (
[COLOR=green][10][/COLOR]    Call :_parse2 ADDRESSES NETMASKS !_AddCount! !_GateCount!
[COLOR=green][11][/COLOR]))  
[COLOR=green][12][/COLOR]Echo.IP Address       NetMask          Gateway          Metric>>!CARD_CARD_IP!_Address_Info.ncnf
[COLOR=green][13][/COLOR]For /L %%I In (1,1,!_max!) Do Echo !_ADDRESSES%%I:"=!!_NETMASKS%%I:"=!!_GATEWAYS%%I:"=!!_METRICS%%I:"=!>>!CARD_CARD_IP!_Address_Info.ncnf
[COLOR=green][14][/COLOR]Goto done
[COLOR=green][15][/COLOR]::Subroutines to parse Addresses, Netmasks, Gateways, and Metrics for proper Display
[COLOR=green][16][/COLOR]:_parse1
[COLOR=green][17][/COLOR]Set _count=0
[COLOR=green][18][/COLOR]Set _tmp=!%1!
[COLOR=green][19][/COLOR]FOR %%A IN ("!_tmp:,=","!") DO (
[COLOR=green][20][/COLOR]  Set /A _count+=1
[COLOR=green][21][/COLOR]  Set _tmp=%%A%_pad%
[COLOR=green][22][/COLOR]  Set _%1!_count!=!_tmp:~0,19!
[COLOR=green][23][/COLOR])
[COLOR=green][24][/COLOR]Set %2=!_Count!&Goto :EOF
[COLOR=green][25][/COLOR]:_parse2
[COLOR=green][26][/COLOR]Set _max=%4
[COLOR=green][27][/COLOR]Set /A _tmp=%3+1
[COLOR=green][28][/COLOR]For /L %%I In (!_tmp!,1,%4) Do (
[COLOR=green][29][/COLOR]  Set _%1%%I=%_pad:~0,17%
[COLOR=green][30][/COLOR]  Set _%2%%I=%_pad:~0,17%
[COLOR=green][31][/COLOR]  )
[COLOR=green][32][/COLOR]Goto :EOF
```


----------



## des000 (May 30, 2008)

For some reason, I cannot get that last modification to work. I don't know that the trailing tab will be a problem, but just in case, and so it looks more like I want it to eventually, closer already, I DO need that tab off.

I tried it verbatem, and with modifications at that line. It does NOT remove the trailing tab. Or, it's for some reason, if it did there, the same strange error I'd gotten before if not. Sometimes when I'm coding in this language, the current code is NOT executed, but some prior code. I do NOT know why it does that, or how to fix it when it occurs. But I have seen it before, and it DOES occur sometimes.

Actually, I think that's what happened, upon reflection, because after that, I'd tried to echo %2, and was surprised to see that it didn't work. I just use notepad to code in this language, because it's readily available. Yes, I KNOW I saved it first. So maybe this code DOES work after all. Have you heard of this issue? If I could determine whether it's this issue for sure, and then if it is, fix it, and prevent it in the future, then if it's NOT that code, I could try again and see if it really works.

I've solved this issue before on accident, but I'm not sure why it happens, so I tend to just fiddle around. It would probably help though if I knew why it happens.


----------



## Squashman (Apr 4, 2003)

des000 said:


> Since you've refferred to line numbers in the origional code, I'm going to repost


NotePad++ shows the line numbers while you are editing the batch file so OutCaste doesn't have to manually put them in. It is an awesome utility that he turned me onto a couple of weeks ago. Has syntax highlighting for many programming languages. You should take a look at using it to edit your batch files. It is free.


----------



## des000 (May 30, 2008)

I heard of it on other sites while working on this, and it DOES sound good. What I did is download it. I'll install and take a look at it. If it's a really cool program, I might add it to my collection of freeware for the project I'm working on.


----------



## des000 (May 30, 2008)

The project I'm working on, by the way, does NOT refer to this project. I've got another project to find, test, and get the installation programs of some freeware that I think I want to start using on Windows XP. These are for common, varied tasks. They are tasks as varied as writing programs, writing letters, system maitenence, etc.

But it is slow, because first I have to get some other things working, like this, then I need to document every one of those programs, as far as exactly what to click to install it. I'm not wanting automatic installs yet, because it just complicates things, but later, who knows what I'll come up with. I just need to organize it all so that instead of CDs in my closet, whether freeware or otherwise, I've got programs installed ready to actually do my bidding.


----------



## TheOutcaste (Aug 8, 2007)

des000 said:


> I tried it verbatem, and with modifications at that line. It does NOT remove the trailing tab.


My bad, have to change another line as well (#22) so the trailing tab doesn't get added to lines that actually have a Metric value.

Here's the modified code that uses a single tab as a delimiter, and does not add a trailing tab. I've included the setup lines I'm using to create data to show how I'm testing with different combinations of data, so remove them before testing in your file.
There are also two lines that echo the data to the screen, so remove them as well.
I've included a screen shot from Notepad++ to show there are tabs between the data (the pale orange arrows), but none on the end of each line.

```
[COLOR=Sienna]@Echo %Off
Setlocal EnableDelayedExpansion
Set CARD_CARD_IP=TestName
If EXIST !CARD_CARD_IP!_Address_Info.ncnf Del !CARD_CARD_IP!_Address_Info.ncnf
Set ADDRESSES=192.168.100.100,192.168.200.150,1.2.3.4
Set NETMASKS=255.255.255.128,255.255.255.0,255.0.0.0
Set GATEWAYS=192.168.100.1,1.2.3.1
Set METRICS=1,3[/COLOR]
:: The following line is a single tab character on the right side of the equals sign. If copied off the web, you'll need to edit it to put in a tab
Set _pad=    
For %%I In (ADDRESSES NETMASKS) Do Call :_parse1 %%I _AddCount
For %%I In (GATEWAYS METRICS) Do Call :_parse1 %%I _GateCount
If !_AddCount! EQU !_GateCount! (
  Set _max=!_AddCount!
  ) Else (
  If !_AddCount! GTR !_GateCount! (
    Call :_parse2 GATEWAYS METRICS !_GateCount! !_AddCount!
    ) Else (
    Call :_parse2 ADDRESSES NETMASKS !_AddCount! !_GateCount!
))  
Echo.IP Address%_pad%NetMask%_pad%Gateway%_pad%Metric>>!CARD_CARD_IP!_Address_Info.ncnf
For /L %%I In (1,1,!_max!) Do Echo !_ADDRESSES%%I:"=!!_NETMASKS%%I:"=!!_GATEWAYS%%I:"=!!_METRICS%%I:"=!>>!CARD_CARD_IP!_Address_Info.ncnf
[COLOR=DeepSkyBlue]Echo.IP Address%_pad%NetMask%_pad%Gateway%_pad%Metric
For /L %%I In (1,1,!_max!) Do Echo !_ADDRESSES%%I:"=!!_NETMASKS%%I:"=!!_GATEWAYS%%I:"=!!_METRICS%%I:"=![/COLOR]
Goto done
::Subroutines to parse Addresses, Netmasks, Gateways, and Metrics for proper Display
:_parse1
Set _count=0
Set _tmp=!%1!
FOR %%A IN ("!_tmp:,=","!") DO (
  Set /A _count+=1
  If %1==METRICS (Set _%1!_count!=%%A) Else (Set _%1!_count!=%%A%_pad%)
)
Set %2=!_Count!&Goto :EOF
:_parse2
Set _max=%4
Set /A _tmp=%3+1
For /L %%I In (!_tmp!,1,%4) Do (
  Set _%1%%I=0.0.0.0%_pad%
  If %2==METRICS (Set _%2%%I=0) Else (Set _%2%%I=0.0.0.0%_pad%)
  )
Goto :EOF
:done
```
Give this a try, see how it works.

Jerry


----------



## des000 (May 30, 2008)

Thanks for posting this help. I solved this particular problem now. I just have to post the answer and close it now. But I already took the other thing down now before posting that, because I'm also going to be moving now and must take my equipment down.


----------



## Squashman (Apr 4, 2003)

_Posted via Mobile Device_
Great job to both of you on getting this solved. This is why I nominated Jerry to be a MVP.


----------



## des000 (May 30, 2008)

Okay. I just moved. As I said before, this is now solved and the files are down right now from the NAS. I am going to post the solution so that other people might also be able to benifit from it, but not until maybe tommorrow. I've just finished getting my new library card which means I've got basic e-mail and Internet access back up for now.

All the files are on my computer, I just have to dig through them and post the proper files up or nothing will make sense. Hopefully this should be tommorrow.


----------

