Jump to content
Sign in to follow this  
Lucidity

Choose variable value

Recommended Posts

Lucidity

In start of the a script i want to choose the value of a variable. Like $num = value. I done it for long time ago but have forgot. How is it made?

To explain more what i meant is that a popup comes when i open the autoit script and there i can write something. This that i'm writing is gonna be the value of variable $num

Edited by Lucidity

Share this post


Link to post
Share on other sites
water

$variable = InputBox(....)

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
PhoenixXL

Choice is Yours

Water has also Given You the Answer of Your Question

If dont like Complex Things dont Try my Code

But The Input Style Looks Cool this Way

I love it this Way

If Cancel Button is Pressed The Function will Return -1 as an Integer

Note if you type -1 and Press OK it will Return as a String

Code:

Global $ghGDIPBrush = 0
Global $ghGDIPDll = 0
Global $ghGDIPPen = 0
Global $giGDIPRef = 0
Global $giGDIPToken = 0
Global Const $tagGDIPSTARTUPINPUT = "int Version;ptr Callback;int NoThread;int NoCodecs"

$variable=_GetInput('Title Goes Here....',100,'Type Your Text','Fields Empty')
ConsoleWrite($variable)

Func _GetInput($sTitle,$sBig=100,$sText='PassWord',$sSecondaryText='Please Enter Some Text',$sFirstButton='Ok',$sSecondButton='Cancel')
Local $sPrevious=Opt('GUIOnEventMode',0)
$hGui= GUICreate($sTitle, 350, $sBig, -1, -1  , 0x80000000, BITOR(0x00000080,0x00000008))
GUISetBkColor(0)
Local $sLabel[3]=[GUICtrlCreateLabel($sText,20,10,200,15),GUICtrlCreateLabel($sFirstButton,150,$sBig-30,50,12),GUICtrlCreateLabel($sSecondButton,200,$sBig-30,50,12)]
For $i=0 To 2
  GUICtrlSetColor($sLabel[$i],0xffffff)
  GUICtrlSetBkColor($sLabel[$i],-2)
  If $i=0 Then ContinueLoop
  GUICtrlSetCursor($sLabel[$i],0)
Next
Local $sInput=GUICtrlCreateEdit('',20,30,260,$sBig-65,64);$ES_AUTOVSCROLL+$WS_VSCROLL
Local $sPos=ControlGetPos($hGui,'',$sInput)
;ConsoleWrite('X:'&$sPos[0]&@TAB&'Y:'&$sPos[1]&@TAB&'Width:'&$sPos[2]&@TAB&'Height:'&$sPos[3]&@CRLF)
;_ScrollBar_Create($hGui,$sInput)
WinSetTrans($hGui, "", 0)
GUISetBkColor(0)
GUISetState(@SW_SHOW, $hGui)
_DrawLine($hGui,10, $sBig-25,90,$sBig-25)
_DrawLine($hGui,10, $sBig-15,70, $sBig-15)
_DrawLine($hGui,15, 10,15, $sBig-10)
_DrawLine($hGui,200, 10,290, 10)
_DrawLine($hGui,240, 20,290, 20)
_DrawLine($hGui,285, 7,285, $sBig-10)
GUICtrlCreatePic('',0,0,350,$sBig,-1,0x00100000)
For $I = 0 To 207 Step 0.02
  WinSetTrans($hGui, "", $I)
Next
Local $sMsg
While $sMsg<>-3
  $sMsg=GUIGetMsg()
  Switch $sMsg
   Case $sLabel[1]
    Switch GUICtrlRead($sInput)
     Case ''
      GUICtrlSetData($sLabel[0],$sSecondaryText)
      ContinueLoop
    EndSwitch
    Opt('GUIOnEventMode',$sPrevious)
    Return GUICtrlRead($sInput)
   Case $sLabel[2]
    ExitLoop
  EndSwitch
WEnd
For $I = 207 To 0 Step -0.02
  WinSetTrans($hGui, "", $I)
