Help regarding a string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • mrdude
    Forum Member
    • Jun 2004
    • 143

    Help regarding a string

    I wonder if someone can help me with this:

    currently my small app gets a mac address from an input box, now say the mac is in this format 001122334455 - my app changes it to 00:11:22:33:44:55 by checking the length when ctrl is pressed.

    Code:
    if e_Key == 17 then
    
    checkit = Input.GetText("Inputmac");
    
    if String.Length(checkit) == 17 then
    
    --do nothing
    
    elseif String.Length(checkit) <= 16 then
    
    result = String.Mid(checkit, 1, 2);
    result2 = String.Mid(checkit, 3, 2);
    result3 = String.Mid(checkit, 5, 2);
    result4 = String.Mid(checkit, 7, 2);
    result5 = String.Mid(checkit, 9, 2);
    result6 = String.Mid(checkit, 11, 2);
    
    Input.SetText("Inputmac", result .. ":" .. result2 .. ":" .. result3 .. ":" .. result4 .. ":" .. result5 .. ":" .. result6);
    end
    end
    I'd like to change the way it checks though, so instead of using length it searches to see if the character ":" (excluding quotes) is used - if it is it does nothing and if it isn't it adds it - just like the code above.

    However I can seem to find the way in apms to do this - if anyone has any idea that would be good if you could point me in the right direction - thanks.
  • jackdaniels
    No longer a forum member
    • Mar 2007
    • 533

    #2
    1. Find the registry key for your adapter [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Cl ass\
    2. Find the ID of your network adapter
    example: devcon hwids PCI\VEN*

    then use simple script to mask it... NOT TESTED

    Code:
    @echo off
    set ip=182.31.24.21
    set mac=4C0010524026
    set interface=Local Area Network
    set mask=255.255.255.0
    set gateway=182.31.24.1
    set dns1=212.221.112.2
    rem ======================
    set metric=0
    set mac_reg=[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0002]
    devcon disable PCI\VEN_10EC
    echo Windows Registry Editor Version 5.00 > tmp%interface%.reg
    echo %mac_reg% >> tmp%interface%.reg
    echo "networkaddress"="%mac%" >> tmp%interface%.reg
    regedit /s tmp%interface%.reg
    del tmp%interface%.reg
    netsh interface ip set address name=%interface% static %ip% %mask% %gateway% %metric%
    netsh interface ip set dns name=%interface% static %dns1%
    devcon enable PCI\VEN_10EC

    Comment

    • Desrat
      Forum Member
      • Nov 2006
      • 240

      #3
      Code:
      if e_Key == 17 then
      
      checkit = Input.GetText("Inputmac");
      
      [COLOR="Red"][B]nSearch = String.Find(checkit, ":", 1, false);
      
      	if nSearch ~= -1 then
      [/B][/COLOR]
      		if String.Length(checkit) == 17 then
      
      			--do nothing
      
      		elseif String.Length(checkit) <= 16 then
      
      		result = String.Mid(checkit, 1, 2);
      		result2 = String.Mid(checkit, 3, 2);
      		result3 = String.Mid(checkit, 5, 2);
      		result4 = String.Mid(checkit, 7, 2);
      		result5 = String.Mid(checkit, 9, 2);
      		result6 = String.Mid(checkit, 11, 2);
      
      		Input.SetText("Inputmac", result .. ":" .. result2 .. ":" .. result3 .. ":" .. result4 .. ":" .. result5 .. ":" .. result6);
      
      		end
      
      	[B][COLOR="Red"]end[/COLOR][/B]
      	
      end

      Comment

      • mrdude
        Forum Member
        • Jun 2004
        • 143

        #4
        Thanks guys, that's great & much appreciated. Cheers

        Comment

        Working...
        X