Jump to content

Variable problem!Please help...


AoRaToS
 Share

Recommended Posts

Ok, I use a function to make lets say 2 child GUI, the same function, only difference is the title which is a different ip address... ofcourse the buttons on the first one stop working because the variables are now assigned to the second window, so how can I set the variables I want somewhat dynamicaly, something like:

$ipaddress & $Okbutton = GUICtrlCreate.... or so so that each ok button is different,so then if I get the window title & $okbutton i have the one I want...It sounds stupid maybe but I can't do it :/

the second part doesn't have to be a variable,just a word to recognise it,so $ipaddress & "ok" would be fine....How can I do that??

This ofcourse doesn't work:

$chatgetclientid & "." & $MessageShow = GUICtrlCreateEdit('', 7, 5, 386, 130,$ES_AUTOVSCROLL+$WS_VSCROLL+$ES_MULTILINE+$ES_READONLY)

This doesn't either:

$chatgetclientid & "MessageShow" = GUICtrlCreateEdit('', 7, 5, 386, 130,$ES_AUTOVSCROLL+$WS_VSCROLL+$ES_MULTILINE+$ES_READONLY)

So what I need is each child window to have it's own variables for buttons,editboxes and the rest...

The GUIs are the same, the problem is I don't know how many they are beforehand and also I don't know their names,the name are a computer name and an IP address for every window...

I thought of an array but I'll still need to create different variables for each child created, If I can do that then I'll see to it that the variables contain the IP and then all is easy cause I just use the ip part of the let's say 2xvariable to act,so $ipaddress + Edit would mean 192.168.0.1_Edit for one GUI and 192.168.0.3_Edit for another, then if I just send to $sendIP & "_Edit" I have the Edit I want to use... :/ but I can't seem to be able to do that...

I can show you my code as an example but you'll need 2 computers on a lan to test it and 3 to see the problem I have.(i found the problem at work and now I'm trying on my pc,a vmware and a second pc I use through netOP)

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

Link to comment
Share on other sites

I saw that you had asked this before... waited and asked again...

Hope this helps

Dim $count = 0
Dim $GUI[1], $button[1]

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F9}", "New_GUI")

ToolTip("Press *F9* to create a new GUI" & @CRLF & "Press *ESC* to Exit this program", 10, 10, "...Valuater 8)", 1)

New_GUI()

While 1
    $Msg = GUIGetMsg()
    
    For $x = 0 To UBound($GUI) - 1
        If $Msg = $button[$x] Then GUIDelete($GUI[$x])
        ; other buttons... etc!!!
    Next
    
WEnd

Func New_GUI()
    $count += 1
    ReDim $GUI[$count], $button[$count]
    $GUI[$count - 1] = GUICreate("GUI #" & $count)
    $button[$count - 1] = GUICtrlCreateButton("EXIT GUI " & $count, 150, 200, 100, 40)
    ; other buttons etc.....
    WinMove($GUI[$count - 1], "", $count * 20, $count * 20)
    GUISetState()
EndFunc   ;==>New_GUI

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

8)

NEWHeader1.png

Link to comment
Share on other sites

I will try and use some of this but I will probably need an array to keep IP's and GUI numbers...Thanks allot for your help!!

Edit: I put $MainEdit[$chatgetclientip] in my code,I'll give it a try tomorrow as it's 01:51 here in Greece and I have to go to work in the morning...

then if i use $MainEdit[$nudgegetip] in another function and the get ip is the same it'll point at the same control so it'll work,hopefully...I'll let you know my friend!!

Edited by AoRaToS

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

Link to comment
Share on other sites

$count will keep the array for all of the IP's, GUI's, Buttons and Edits and more!!

***** THIS WILL ERROR AFTER 12 GUI's *********

I only made 12 IP numbers is why, you can read them from a file or ???

Dim $count = 0
Dim $GUI[1], $button[1], $edit[1]

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F9}", "New_GUI")

ToolTip("Press *F9* to create a new GUI" & @CRLF & "Press *ESC* to Exit this program", 10, 10, "...Valuater 8)", 1)

; as an example
; get you IP numbers
$IP = StringSplit("221.199.332,212.555.645,199.222.333,456.121.456,525.323.565,111.545.898,221.199.332,212.555.645,199.222.333,456.121.456,525.323.565,111.545.898", ",")

New_GUI()

While 1
    $Msg = GUIGetMsg()

    For $x = 1 To UBound($GUI) - 1
        If $Msg = $button[$x] Then GUIDelete($GUI[$x])
        ; other buttons... etc!!!
    Next

