Jump to content

Use two variable at same time


Terenz
 Share

Recommended Posts

Hi all, it's hard for me to explain what i need so i have create an example:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("TestForm", 414, 271, 196, 132)
$Label1 = GUICtrlCreateLabel("Label1", 8, 8, 404, 153)
GUICtrlSetFont(-1, 100, 400, 0, "Arial")
$Label2 = GUICtrlCreateLabel("Label2", 0, 160, 285, 108)
GUICtrlSetFont(-1, 70, 400, 0, "Arial")
GUISetState(@SW_SHOW)

;~ _Change_Size($Label1, 10)
;~ _Change_Size($Label2, 10)
Sleep(1000)
_Change_Size(BitOR($Label1, $Label2),10)
_Change_Size(BitXOR($Label1, $Label2),10)
_Change_Size(BitAND($Label1, $Label2),10)
Sleep(1000)

Func _Change_Size($MyLabel, $Size)
    GUICtrlSetFont($MyLabel, $Size, 400, 0, "Arial")
EndFunc

I know i can call 2 times the function, but there is't a way to perform the same operation using only one function? I have try with Bit operator but not work. Is possible or not?

Thanks :D

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

Use an array, pass the array to the function, loop through the array to find what labels you're wanting to set.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I'm afraid I have no idea what you mean by "store directly the variable".

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("TestForm", 414, 271, 196, 132)
$Label1 = GUICtrlCreateLabel("Label1", 8, 8, 404, 153)
GUICtrlSetFont(-1, 100, 400, 0, "Arial")
$Label2 = GUICtrlCreateLabel("Label2", 0, 160, 285, 108)
GUICtrlSetFont(-1, 70, 400, 0, "Arial")
GUISetState(@SW_SHOW)

Sleep(1000)
Local $MyArr[3] = [$Label1, $Label2]
_Change_Size($MyArr, 10)
Sleep(1000)

Func _Change_Size($MyLabel, $Size)
    If IsArray($MyLabel) Then
        For $i = 0 To UBound($MyLabel) - 1
            GUICtrlSetFont($MyLabel[$i], $Size, 400, 0, "Arial")
        Next
    Else
        GUICtrlSetFont($MyLabel, $Size, 400, 0, "Arial")
    EndIf
EndFunc   ;==>_Change_Size

Seems work, i think there isn't a way to declare the Local $MyArray when i call the function in one line instead of two.

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

Hi Terenz

I think you may be looking for a loop?

you want to call the same function over and over again with slight adjustments?

then put it in a  loop...once we know we are on the right track we can come up with some examples...

Bill

Link to comment
Share on other sites

Using an array is more versatile, but you could do the following to pass the variables the way you want.

 
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("TestForm", 414, 271, 196, 132)
$Label1 = GUICtrlCreateLabel("Label1", 8, 8, 404, 153)
GUICtrlSetFont(-1, 100, 400, 0, "Arial")
$Label2 = GUICtrlCreateLabel("Label2", 0, 160, 285, 108)
GUICtrlSetFont(-1, 70, 400, 0, "Arial")
GUISetState(@SW_SHOW)

Sleep(1000)

_Change_Size($Label1, 10, $Label2, 20);as many IDs and sizes up to 8 pairs
Sleep(1000)

Func _Change_Size($lab1, $Size1, $lab2 = 0, $size2 = 0, $lab3 = 0, $Size3 = 0, $lab4 = 0, $size4 = 0, $lab5 = 0, $Size5 = 0, $lab6 = 0, $size6 = 0, $lab7 = 0, $Size7 = 0, $lab8 = 0, $size8 = 0)
    Local $ii, $iPairs = Floor(@NumParams / 2)

    For $ii = 1 To $iPairs
        GUICtrlSetFont(Eval("lab" & $ii), Eval("Size" & $ii), "Arial")
    Next
EndFunc   ;==>_Change_Size
 

Edit: Removed  Call("_Change_Size".. and just used _ChangeSize. (Don't know why I used call - proably thinking about Eval)

Edited by martin
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

Alternatively:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("TestForm", 414, 271, 196, 132)
$Label1 = GUICtrlCreateLabel("Label1", 8, 8, 404, 153)
GUICtrlSetFont(-1, 100, 400, 0, "Arial")
$Label2 = GUICtrlCreateLabel("Label2", 0, 160, 285, 108)
GUICtrlSetFont(-1, 70, 400, 0, "Arial")
GUISetState(@SW_SHOW)

Sleep(1000)
_Change_Size("Label1|10|Label2|20");as many IDs and sizes as you would like
Sleep(1000)

Func _Change_Size($SizeString)
    Local $aSplit = StringSplit($SizeString, '|')
    For $ii = 1 To Floor($aSplit[0] / 2) * 2 Step 2
        GUICtrlSetFont(Eval($aSplit[$ii]), $aSplit[$ii + 1], "Arial")
    Next
EndFunc   ;==>_Change_Size
Edited by danwilli
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...