Next
GUIDelete($hGui)
Opt('GUIOnEventMode',$sPrevious)
Return -1
EndFunc
Func _DrawLine($Gui,$x1,$y1,$x2,$y2,$sChannel='80FFD700')
Local  $hGraphic, $hPen
; Draw line
_GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($Gui)
$hPen = _GDIPlus_PenCreate ('0x'&$sChannel)
If Not _GDIPlus_GraphicsDrawLine ($hGraphic, $x1,$y1,$x2,$y2, $hPen) Then ConsoleWrite('Error:'&@error&@CRLF)
; Clean up resources
_GDIPlus_PenDispose ($hPen)
_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_ShutDown ()
;Done.....
EndFunc   ;==>_Main
#region -GDI +
Func _GDIPlus_Startup()
$giGDIPRef += 1
If $giGDIPRef > 1 Then Return True
$ghGDIPDll = DllOpen("GDIPlus.dll")
If $ghGDIPDll = -1 Then Return SetError(1, 2, False)
Local $tInput = DllStructCreate($tagGDIPSTARTUPINPUT)
Local $pInput = DllStructGetPtr($tInput)
Local $tToken = DllStructCreate("ulong_ptr Data")
Local $pToken = DllStructGetPtr($tToken)
DllStructSetData($tInput, "Version", 1)
Local $aResult = DllCall($ghGDIPDll, "int", "GdiplusStartup", "ptr", $pToken, "ptr", $pInput, "ptr", 0)
If @error Then Return SetError(@error, @extended, False)
$giGDIPToken = DllStructGetData($tToken, "Data")
Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_Startup
Func _GDIPlus_GraphicsCreateFromHWND($hWnd)
Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateFromHWND", "hwnd", $hWnd, "ptr*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return SetExtended($aResult[0], $aResult[2])
EndFunc   ;==>_GDIPlus_GraphicsCreateFromHWND
Func _GDIPlus_PenCreate($iARGB = 0xFF000000, $fWidth = 1, $iUnit = 2)
Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePen1", "dword", $iARGB, "float", $fWidth, "int", $iUnit, "ptr*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return SetExtended($aResult[0], $aResult[4])
EndFunc   ;==>_GDIPlus_PenCreate
Func _GDIPlus_GraphicsDrawLine($hGraphics, $iX1, $iY1, $iX2, $iY2, $hPen = 0)
__GDIPlus_PenDefCreate($hPen)
Local $aResult = DllCall($ghGDIPDll, "int", "GdipDrawLineI", "handle", $hGraphics, "handle", $hPen, "int", $iX1, "int", $iY1, _
   "int", $iX2, "int", $iY2)
Local $tmpError = @error, $tmpExtended = @extended
__GDIPlus_PenDefDispose()
If $tmpError Then Return SetError($tmpError, $tmpExtended, False)
Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsDrawLine
Func __GDIPlus_PenDefCreate(ByRef $hPen)
If $hPen = 0 Then
  $ghGDIPPen = _GDIPlus_PenCreate()
  $hPen = $ghGDIPPen
EndIf
EndFunc   ;==>__GDIPlus_PenDefCreate
Func __GDIPlus_PenDefDispose()
If $ghGDIPPen <> 0 Then
  _GDIPlus_PenDispose($ghGDIPPen)
  $ghGDIPPen = 0
EndIf
EndFunc   ;==>__GDIPlus_PenDefDispose
Func _GDIPlus_PenDispose($hPen)
Local $aResult = DllCall($ghGDIPDll, "int", "GdipDeletePen", "handle", $hPen)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_PenDispose
Func _GDIPlus_Shutdown()
If $ghGDIPDll = 0 Then Return SetError(-1, -1, False)
$giGDIPRef -= 1
If $giGDIPRef = 0 Then
  DllCall($ghGDIPDll, "none", "GdiplusShutdown", "ptr", $giGDIPToken)
  DllClose($ghGDIPDll)
  $ghGDIPDll = 0
EndIf
Return True
EndFunc   ;==>_GDIPlus_Shutdown
Func _GDIPlus_GraphicsDispose($hGraphics)
Local $aResult = DllCall($ghGDIPDll, "int", "GdipDeleteGraphics", "handle", $hGraphics)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsDispose
#endregion -GDI +

Regards

Phoenix XL

Edited by PhoenixXL
  • Like 1

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
Lucidity

Ahh thank you!

@PhoenixXL that's looking kinda advanced to really understand it..

Though, I'd another idea now.

Does it work to take those values from a plain txt file instead? If having the variable values there written up, and the script takes these values. In order not need to set these in the start of the script but rather from a textfile that can be saved and easily changed?

Share this post


Link to post
Share on other sites
water

