Sign in to follow this  
Followers 0
micr0shaft

Unable to clear/hide last item displayed on treeview

13 posts in this topic

#1 ·  Posted (edited)

This is my first GUI with Autoit and Iv been having a lot of fun using it until now, Iv wrapped my head around most of the GUI and have got the functions I need all working but I am totally stuck using treeview.

Iv managed to create a settings page for my app using Koda with a treeview on the left side to navigate the different settings pages, But when I click a different treeview item it keeps the old settings page and overlaps the new one (see pic).

post-57819-12733707809676_thumb.png

I searched on here, google and checked scripts using treeview and found nothing I was able to use im using Case $TreeView1_2 to call the pages and:

$selected2 = _GUICtrlTreeView_GetSelected($TreeView1, $TreeView1_2)

If $selected2 = True Then

"GUI COMPONENTS"

Endif

Iv tried a few different was of calling the page but when they display they all ways overlap, I tried throwing GUICtrlSetState($TreeView1_2, $GUI_HIDE) / $SW_HIDE if not selected but nothing seems to work.

Could someone please help me crack this, It has help me back for days.

Thanks a lot for any help.

Edited by micr0shaft

Share this post


Link to post
Share on other sites

micr0shaft,

Welcome to the AutoIt forum. :idea:

When you post here it always helps if you show us the code that gives the problem. Having some code to work on is a great help - it saves us having to write something from scratch - and greatly increases your chance of getting help.

So, can we have a bit more than the 4 lines above? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

micr0shaft,

Welcome to the AutoIt forum. :idea:

When you post here it always helps if you show us the code that gives the problem. Having some code to work on is a great help - it saves us having to write something from scratch - and greatly increases your chance of getting help.

So, can we have a bit more than the 4 lines above? :)

M23

Thanks A LOT for your reply Melba.

This is taken from my main form and is the section I am having probs with:

#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiStatusBar.au3>
#include <GDIPlus.au3>
#Include <GuiTreeView.au3>
#include <ButtonConstants.au3>
#include <GuiIPAddress.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "WinHTTP.au3"
#Include <GuiEdit.au3>
#Include <GuiListView.au3>
#include <File.au3>
#include <Array.au3>
#include <WinAPI.au3>
#include "RestrictControlRegExp.au3"
#include <Misc.au3>
#include <String.au3>
#include <GUIComboBox.au3>
#NoTrayIcon


; Menu From Main Form
$File = GUICtrlCreateMenu("&File")
$Settings = GUICtrlCreateMenuItem("Settings", $File)
$Exit = GUICtrlCreateMenuItem("Exit", $File)
$Help = GUICtrlCreateMenu("&Help")
$Readme = GUICtrlCreateMenuItem("Readme", $Help)
$About = GUICtrlCreateMenuItem("About", $Help)


