Jump to content

Choose variable value


Recommended Posts

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

$variable = InputBox(....)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

×
×
  • Create New...