WEnd

Func New_GUI()
    $count += 1
    ReDim $GUI[$count], $button[$count], $edit[$count]
    $GUI[$count - 1] = GUICreate("GUI #" & $count & "    IP #" & $IP[$count])
    $button[$count - 1] = GUICtrlCreateButton("EXIT GUI " & $count, 150, 300, 100, 40)
    $edit[$count - 1] = GUICtrlCreateEdit("IP = " & $IP[$count], 10, 20, 380, 200)
    ; other buttons etc.....
    WinMove($GUI[$count - 1], "", $count * 20, $count * 20)
    GUISetState()
EndFunc   ;==>New_GUI

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

I'm not reading the ip's from a file, let me explain, I've made a messenger program over lan, something like msn,simple,you log on the rest see you log on,your name-ip appears in there list and their names-ip in your list.You double click the name - ip and that creates a chat window using the name-ip taken from the list to set the title,you write something and click send and it sends it to the address that's in the title so that it goes where it should, it works great with 2 people2, then when the other one receives a message with the right specifications TEXTname-ip if a window with the name-ip doesn't exist it creates it and shows the message where it should,there is 1 function for creating the windows when it receives a message and it uses a few single variables, like this:

$ChildGUI = GUICreate($chatgetclientid, 400, 250, 0, 0, Default, $WS_EX_MDICHILD, $MainGUI)
$MainEdit = GUICtrlCreateEdit('', 5, 140, 390, 80, $ES_MULTILINE)
$MessageShow = GUICtrlCreateEdit('', 7, 5, 386, 130, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_MULTILINE + $ES_READONLY)
$Nudgebtn = GUICtrlCreateButton("Nudge", 264, 222, 60, 25)
GUICtrlSetOnEvent($Nudgebtn, "Nudge")
$Sendbtn = GUICtrlCreateButton("Send", 334, 222, 60, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent($Sendbtn, "Sendtext")

The problem as you can see is when a second window is created it uses these same variables so they aren't assigned to the first one anymore and it stops responding,you can't send or do anything...so if I have to windows: window1 and window2 (the second being the latest) if I receive something for window1 it will be put on $MessageShow which would be ok for just one window but won't work for more that one cause the text will be put on window2.

So when the message is received I need to take the ip from inside it (I know how to do that,I use it already) and if the window exists send the text to the $MessageShow (ip) or if it doesn't exist, create the gui using the variables containing that ip so that i can send to them later,I don't know if you get it, I can send you my code but over a pm.

All the problem is with the variables but I think I can work it out just with your example,If I can't we can escalate - go further, I like trying on my own cause I learn allot in the process, you gave me a clue abut variables that I didn't know, now it's my turn to try ;)

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

Link to comment
Share on other sites

Good to see that someone really "wants" to learn...

Because you are using "on-event" mode

be sure to check this out,

here is ONE way to handle multiple control id events

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Opt("GUIOnEventMode", 1)

Global $SSB = StringSplit("1|2|3|4|5|6|7|8|9|-|0|+|/|*|.|C|%|=", "|"), $bX = 8, $bY = 40

$Form1 = GUICreate("Lc", 108, 233, 193, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close", $Form1)
GUISetBkColor(0xFFFF00)
$som = GUICtrlCreateInput("", 8, 8, 89, 21)
For $i = 1 To $SSB[0]
    GUICtrlCreateButton($SSB[$i], $bX, $bY, 27, 25, $BS_CENTER)
    GUICtrlSetOnEvent(-1, "Event")
    GUICtrlSetFont(-1, 10, 700, 0, "MS Sans Serif")
    If Not Mod($i, 3) Then
        $bX = 8
        $bY += 32
    Else
        $bX += 32
    EndIf
Next
$SSB = 0
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func Event()
    Switch GUICtrlRead(@GUI_CtrlId)
        Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-", "*", "/", "."
            GUICtrlSetData($som,  GUICtrlRead($som) & GUICtrlRead(@GUI_CtrlId))
        Case "="
            If Execute(GUICtrlRead($som)) Then GUICtrlSetData($som, Execute(GUICtrlRead($som)))
            if Not ProcessExists('notepad.exe') Then Run('notepad.exe')
            WinActivate("Untitled")
            WinWaitActive("Untitled")
            ControlSend("Untitled", "", "Edit1", GUICtrlRead($som))
        Case "C"
            GUICtrlSetData($som, "")
        Case "%"
            ;??? Percent, leave this one for you tongue.gif
    EndSwitch
EndFunc

Func Close()
    Exit
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

This is the function I call to create each child window

Func Messagesend()
    If WinExists($chatname, "") Then
        WinActivate($chatname, "")
    Else
        $Stripchatdots = StringStripWS($chatname, 8)
        $chatwinipname = StringSplit($Stripchatdots, ":")
        $chatwinname = $chatwinipname[1]
        $chatwinip = $chatwinipname[2]
        $ChildGUI = GUICreate($chatname, 400, 250, 0, 0, Default, $WS_EX_MDICHILD, $MainGUI)
        $MainEdit = GUICtrlCreateEdit('', 5, 140, 390, 80, $ES_MULTILINE)
        $MessageShow = GUICtrlCreateEdit('', 7, 5, 386, 130, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_MULTILINE + $ES_READONLY)
        $Nudgebtn = GUICtrlCreateButton("Nudge", 264, 222, 60, 25)
        GUICtrlSetOnEvent($Nudgebtn, "Nudge")
        $Sendbtn = GUICtrlCreateButton("Send", 334, 222, 60, 25, $BS_DEFPUSHBUTTON)
        GUICtrlSetOnEvent($Sendbtn, "Sendtext")
        GUISetOnEvent($GUI_EVENT_CLOSE, "WindowClose")
        GUISetState(@SW_SHOW)
    EndIf
EndFunc

how can I set $MainEdit, $MessageShow and the rest be specific for each child GUI created, it wuld be easy if I could distinguish them by the $chatwinip...

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

Link to comment
Share on other sites

This is the function I call to create each child window

Func Messagesend()
    If WinExists($chatname, "") Then
        WinActivate($chatname, "")
    Else
        $Stripchatdots = StringStripWS($chatname, 8)
        $chatwinipname = StringSplit($Stripchatdots, ":")
        $chatwinname = $chatwinipname[1]
        $chatwinip = $chatwinipname[2]
        $ChildGUI = GUICreate($chatname, 400, 250, 0, 0, Default, $WS_EX_MDICHILD, $MainGUI)
        $MainEdit = GUICtrlCreateEdit('', 5, 140, 390, 80, $ES_MULTILINE)
        $MessageShow = GUICtrlCreateEdit('', 7, 5, 386, 130, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_MULTILINE + $ES_READONLY)
        $Nudgebtn = GUICtrlCreateButton("Nudge", 264, 222, 60, 25)
        GUICtrlSetOnEvent($Nudgebtn, "Nudge")
        $Sendbtn = GUICtrlCreateButton("Send", 334, 222, 60, 25, $BS_DEFPUSHBUTTON)
        GUICtrlSetOnEvent($Sendbtn, "Sendtext")
        GUISetOnEvent($GUI_EVENT_CLOSE, "WindowClose")
        GUISetState(@SW_SHOW)
    EndIf
EndFunc

how can I set $MainEdit, $MessageShow and the rest be specific for each child GUI created, it wuld be easy if I could distinguish them by the $chatwinip...

I think you need to use arrays so the first child guyi is $ChildGui[0], and it has $MainEdit[0] and so on. The Nth child gui is $ChildGui[N - 1].

You would need to declare these variables as arrays first, allowing for some maximum number of child windows.

Dim $ChildGui[17], $MainEdit[17]....

Then you would need to change your event functions so you could tell which child window the event comes from. @GUI_WINHANDLE can be used for that, eg

Func SomeEvent()
Local $n, $ChildNUmber = -1
For $n = 0 to $lastChild
 if $ChildGui[$n] = @GUI_WINHANDLE then
   $ChildNumber = $n
   exitloop
 endif
next

if $ChildNumber = -1 then return
;carry on but instead of say $Nudgebtn we use $Nudgebtn[$ChildNumber]
.
.
.
EndFunc

I hope that makes sense :)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I get that but it's hard to use @GUI_WINHANDLE at some occassions like when I receive a message through udp i need to trigger the correct child window :/

But if you have an ip reference for each child

$ChildIP[$childguiNumber]

then when you receive a message via udp which references a certain IP you can loop through the $ChildIP array untill you find the ip and then youi know the childgui number.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I'm not really good at using arrays so maybe you could help me do it if I give you the code I have so far, In the meantime I thought of another way to do what I want, what if whenever I activate a child window I set what the buttons/editboxes do?Would that stress the cpu?It's not a complex GUI..And how would I do that by the way? Delete the GUI and recreate it?

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...