; $SettingsOPS = GUICreate("Settings", 490, 435, 163, 193, -1, -1, $Form1) ; Normally use this line when running from main parent form
$SettingsOPS = GUICreate("Settings", 490, 435, 163, 193, -1, -1)
$GroupBox1 = GUICtrlCreateGroup("", 8, 1, 473, 393)
$TreeView1 = GUICtrlCreateTreeView(8, 8, 153, 385)
$TreeView1_0 = GUICtrlCreateTreeViewItem("General", $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem("Connection Settings", $TreeView1)
$TreeView1_2 = GUICtrlCreateTreeViewItem("Advanced", $TreeView1_1)
$TreeView1_3 = GUICtrlCreateTreeViewItem("Stealth Settings", $TreeView1)
$Button1 = GUICtrlCreateButton("&OK", 249, 403, 75, 25)
$Button2 = GUICtrlCreateButton("&Cancel", 410, 403, 75, 25)
$Button3 = GUICtrlCreateButton("&Apply", 330, 403, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)


            While 1
            $msg = GUIGetMsg()

            If $msg = $GUI_EVENT_CLOSE Then ExitLoop
            Switch $msg
            Case $GUI_EVENT_CLOSE
            Exit
            Case $Button2
            ExitLoop

Case $SettingsOPS

Case $TreeView1_1


$selected = _GUICtrlTreeView_GetSelected($TreeView1, $TreeView1_1)
If $selected = True Then
;$tstmsg = GUICtrlRead($TreeView1_1, 1)     ; Misc Crap I have tried
;If $tstmsg = "Connection Settings" Then
;while $tstmsg = "Connection Settings"


$RTRIP = _GUICtrlIpAddress_Create($SettingsOPS, 304, 248, 145, 27, -1, $WS_EX_STATICEDGE)
_GUICtrlIpAddress_Set($RTRIP, "192.168.0.1")
$CABLEIP = _GUICtrlIpAddress_Create($SettingsOPS, 312, 48, 145, 25, -1, $WS_EX_STATICEDGE)
_GUICtrlIpAddress_Set($CABLEIP, "192.168.100.1")
$CMIPTXT = GUICtrlCreateLabel("CABLE MODEM IP:", 200, 56, 104, 18)
GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
$RTRIPTXT = GUICtrlCreateLabel("ROUTER IP:", 224, 256, 69, 18)
GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
$CMUSER = GUICtrlCreateInput("", 312, 80, 145, 21)
$CMUSRTXT = GUICtrlCreateLabel("USER NAME:", 232, 80, 73, 18)
GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
$CMPWDTXT = GUICtrlCreateLabel("PASSWORD:", 232, 104, 73, 18)
GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
$CMPWD = GUICtrlCreateInput("", 312, 104, 145, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$RTRUSR = GUICtrlCreateInput("", 304, 280, 145, 21)
$RTRPWD = GUICtrlCreateInput("", 304, 304, 145, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$RTRUSRTXT = GUICtrlCreateLabel("USER NAME:", 224, 280, 73, 18)
GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
$RTRPWDTXT = GUICtrlCreateLabel("PASSWORD:", 224, 304, 73, 18)
GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
$CMGRP = GUICtrlCreateGroup("CABLE MODEM SETTINGS", 176, 24, 289, 185)
$TENETUSR = GUICtrlCreateInput("", 312, 136, 145, 21)
$TELNETPWD = GUICtrlCreateInput("", 312, 160, 145, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$TLNTUSRTXT = GUICtrlCreateLabel("TELNET USER NAME:", 184, 144, 121, 18)
GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
$TLNTPWDTXT = GUICtrlCreateLabel("TELNET PASSWORD:", 184, 168, 121, 18)
GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$RTRGRP = GUICtrlCreateGroup("ROUTER SETTINGS", 176, 224, 289, 129)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;Wend ; Misc Crap I have tried

Else





EndIf

Case $TreeView1_2

$selected2 = _GUICtrlTreeView_GetSelected($TreeView1, $TreeView1_2)
If $selected2 = True Then

;$tstmsg = GUICtrlRead($TreeView1_2, 1) ; Misc Crap I have tried
;If $tstmsg = "Advanced" Then
;while $tstmsg = "Advanced"
;MsgBox(0, "", $selected2)


$advconrtgrp = GUICtrlCreateGroup("ROUTER MAC SETTINGS", 176, 24, 289, 345)
GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
$ROUTERPOST = GUICtrlCreateInput("", 208, 208, 225, 22)
GUICtrlSetTip(-1, "THIS SHOULD CONTAIN A MAC ADDRESS AND REBOOT COMMAND (UNLESS YOUR ROUTER REBOOTS AUTOMATICALLY ON MAC CHANGE).")
$ROUTERMAC = GUICtrlCreateInput("", 272, 312, 97, 22)
GUICtrlSetTip(-1, "THIS SHOULD BE 12 CHARACTERS LONG WITHOUT ANY SPACES OR COLONS.")
$RTRPOSTTXT = GUICtrlCreateLabel("PLEASE ENTER THE HTTP POST COMMAND ", 216, 168, 212, 17)
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
GUICtrlSetTip(-1, "THIS SHOULD CONTAIN A MAC ADDRESS AND REBOOT COMMAND (UNLESS YOUR ROUTER REBOOTS AUTOMATICALLY ON MAC CHANGE).")
$RTRPOSTTXT2 = GUICtrlCreateLabel(" REQUIRED TO CHANGE YOUR ROUTERS MAC.", 208, 184, 230, 17)
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
GUICtrlSetTip(-1, "THIS SHOULD CONTAIN A MAC ADDRESS AND REBOOT COMMAND (UNLESS YOUR ROUTER REBOOTS AUTOMATICALLY ON MAC CHANGE).")
$RTRPOSTTXT3 = GUICtrlCreateLabel("", 192, 80, 4, 4)
$RTRMACTXT1 = GUICtrlCreateLabel("PLEASE ENTER THE MAC ADDRESS THAT", 224, 272, 200, 17)
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
$RTRMACTXT2 = GUICtrlCreateLabel("MUST BE IN THE ABOVE STRING.", 248, 288, 162, 17)
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
$RTRADVSETGRP = GUICtrlCreateGroup("", 192, 256, 257, 97)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group1 = GUICtrlCreateGroup("", 192, 152, 257, 97)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("", 192, 48, 257, 97)
$ROUTERPAGE = GUICtrlCreateInput("", 232, 104, 177, 22)
GUICtrlSetTip(-1, "THIS SHOULD BE THE ADDRESS AFTER THE IP ADDRESS.  E.G  MAIN.HTML / MAIN.CGI /MAIN.PHP")
$RTRPAGETXT = GUICtrlCreateLabel("PLEASE ENTER THE WEB ""PAGE"" ADDRESS", 216, 64, 208, 17)
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
$RTRPAGETXT2 = GUICtrlCreateLabel("TO SEND THE THE POST COMMAND TO", 224, 80, 192, 17)
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)

;Wend ; Misc Crap I have tried

Else

EndIf
        EndSwitch
            WEnd
            GUIDelete()

Again Thanks for your help

Edited by micr0shaft

Share this post


Link to post
Share on other sites

micr0shaft,

You just need to delete the previously created controls before you create the new ones. So you need to work out where they begin and end - I have used Dummy controls here as you can then name them suitably: :(

#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiStatusBar.au3>
#include <GDIPlus.au3>
#include <GuiTreeView.au3>
#include <ButtonConstants.au3>
#include <GuiIPAddress.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;#include "WinHTTP.au3"
#include <GuiEdit.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <Array.au3>
#include <WinAPI.au3>
;#include "RestrictControlRegExp.au3"
#include <Misc.au3>
#include <String.au3>
#include <GUIComboBox.au3>
#NoTrayIcon

Global $hTV1_1_Start, $hTV1_1_End, $hTV1_2_Start, $hTV1_2_End

; Menu From Main Form
$File = GUICtrlCreateMenu("&File")
$Settings = GUICtrlCreateMenuItem("Settings", $File)
$Exit = GUICtrlCreateMenuItem("Exit", $File)
$Help = GUICtrlCreateMenu("&Help")
$Readme = GUICtrlCreateMenuItem("Readme", $Help)
$About = GUICtrlCreateMenuItem("About", $Help)

; $SettingsOPS = GUICreate("Settings", 490, 435, 163, 193, -1, -1, $Form1) ; Normally use this line when running from main parent form
$SettingsOPS = GUICreate("Settings", 490, 435, 163, 193, -1, -1)
$GroupBox1 = GUICtrlCreateGroup("", 8, 1, 473, 393)
$TreeView1 = GUICtrlCreateTreeView(8, 8, 153, 385)
$TreeView1_0 = GUICtrlCreateTreeViewItem("General", $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem("Connection Settings", $TreeView1)
$TreeView1_2 = GUICtrlCreateTreeViewItem("Advanced", $TreeView1_1)
$TreeView1_3 = GUICtrlCreateTreeViewItem("Stealth Settings", $TreeView1)
$Button1 = GUICtrlCreateButton("&OK", 249, 403, 75, 25)
$Button2 = GUICtrlCreateButton("&Cancel", 410, 403, 75, 25)
$Button3 = GUICtrlCreateButton("&Apply", 330, 403, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            ExitLoop

        Case $SettingsOPS

        Case $TreeView1_1

            $selected = _GUICtrlTreeView_GetSelected($TreeView1, $TreeView1_1)
            If $selected = True Then

                ; Delete previous controls
                For $i = $hTV1_2_Start To $hTV1_2_End
                    GUICtrlDelete($i)
                Next

                $RTRIP = _GUICtrlIpAddress_Create($SettingsOPS, 304, 248, 145, 27, -1, $WS_EX_STATICEDGE)
                _GUICtrlIpAddress_Set($RTRIP, "192.168.0.1")
                $CABLEIP = _GUICtrlIpAddress_Create($SettingsOPS, 312, 48, 145, 25, -1, $WS_EX_STATICEDGE)
                _GUICtrlIpAddress_Set($CABLEIP, "192.168.100.1")
                ; Mark start of control creation
                $hTV1_1_Start = GUICtrlCreateDummy()
                $CMIPTXT = GUICtrlCreateLabel("CABLE MODEM IP:", 200, 56, 104, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $RTRIPTXT = GUICtrlCreateLabel("ROUTER IP:", 224, 256, 69, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $CMUSER = GUICtrlCreateInput("", 312, 80, 145, 21)
                $CMUSRTXT = GUICtrlCreateLabel("USER NAME:", 232, 80, 73, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $CMPWDTXT = GUICtrlCreateLabel("PASSWORD:", 232, 104, 73, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $CMPWD = GUICtrlCreateInput("", 312, 104, 145, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
                $RTRUSR = GUICtrlCreateInput("", 304, 280, 145, 21)
                $RTRPWD = GUICtrlCreateInput("", 304, 304, 145, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
                $RTRUSRTXT = GUICtrlCreateLabel("USER NAME:", 224, 280, 73, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $RTRPWDTXT = GUICtrlCreateLabel("PASSWORD:", 224, 304, 73, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $CMGRP = GUICtrlCreateGroup("CABLE MODEM SETTINGS", 176, 24, 289, 185)
                $TENETUSR = GUICtrlCreateInput("", 312, 136, 145, 21)
                $TELNETPWD = GUICtrlCreateInput("", 312, 160, 145, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
                $TLNTUSRTXT = GUICtrlCreateLabel("TELNET USER NAME:", 184, 144, 121, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $TLNTPWDTXT = GUICtrlCreateLabel("TELNET PASSWORD:", 184, 168, 121, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                $RTRGRP = GUICtrlCreateGroup("ROUTER SETTINGS", 176, 224, 289, 129)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                ; Mark end of control creation
                $hTV1_1_End = GUICtrlCreateDummy()

            Else

            EndIf

        Case $TreeView1_2

            $selected2 = _GUICtrlTreeView_GetSelected($TreeView1, $TreeView1_2)
            If $selected2 = True Then

                ; Delete previous controls
                For $i = $hTV1_1_Start To $hTV1_1_End
                    GUICtrlDelete($i)
                Next
                ; Destroy IP address controls
                _GUICtrlIpAddress_Destroy($RTRIP)
                _GUICtrlIpAddress_Destroy($CABLEIP)

                ; Mark start of control creation
                $hTV1_2_Start = GUICtrlCreateDummy()
                $advconrtgrp = GUICtrlCreateGroup("ROUTER MAC SETTINGS", 176, 24, 289, 345)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $ROUTERPOST = GUICtrlCreateInput("", 208, 208, 225, 22)
                GUICtrlSetTip(-1, "THIS SHOULD CONTAIN A MAC ADDRESS AND REBOOT COMMAND (UNLESS YOUR ROUTER REBOOTS AUTOMATICALLY ON MAC CHANGE).")
                $ROUTERMAC = GUICtrlCreateInput("", 272, 312, 97, 22)
                GUICtrlSetTip(-1, "THIS SHOULD BE 12 CHARACTERS LONG WITHOUT ANY SPACES OR COLONS.")
                $RTRPOSTTXT = GUICtrlCreateLabel("PLEASE ENTER THE HTTP POST COMMAND ", 216, 168, 212, 17)
                GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
                GUICtrlSetTip(-1, "THIS SHOULD CONTAIN A MAC ADDRESS AND REBOOT COMMAND (UNLESS YOUR ROUTER REBOOTS AUTOMATICALLY ON MAC CHANGE).")
                $RTRPOSTTXT2 = GUICtrlCreateLabel(" REQUIRED TO CHANGE YOUR ROUTERS MAC.", 208, 184, 230, 17)
                GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
                GUICtrlSetTip(-1, "THIS SHOULD CONTAIN A MAC ADDRESS AND REBOOT COMMAND (UNLESS YOUR ROUTER REBOOTS AUTOMATICALLY ON MAC CHANGE).")
                $RTRPOSTTXT3 = GUICtrlCreateLabel("", 192, 80, 4, 4)
                $RTRMACTXT1 = GUICtrlCreateLabel("PLEASE ENTER THE MAC ADDRESS THAT", 224, 272, 200, 17)
                GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
                $RTRMACTXT2 = GUICtrlCreateLabel("MUST BE IN THE ABOVE STRING.", 248, 288, 162, 17)
                GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
                $RTRADVSETGRP = GUICtrlCreateGroup("", 192, 256, 257, 97)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                $Group1 = GUICtrlCreateGroup("", 192, 152, 257, 97)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                $Group2 = GUICtrlCreateGroup("", 192, 48, 257, 97)
                $ROUTERPAGE = GUICtrlCreateInput("", 232, 104, 177, 22)
                GUICtrlSetTip(-1, "THIS SHOULD BE THE ADDRESS AFTER THE IP ADDRESS.  E.G  MAIN.HTML / MAIN.CGI /MAIN.PHP")
                $RTRPAGETXT = GUICtrlCreateLabel("PLEASE ENTER THE WEB ""PAGE"" ADDRESS", 216, 64, 208, 17)
                GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
                $RTRPAGETXT2 = GUICtrlCreateLabel("TO SEND THE THE POST COMMAND TO", 224, 80, 192, 17)
                GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                ; Mark end of control creation
                $hTV1_2_End = GUICtrlCreateDummy()

            Else

            EndIf
    EndSwitch
WEnd
GUIDelete()

Note that you often need special commands to delete UDF-created controls, as is the case here with the IP inputs.

Health warning: This trick depends not only on the controls being created in immediate succession, but also on their being in consecutive places in AutoIt's internal control array. If you create/delete other controls within your script while this section is running you may well find that the second condition is not true. :) In that case you will have to delete the controls individually by ControlID.

I hope that helps. :idea:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

micr0shaft,

You just need to delete the previously created controls before you create the new ones. So you need to work out where they begin and end - I have used Dummy controls here as you can then name them suitably: :)

#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiStatusBar.au3>
#include <GDIPlus.au3>
#include <GuiTreeView.au3>
#include <ButtonConstants.au3>
#include <GuiIPAddress.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;#include "WinHTTP.au3"
#include <GuiEdit.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <Array.au3>
#include <WinAPI.au3>
;#include "RestrictControlRegExp.au3"
#include <Misc.au3>
#include <String.au3>
#include <GUIComboBox.au3>
#NoTrayIcon

Global $hTV1_1_Start, $hTV1_1_End, $hTV1_2_Start, $hTV1_2_End

; Menu From Main Form
$File = GUICtrlCreateMenu("&File")
$Settings = GUICtrlCreateMenuItem("Settings", $File)
$Exit = GUICtrlCreateMenuItem("Exit", $File)
$Help = GUICtrlCreateMenu("&Help")
$Readme = GUICtrlCreateMenuItem("Readme", $Help)
$About = GUICtrlCreateMenuItem("About", $Help)

; $SettingsOPS = GUICreate("Settings", 490, 435, 163, 193, -1, -1, $Form1) ; Normally use this line when running from main parent form
$SettingsOPS = GUICreate("Settings", 490, 435, 163, 193, -1, -1)
$GroupBox1 = GUICtrlCreateGroup("", 8, 1, 473, 393)
$TreeView1 = GUICtrlCreateTreeView(8, 8, 153, 385)
$TreeView1_0 = GUICtrlCreateTreeViewItem("General", $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem("Connection Settings", $TreeView1)
$TreeView1_2 = GUICtrlCreateTreeViewItem("Advanced", $TreeView1_1)
$TreeView1_3 = GUICtrlCreateTreeViewItem("Stealth Settings", $TreeView1)
$Button1 = GUICtrlCreateButton("&OK", 249, 403, 75, 25)
$Button2 = GUICtrlCreateButton("&Cancel", 410, 403, 75, 25)
$Button3 = GUICtrlCreateButton("&Apply", 330, 403, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            ExitLoop

        Case $SettingsOPS

        Case $TreeView1_1

            $selected = _GUICtrlTreeView_GetSelected($TreeView1, $TreeView1_1)
            If $selected = True Then

                ; Delete previous controls
                For $i = $hTV1_2_Start To $hTV1_2_End
                    GUICtrlDelete($i)
                Next

                $RTRIP = _GUICtrlIpAddress_Create($SettingsOPS, 304, 248, 145, 27, -1, $WS_EX_STATICEDGE)
                _GUICtrlIpAddress_Set($RTRIP, "192.168.0.1")
                $CABLEIP = _GUICtrlIpAddress_Create($SettingsOPS, 312, 48, 145, 25, -1, $WS_EX_STATICEDGE)
                _GUICtrlIpAddress_Set($CABLEIP, "192.168.100.1")
                ; Mark start of control creation
                $hTV1_1_Start = GUICtrlCreateDummy()
                $CMIPTXT = GUICtrlCreateLabel("CABLE MODEM IP:", 200, 56, 104, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $RTRIPTXT = GUICtrlCreateLabel("ROUTER IP:", 224, 256, 69, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $CMUSER = GUICtrlCreateInput("", 312, 80, 145, 21)
                $CMUSRTXT = GUICtrlCreateLabel("USER NAME:", 232, 80, 73, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $CMPWDTXT = GUICtrlCreateLabel("PASSWORD:", 232, 104, 73, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $CMPWD = GUICtrlCreateInput("", 312, 104, 145, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
                $RTRUSR = GUICtrlCreateInput("", 304, 280, 145, 21)
                $RTRPWD = GUICtrlCreateInput("", 304, 304, 145, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
                $RTRUSRTXT = GUICtrlCreateLabel("USER NAME:", 224, 280, 73, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $RTRPWDTXT = GUICtrlCreateLabel("PASSWORD:", 224, 304, 73, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $CMGRP = GUICtrlCreateGroup("CABLE MODEM SETTINGS", 176, 24, 289, 185)
                $TENETUSR = GUICtrlCreateInput("", 312, 136, 145, 21)
                $TELNETPWD = GUICtrlCreateInput("", 312, 160, 145, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
                $TLNTUSRTXT = GUICtrlCreateLabel("TELNET USER NAME:", 184, 144, 121, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $TLNTPWDTXT = GUICtrlCreateLabel("TELNET PASSWORD:", 184, 168, 121, 18)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                $RTRGRP = GUICtrlCreateGroup("ROUTER SETTINGS", 176, 224, 289, 129)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                ; Mark end of control creation
                $hTV1_1_End = GUICtrlCreateDummy()

            Else

            EndIf

        Case $TreeView1_2

            $selected2 = _GUICtrlTreeView_GetSelected($TreeView1, $TreeView1_2)
            If $selected2 = True Then

                ; Delete previous controls
                For $i = $hTV1_1_Start To $hTV1_1_End
                    GUICtrlDelete($i)
                Next
                ; Destroy IP address controls
                _GUICtrlIpAddress_Destroy($RTRIP)
                _GUICtrlIpAddress_Destroy($CABLEIP)

                ; Mark start of control creation
                $hTV1_2_Start = GUICtrlCreateDummy()
                $advconrtgrp = GUICtrlCreateGroup("ROUTER MAC SETTINGS", 176, 24, 289, 345)
                GUICtrlSetFont(-1, 9, 400, 0, "Tahoma")
                $ROUTERPOST = GUICtrlCreateInput("", 208, 208, 225, 22)
                GUICtrlSetTip(-1, "THIS SHOULD CONTAIN A MAC ADDRESS AND REBOOT COMMAND (UNLESS YOUR ROUTER REBOOTS AUTOMATICALLY ON MAC CHANGE).")
                $ROUTERMAC = GUICtrlCreateInput("", 272, 312, 97, 22)
                GUICtrlSetTip(-1, "THIS SHOULD BE 12 CHARACTERS LONG WITHOUT ANY SPACES OR COLONS.")
                $RTRPOSTTXT = GUICtrlCreateLabel("PLEASE ENTER THE HTTP POST COMMAND ", 216, 168, 212, 17)
                GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
                GUICtrlSetTip(-1, "THIS SHOULD CONTAIN A MAC ADDRESS AND REBOOT COMMAND (UNLESS YOUR ROUTER REBOOTS AUTOMATICALLY ON MAC CHANGE).")
                $RTRPOSTTXT2 = GUICtrlCreateLabel(" REQUIRED TO CHANGE YOUR ROUTERS MAC.", 208, 184, 230, 17)
                GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
                GUICtrlSetTip(-1, "THIS SHOULD CONTAIN A MAC ADDRESS AND REBOOT COMMAND (UNLESS YOUR ROUTER REBOOTS AUTOMATICALLY ON MAC CHANGE).")
                $RTRPOSTTXT3 = GUICtrlCreateLabel("", 192, 80, 4, 4)
                $RTRMACTXT1 = GUICtrlCreateLabel("PLEASE ENTER THE MAC ADDRESS THAT", 224, 272, 200, 17)
                GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
                $RTRMACTXT2 = GUICtrlCreateLabel("MUST BE IN THE ABOVE STRING.", 248, 288, 162, 17)
                GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
                $RTRADVSETGRP = GUICtrlCreateGroup("", 192, 256, 257, 97)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                $Group1 = GUICtrlCreateGroup("", 192, 152, 257, 97)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                $Group2 = GUICtrlCreateGroup("", 192, 48, 257, 97)
                $ROUTERPAGE = GUICtrlCreateInput("", 232, 104, 177, 22)
                GUICtrlSetTip(-1, "THIS SHOULD BE THE ADDRESS AFTER THE IP ADDRESS.  E.G  MAIN.HTML / MAIN.CGI /MAIN.PHP")
                $RTRPAGETXT = GUICtrlCreateLabel("PLEASE ENTER THE WEB ""PAGE"" ADDRESS", 216, 64, 208, 17)
                GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
                $RTRPAGETXT2 = GUICtrlCreateLabel("TO SEND THE THE POST COMMAND TO", 224, 80, 192, 17)
                GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                ; Mark end of control creation
                $hTV1_2_End = GUICtrlCreateDummy()

            Else

            EndIf
    EndSwitch
WEnd
GUIDelete()

Note that you often need special commands to delete UDF-created controls, as is the case here with the IP inputs.

Health warning: This trick depends not only on the controls being created in immediate succession, but also on their being in consecutive places in AutoIt's internal control array. If you create/delete other controls within your script while this section is running you may well find that the second condition is not true. :( In that case you will have to delete the controls individually by ControlID.

I hope that helps. :idea:

M23

Amazing thank you :)

I spend the best part of 2 nights searching for that lol.

I was having problems if I selected the advanced tree item before connection settings, It would crash out with undeclared variable error for :

_GUICtrlIpAddress_Destroy($RTRIP)

_GUICtrlIpAddress_Destroy($CABLEIP)

Fixed it by making it global, But still displays incorrectly if you click the treeview item repeatedly the IpAdress's overlap them both.

But I think ill drop them for standard input boxes with _RegEx_RestrictControl limits.

Again thanks Melba, I was tearing my hair out over this one.

By any chance would you know how/if it would be possible to extract mac address from an unknown string if you know the mac address already?

For example:

0=0&1=0&2=0&3=0&4=&5=&6=&7=&8=&9=&10=00&11=22&12=72&13=90&14=AC&15=03&16=00&17=F4&18=7B&19=09&20=44&21=C5&Save=++Save++

If I wanted my app to change just the following in to variables from the above string and keep the rest of the string intact: 00 22 72 90 AC 03

So it would look like:

"0=0&1=0&2=0&3=0&4=&5=&6=&7=&8=&9=&" & "10=00" & "&11=" & $RTMAC0 & $RTMAC1 & "&12=" & $RTMAC2 & $RTMAC3 & "&13=" & $RTMAC4 & $RTMAC5 & "&14=" & $RTMAC6 & $RTMAC7 & "&15=" & $RTMAC8 & $RTMAC9 & "&16=00&17=02&18=5D&19=62&20=98&21=B0&Save=++Save++"

The problem is the above string is the HTTP POST code to change the mac on my router but I want the app to work for other peoples routers.

So by providing them with a input to enter their own HTTP POST code for their router and a input to enter the same mac that is in the POST string for reference, Would the be a way of getting my app to replace the existing mac from the POST string and convert each letter/number of only the mac into $vars?

Sorry if that was long winded.

Share this post


Link to post
Share on other sites

micr0shaft,

Yes, declaring them as Global was the right solution. :idea:

Two ways to get your string intermingled:

$sString = "0=0&1=0&2=0&3=0&4=&5=&6=&7=&8=&9=&10=00&11=22&12=72&13=90&14=AC&15=03&16=00&17=F4&18=7B&19=09&20=44&21=C5&Save=++Save++"

$sRTMAC = "ab cd ef gh ij kl"

; First example - breaking into single digits
$aRTMAC = StringSplit(StringStripWS($sRTMAC, 8), "")
$sReplace = $sString
For $i = 1 To 6
    $iIndex = StringInStr($sReplace, "&" & String(9 + $i))
    $sReplace = StringMid($sReplace, 1, $iIndex + 3) & $aRTMAC[($i * 2) - 1] & $aRTMAC[($i * 2)] & StringMid($sReplace, $iIndex + 6)
Next
ConsoleWrite($sReplace & @CRLF)

; Second example - breaking into pairs of digits
$aRTMAC = StringSplit($sRTMAC, " ")
$sReplace = $sString
For $i = 1 To 6
    $iIndex = StringInStr($sReplace, "&" & String(9 + $i))
    $sReplace = StringMid($sReplace, 1, $iIndex + 3) & $aRTMAC[$i] & StringMid($sReplace, $iIndex + 6)
Next
ConsoleWrite($sReplace & @CRLF)

I changed the IP address into letters so you could see the result more clearly.

I hope that does what you want - the last post might have been longwinded, but it was not entirely clear! :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

micr0shaft,

Yes, declaring them as Global was the right solution. :idea:

Two ways to get your string intermingled:

$sString = "0=0&1=0&2=0&3=0&4=&5=&6=&7=&8=&9=&10=00&11=22&12=72&13=90&14=AC&15=03&16=00&17=F4&18=7B&19=09&20=44&21=C5&Save=++Save++"

$sRTMAC = "ab cd ef gh ij kl"

; First example - breaking into single digits
$aRTMAC = StringSplit(StringStripWS($sRTMAC, 8), "")
$sReplace = $sString
For $i = 1 To 6
    $iIndex = StringInStr($sReplace, "&" & String(9 + $i))
    $sReplace = StringMid($sReplace, 1, $iIndex + 3) & $aRTMAC[($i * 2) - 1] & $aRTMAC[($i * 2)] & StringMid($sReplace, $iIndex + 6)
Next
ConsoleWrite($sReplace & @CRLF)

; Second example - breaking into pairs of digits
$aRTMAC = StringSplit($sRTMAC, " ")
$sReplace = $sString
For $i = 1 To 6
    $iIndex = StringInStr($sReplace, "&" & String(9 + $i))
    $sReplace = StringMid($sReplace, 1, $iIndex + 3) & $aRTMAC[$i] & StringMid($sReplace, $iIndex + 6)
Next
ConsoleWrite($sReplace & @CRLF)

I changed the IP address into letters so you could see the result more clearly.

I hope that does what you want - the last post might have been longwinded, but it was not entirely clear! :)

M23

Im sorry about not being clear ill try better :(

The problem is the $sString in your above example will have different contents and be different lengths for each person using the program with them having different routers thus different $sString's.

What I need it to do is recognise and change just the 12 digit mac within the "random" string in to one variable per digit.

I hoped to achieve this by providing two input boxes for the user, One for the POST command ($sString) and another for the 12 digit mac that is also in the POST command ($sString)

To hopefully have the app locate the mac within the $sString (bearing in mind there may be other matching digits from the mac else where in the $sString.

Ultimately the mac within the $sString will be randomised and sent to the router.

Is this doable?

Thanks for taking the time

Share this post


Link to post
Share on other sites

micr0shaft,

A bit clearer - so I hope that this is what you want: :idea:

$sString = "0=0&1=0&2=0&3=0&4=&5=&6=&7=&8=&9=&10=00&11=22&12=72&13=90&14=AC&15=03&16=00&17=F4&18=7B&19=09&20=44&21=C5&Save=++Save++"

$sRTMAC = "00 22 72 90 AC 03"

; Split RTMAC into single digits
$aRTMAC = StringSplit(StringStripWS($sRTMAC, 8), "")

; Create pattern
$sPattern = ".+=" & $aRTMAC[1] & $aRTMAC[2] & ".+=" & $aRTMAC[3] & $aRTMAC[4] & ".+=" & $aRTMAC[5] & $aRTMAC[6] & ".+=" & $aRTMAC[7] & $aRTMAC[8] & ".+=" & $aRTMAC[9] & $aRTMAC[10] & ".+=" & $aRTMAC[11] & $aRTMAC[12]

; Check if it exists
$aResult = StringRegExp($sString, $sPattern, 1)
If Not @error Then
    ; Get start point of remainder of string
    $iRemainder = @extended
    ; Get end point of found string
    $iEnd = $iRemainder - 1
    ; Get found string
    $sTemp = $aResult[0]
    ; Start constructing final string with the final RTMAC variables
    $sFinalString = ' & $aRTMAC[11] & $aRTMAC[12]'
    ; Move back through found string
    For $i = 10 To 2 Step -2
        ; Remove current RTMAC pair at end
        $sTemp = StringTrimRight($sTemp, 2)
        ; Get current length
        $iLen = StringLen($sTemp)
        ; Look for next &
        $iStart = StringInStr($sTemp, "&", 0, -1)
        ; Prepend next RTMAC variables and the intervening "&#=" chars to final string
        $sFinalString = '& $aRTMAC[' & $i - 1 & '] & $aRTMAC[' & $i & '] & "' & StringMid($sTemp, $iStart, $iEnd - $iStart) & '" ' & $sFinalString
        ; Trim the "&#=" chars from the string
        $sTemp = StringTrimRight($sTemp, $iEnd - $iStart - 1)
        ; Move counter
        $iEnd = $iStart - 1
    Next
    ; Remove final RTMAC pair
    $sTemp = StringTrimRight($sTemp, 2)
    ; Complete final string by prepending what is left and appending what was left off
    $sFinalString = '"' & $sTemp & '" ' & $sFinalString & ' & "' & StringMid($sString, $iRemainder) & '"'

    ; Display string
    ConsoleWrite($sFinalString & @CRLF)

Else
    ; Error!
    ConsoleWrite("Error" & @CRLF)
EndIf

Are we there yet? :(

M23

P.S. When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. :)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Closer :idea:

When the $sString is for example this: telnet=0,downlink=on,1=00,2=22,3=72,4=90,5=AC,6=03,setting=on,save=yes

It replaces the mac ok and appends the end but the beginning is lost.

"" & $aRTMAC[1] & $aRTMAC[2] & "" & $aRTMAC[3] & $aRTMAC[4] & "" & $aRTMAC[5] & $aRTMAC[6] & "" & $aRTMAC[7] & $aRTMAC[8] & "" & $aRTMAC[9] & $aRTMAC[10] & ""  & $aRTMAC[11] & $aRTMAC[12] & ",setting=on,save=yes"

Share this post


Link to post
Share on other sites

micr0shaft,

If you do not give me the full picture how am I supposed to work out valid solutions? :idea: Everything you have shown so far uses "&" as a delimiter, now you say you might have "," as well.

Before I spend any more time on this, are there any other delimiters I need to code for? Bear in mind that I have no idea what you are actually talking about ( and please do not bother to explain) so I am basing my code entirely on what you post. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Sorry if I have annoyed you?

As I said in my above post "The problem is the $sString in your above example will have different contents and be different lengths for each person using the program with them having different routers thus different $sString's."

That's the problem there are so many routers there is no way of knowing what the delimiter will be for each one.

The "," I used was just me testing different things.

Share this post


Link to post
Share on other sites

micr0shaft,

Sorry if I have annoyed you

Not really - I just do not like having goalposts changed in mid-match! :)

Now, I have made the assumption that the string will always be of this format:

.....(Some_chars)=(Possible alphanumeric)delimiter(Some_chars)=(Possible alphanumeric)delimiter(Some_chars)=(Possible alphanumeric)delimiter(Some_chars)=(Possible alphanumeric).....

This script works out what delimiter the string is using and then does its work based on that.

$sString_1 = "0=0&1=0&2=0&3=0&4=&5=&6=&7=&8=&9=&10=00&11=22&12=72&13=90&14=AC&15=03&16=00&17=F4&18=7B&19=09&20=44&21=C5&Save=++Save++"

$sString_2 = "telnet=0,downlink=on,1=00,2=22,3=72,4=90,5=AC,6=03,setting=on,save=yes"

$sRTMAC = "00 22 72 90 AC 03"

$sResult_1 = _Create_String($sString_1, $sRTMAC)
ConsoleWrite($sResult_1 & @CRLF)

$sResult_2 = _Create_String($sString_2, $sRTMAC)
ConsoleWrite($sResult_2 & @CRLF)

Func _Create_String($sString, $sRTMAC)

    ; Split RTMAC into single digits
    $aRTMAC = StringSplit(StringStripWS($sRTMAC, 8), "")

    ; Create patterns
    $sPattern_Part = ""
    For $i = 1 To 9 Step 2
        $sPattern_Part &= ".+=" & $aRTMAC[$i] & $aRTMAC[$i + 1]
    Next
    $sPattern_Full = $sPattern_Part & ".+=" & $aRTMAC[$i] & $aRTMAC[$i + 1]

    ; Check if it exists
    $aResult = StringRegExp($sString, $sPattern_Full, 1)
    If Not @error Then
        ; Get start point of remainder of string
        $iRemainder = @extended

        ; Check part pattern
        StringRegExp($sString, $sPattern_Part, 1)
        ; Get delimiter character
        $sDelimiter = StringMid($sString, @extended, 1)
        ; Get end point of found string
        $iEnd = $iRemainder - 1
        ; Get found string
        $sTemp = $aResult[0]

        ; Start constructing final string with the final RTMAC variables
        $sFinalString = ' & $aRTMAC[11] & $aRTMAC[12]'
        ; Move back through found string
        For $i = 10 To 2 Step -2
            ; Remove current RTMAC pair at end
            $sTemp = StringTrimRight($sTemp, 2)
            ; Get current length
            $iLen = StringLen($sTemp)
            ; Look for next &
            $iStart = StringInStr($sTemp, $sDelimiter, 0, -1)
            ; Prepend next RTMAC variables and the intervening "&#=" chars to final string
            $sFinalString = '& $aRTMAC[' & $i - 1 & '] & $aRTMAC[' & $i & '] & "' & StringMid($sTemp, $iStart, $iEnd - $iStart) & '" ' & $sFinalString
            ; Trim the "&#=" chars from the string
            $sTemp = StringTrimRight($sTemp, $iEnd - $iStart - 1)
            ; Move counter
            $iEnd = $iStart - 1
        Next
        ; Remove final RTMAC pair
        $sTemp = StringTrimRight($sTemp, 2)
        ; Complete final string by prepending what is left and appending what was left off
        $sFinalString = '"' & $sTemp & '" ' & $sFinalString & ' & "' & StringMid($sString, $iRemainder) & '"'

        ; Return string
        Return $sFinalString

    Else
        ; Error!
        Return SetError(1, 0, "")
    EndIf

EndFunc

As you can see, it works for the 2 strings you provided. If the string follows the pattern as I set out above, it should work for any delimiter (assuming the delimiter is not found elsewhere in the string, which seems pretty reasonable).

I hope that is the solution you were looking for. :idea:

m23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Unlike M23, I'm still not sure of what you want but lets give this a try.

#Include<array.au3> ;; Display purposes only

$sString_1 = "0=0&1=0&2=0&3=0&4=&5=&6=&7=&8=&9=&10=00&11=22&12=72&13=90&14=AC&15=03&16=00&17=F4&18=7B&19=09&20=44&21=C5&Save=++Save++"
$sString_2 = "telnet=0,downlink=on,1=00,2=22,3=72,4=90,5=AC,6=03,setting=on,save=yes"
$aString_1 = StringRegExp($sString_1, "(?i)([a-z\d=]+)(?:" & _GetSep($sString_1) & "|$)", 3)
$aString_2 = StringRegExp($sString_2, "(?i)([a-z\d=]+)(?:" & _GetSep($sString_2) & "|$)", 3)
_ArrayDisplay($aString_1, "String 1")
_ArrayDisplay($aString_2, "String 2")

Func _GetSep($s_Str)
    Return StringRegExpReplace($s_Str, "(?i)(?:[a-z\d=])+([[:punct:]]).+", "$1")
EndFunc

Edit: Fixed typo in code

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0