Sure. Please have a look at FileReadLine or if it is an INI file look at the Ini* functions.

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

  • Similar Content

    • Skeletor
      By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
    • xiantez
      By xiantez
      This script used to work on an older version of AutoIT. Currently I am running AutoIT v3.3.14.5 and it's failing.
      Func PublicIP() ;Post public facing IP address Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8' Local $getIPaddress = BinaryToString(InetRead($url)) Local $sStart = 'clamp:2">' Local $sEnd = '</div>' Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd For $i In $ipaddress MsgBox(0, 'External IP', "Your public IP address is " & $i) Next EndFunc ;==>PublicIP The console output shows:
      "C:\Users\user\Documents\AutoIT\Scripts\WSI Tools.au3" (197) : ==> Variable must be of type "Object".: For $i In $ipaddress For $i In $ipaddress^ ERROR ->14:12:16 AutoIt3.exe ended.rc:1 +>14:12:16 AutoIt3Wrapper Finished. >Exit code: 1 Time: 9.811
    • b9k
      By b9k
      Hi, I am stuck on a GUI problem and would like your help to solve it.
      I am trying to automate the SoundWire Server app to match my current system volume level while it is minimized to the notification area (so no clicking or stealing focus),
      I can already get the handle and alter the tracker position by sending a WM_SETPOS message, but somehow the actual volume is not changed: I think I need to do something else to trigger the event handler for the value change and propagate it correctly.
      This is the control summary from Au3 info:
      >>>> Window <<<< Title: SoundWire Server Class: #32770 Position: 441, 218 Size: 566, 429 Style: 0x94CA00C4 ExStyle: 0x00050101 Handle: 0x0000000000510E12 >>>> Control <<<< Class: msctls_trackbar32 Instance: 4 ClassnameNN: msctls_trackbar324 Name: Advanced (Class): [CLASS:msctls_trackbar32; INSTANCE:4] ID: 6002 Text: Position: 51, 222 Size: 47, 126 ControlClick Coords: 1, 101 Style: 0x5001000A ExStyle: 0x00000000 Handle: 0x00000000001234C8 >>>> Mouse <<<< Position: 496, 567 Cursor ID: 2 Color: 0xF0F0F0 >>>> StatusBar <<<< >>>> ToolsBar <<<< >>>> Visible Text <<<< Default multimedia device Tray on Start Static Server Address: 192.168.1.8 Status: Connected to B9K~OP3 Audio Output Audio Input Level Record to File Input Select: 44.1 kHz Minimize to Master Volume Mute >>>> Hidden Text <<<< Slider2 Mute OK Cancel Label Balance Slider1 Volume Front L/R Fr C/LFE Side L/R Back L/R
      I am attaching the program in question so you don't have to install it (i don't know if it is portable enough, tough): 

      SoundWire Server_files.zip

      Thanks in advance and I hope I didn't post in the wrong section
    • California
      By California
      Hello,
      I wrote a benchmark script to measure variable declarations
      to find out whether you should focus more on static or global variables
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 #ce ---------------------------------------------------------------------------- #Region Pre-Setting Local $iTally1 = 0 Local $iTally2 = 0 Local $iTally3 = 0 Local $iTally4 = 0 Local $iTally5 = 0 Local $iTally6 = 0 Local $iTally7 = 0 Global $GLOBALCONST1 = 1 Global $GLOBALCONST2 = 1 Global $GLOBALCONST3 = 1 Global $GLOBALCONST4 = 1 Global $GLOBALCONST5 = 1 #EndRegion Pre-Setting #Region Test Functions Func s1() Static $i = $GLOBALCONST1 Return $i EndFunc Func g2() Return $GLOBALCONST2 EndFunc Func g3() Static $i7 = "gsdgdfegbgbrwefw" Return $GLOBALCONST3 EndFunc Func g4() Static $i1 = 1 Static $i2 = "asd" Static $i3 = 234 Static $i4 = True Static $i5 = [0] Static $i6 = "hgsdg" Static $i7 = 1 Static $i8 = 1 Static $i9 = 1 Static $i0 = 1 Return $GLOBALCONST4 EndFunc Func g5() Local $i = $GLOBALCONST5 Return $i EndFunc Func g6() Local $i = 1 Return $i EndFunc Func g7() Return 1 EndFunc #EndRegion Test Functions #Region Benchmark Loop For $i = 0 To 15 Local $tDelta = TimerInit() Do $iTally1 += s1() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally2 += g2() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally3 += g3() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally4 += g4() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally5 += g5() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally6 += g6() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally7 += g7() Until TimerDiff($tDelta) >= 1000 Next #EndRegion Benchmark Loop ConsoleWrite(@CRLF&"Static1: "&$iTally1&" pkt"&@CRLF&"Global2: "&$iTally2&" pkt"&@CRLF&"Global3: "&$iTally3&" pkt"&@CRLF&"Global4: "&$iTally4&" pkt"&@CRLF&"Local5: "&$iTally5&" pkt"&@CRLF&"Local6: "&$iTally6&" pkt"&@CRLF&"Hardcode7:"&$iTally7&" pkt"&@CRLF) #cs Result Static1: 10291881 pkt global to static Global2: 13977324 pkt only global Global3: 9886169 pkt global and static Global4: 2933051 pkt global and many statics Local5: 9937314 pkt global to local Local6: 10306484 pkt only local Hardcode7: 14835319 pkt no variable #ce Result:
      100% no variable, hardcore value
      94% only global variable use
      69% only local variable use with hardcore value set
      69% only static variable use with global variable value set
      67% declaration of local variable with global variable value set
      66% only global variable use with one static variable beside
      20% only global variable use with ten static variables beside
      My thesis of the result:
      Be careful with declarations, whether local, global or static Note: in my test the global variable performance was better than the local one, but in practice the global one would lose performance due to multiple operations
       
      What is your best practice sharing data between multiple functions?
×