Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Location
    Somewhere in Texas, USA
    Posts
    417

    Parsing an IP address and manipulating it.....

    I am using AMS5 and am trying to create an application to automate a printer setup using an HP print Server. Problem is that in order to make it work I need to be able to take an IP address (DHCP) and make a few changes and re-assemble the IP address and import changes to the registry.

    Example:

    10.175.55.123 being the IP addy of the system the app would be running on.

    I need to take that IP and change the last oct (123) to (142). Then take the second oct (175) and subtract 64 which would give me (111) and then re-assemble that info into new IP 10.111.55.142. This is just an example of one location where this would be ran. The 2nd, 3rd and 4th octs will change from location to location.

    I have tried every string function and stilll not having any luck.

    I would GREATLY appreciate it if one of you guru's could point me in the right direction.

    Thanks in Advance

  2. #2
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    Code:
    function DelimitedStringToTable(DelimitedString, Delimiter)
    	tbReturn = {};
    	local strWorking;
    	local nPos = nil;
    	local strData;
    	local nTableIndex = 1;
    	local nDelimiterLength = String.Length(Delimiter);
    	
    	if(nDelimiterLength < 1)then
    		tbReturn[nTableIndex] = DelimitedString;
    		return tbReturn;
    	end
    	
    	strWorking = DelimitedString;
    	nPos = String.Find(strWorking,Delimiter);
    	while(nPos ~= -1)do
    		strData = String.Left(strWorking,nPos-1);
    		tbReturn[nTableIndex] = strData;
    		nTableIndex = nTableIndex + 1;
    		local nLength = String.Length(strWorking);
    		strWorking = String.Right(strWorking,nLength - (nPos + (nDelimiterLength-1)));
    		nPos = String.Find(strWorking,Delimiter);
    	end
    	if(strWorking ~= "")then
    		tbReturn[nTableIndex] = strWorking;
    	end
    	
    	return tbReturn;
    end
    
    sIPAddress = "10.175.55.123"
    tblOctets = DelimitedStringToTable(sIPAddress, ".")
    tblOctets[4] = 142
    tblOctets[2] = String.ToNumber(tblOctets[2]) - 64
    
    sNewIPAddress = Table.Concat(tblOctets, ".")
    Dialog.Message("IP Address", sNewIPAddress)

  3. #3
    Join Date
    Aug 2004
    Location
    Somewhere in Texas, USA
    Posts
    417
    Thanks, Worm!

    I tried your code and it works flawlessly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts