Sign in to follow this  
Followers 0
Xonos

Dynamic Variables

14 posts in this topic

#1 ·  Posted (edited)

Hello! I have a question...

What method would I use to make a popup box that has an input text field. In the field, the user would enter a string and whatever string they type after clicking "ok" would store that string as a pre-determined variable. For example:

Program boots up:

I click a button called Backup. After clicking Backup, it will call a function. In this function, it will popup another box asking to type out a string. You type out your string and whatever you type is stored as a variable.. How would I accomplish that or where should I start? I don't know what to type in search to find what I am looking for.

Edited by Richardo

[center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font] AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center]

Share this post


Link to post
Share on other sites



$hInput = InputBox("Enter", "Enter data...")
MsgBox(0, "", $hInput)
oh hey! Thanks for the direct answer!!! I have one more question.. I forgot how to attach a variable to a string in a command.

For example, how would I attach the $hInput to a run command that already has a string in it?

run("C:\Program Files\MyProgram\" + $hInput)

How would I add in this variable to continue after \MyProgram\. If I typed myprogram.exe in the input, it would complete as C:\Program Files\MyProgram\myprogram.exe.


[center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font] AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center]

Share this post


Link to post
Share on other sites

Use &

Actually, use the damn help file, these are simple questions, you're wasting your time and ours, while you could take a look at the helpfile and the examples.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Sorry?...

Thanks for your help.

I actually checked the help file and & didn't seem to work when adding a variable to a string. I am a huge fan of the search function and help files but I really am unsure on what to search for. I wasn't asking for someone to write my script for me.. just guide me to the right direction. I didn't mean to offend anyone and I certainly didn't mean to waste all of your time.

EDIT:

I figured out a solution. While I was unable to attach the variable to the end of a string, I was sucessful in declaring another variable as the string and just attach two variables together by use of the & operator. For example.

$location = "C:\Programs\"
$application = "program.exe"

run($location & $application)
;This will return C:\Programs\program.exe

Again, sorry for wasting everyones time.

Edited by Richardo

[center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font] AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center]

Share this post


Link to post
Share on other sites

While I was unable to attach the variable to the end of a string, ...

How was that unsuccessful? If you just changed your original example from + to &, it would have worked:
run("C:\Program Files\MyProgram\" & $hInput)

P.S. By convention, the "h" prefix is for handles, and you would typically use $sInput for a string. Not required, but avoids some confusion.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Well, I don't use it in that manner. This is my script and I am having issues again. It's wierd.

#include <GUIConstants.au3>

GUICreate("BackIt", 255, 110, 255, 255)
GUICtrlCreateLabel("Please select an task to perform.", 5, 5)
$buttonInstall = GUICtrlCreateButton("Start", 95, 75, 60)
$comboInstallType = GUICtrlCreateCombo("Backup", 93, 40, 65)
GUICtrlSetData($comboInstallType, "Recover")
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $buttonInstall
            If GUICtrlRead($comboInstallType) = "Backup" Then
                _BackupFiles()
            EndIf
            If GUICtrlRead($comboInstallType) = "Recover" Then
                _RecoverFiles()
            EndIf
            ExitLoop
    EndSelect
WEnd



Func _BackupFiles()
;$copyLoc = "C:\Copy\Files\"
;$backupLoc = "C:\Copy\Backup\"
    $rlocation = InputBox("BackIt","Please specify the room number and location of the room. This is very important that you type the correct information! (Ex: A201, D13, B101)", "")
;MsgBox(4096, "BackIt", "Files have been backed up!", 10)
    _FileCopy("C:\Copy\Files\" , "C:\Copy\Backup\" & $rlocation)

EndFunc


Func _RecoverFiles()
         MsgBox(4096, "BackIt", "Files have been recovered!", 10)
;No recovery section added yet.
EndFunc


Func _FileCopy($fromFile,$tofile)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)
EndFunc

The script compiles perfectly but it just won't copy.

Edited by Richardo

[center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font] AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Well, I don't use it in that manner. This is my script and I am having issues again. It's wierd.

CODE
#include <GUIConstants.au3>

GUICreate("BackIt", 255, 110, 255, 255)

GUICtrlCreateLabel("Please select an task to perform.", 5, 5)

$buttonInstall = GUICtrlCreateButton("Start", 95, 75, 60)

$comboInstallType = GUICtrlCreateCombo("Backup", 93, 40, 65)

GUICtrlSetData($comboInstallType, "Recover")

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $buttonInstall

If GUICtrlRead($comboInstallType) = "Backup" Then

_BackupFiles()

EndIf

If GUICtrlRead($comboInstallType) = "Recover" Then

_RecoverFiles()

EndIf

ExitLoop

EndSelect

WEnd

Func _BackupFiles()

;$copyLoc = "C:\Copy\Files\"

;$backupLoc = "C:\Copy\Backup\"

$rlocation = InputBox("BackIt","Please specify the room number and location of the room. This is very important that you type the correct information! (Ex: A201, D13, B101)", "")

;MsgBox(4096, "BackIt", "Files have been backed up!", 10)

_FileCopy("C:\Copy\Files\" , "C:\Copy\Backup\" & $rlocation)

EndFunc

Func _RecoverFiles()

MsgBox(4096, "BackIt", "Files have been recovered!", 10)

;No recovery section added yet.

EndFunc

Func _FileCopy($fromFile,$tofile)

Local $FOF_RESPOND_YES = 16

Local $FOF_SIMPLEPROGRESS = 256

$winShell = ObjCreate("shell.application")

$winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)

EndFunc

The script compiles perfectly but it just won't copy.
Are you sure it's valid to try copying a folder object (which would include its subfolders) into one of its subfolders?

:party:

P.S. If I'm right about the issue, you may see COM errors about this line in the console when running from SciTE:

$winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)

What do you get when running it from SciTE?

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Are you sure it's valid to try copying a folder object (which would include its subfolders) into one of its subfolders?

:party:

P.S. If I'm right about the issue, you may see COM errors about this line in the console when running from SciTE:

$winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)

What do you get when running it from SciTE?

:)

I compiled with no errors.

>"C:\Program Files\AutoIt3\SciTE\..\aut2exe\aut2exe.exe" /in "C:\Documents and Settings\Richardo\Desktop\Projects\Scripts\BackIt\Test Sources\test2.au3"

Ultimate Packer for eXecutables

Copyright © 1996 - 2008

UPX 3.03w Markus Oberhumer, Laszlo Molnar & John Reiser Apr 27th 2008

File size Ratio Format Name

-------------------- ------ ----------- -----------

612864 -> 290304 47.37% win32/pe test2.exe

Packed 1 file.

>Exit code: 0 Time: 1.867

Also, I rewrote it a little bit and I even get the return to work properly but it just won't copy.

#include <GUIConstants.au3>

GUICreate("BackIt", 255, 110, 255, 255)
GUICtrlCreateLabel("Please select an task to perform.", 5, 5)
$buttonInstall = GUICtrlCreateButton("Start", 95, 75, 60)
$comboInstallType = GUICtrlCreateCombo("Backup", 93, 40, 65)
GUICtrlSetData($comboInstallType, "Recover")
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $buttonInstall
            If GUICtrlRead($comboInstallType) = "Backup" Then
                _BackupFiles()
            EndIf
            If GUICtrlRead($comboInstallType) = "Recover" Then
                _RecoverFiles()
            EndIf
            ExitLoop
    EndSelect
WEnd



Func _BackupFiles()
    $copyLoc = "C:/Copy/Files/"
    $backupLoc = "C:/Copy/Backup/"
    $recovery = InputBox("BackIt","Please specify the room number and location of the room. This is very important that you type the correct information! (Ex: A201, D13, B101)", "")
    MsgBox(4096, "BackIt", $backupLoc & $recovery & "/", 10)
    _FileCopy($copyLoc , $backupLoc & $recovery & "/")

EndFunc


Func _RecoverFiles()
        MsgBox(4096, "BackIt", "Files have been recovered!", 10)
EndFunc


Func _FileCopy($fromFile,$tofile)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)
EndFunc

It compiles with no errors and also does not start copying. If I specify the location by use of a string, it works fine... It's when I add & $recovery that makes it not work.


[center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font] AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center]

Share this post


Link to post
Share on other sites

I compiled with no errors.

I was asking about console output when you RUN it (F5), not when you compile it.

Also, I rewrote it a little bit and I even get the return to work properly but it just won't copy.

CODE
#include <GUIConstants.au3>

GUICreate("BackIt", 255, 110, 255, 255)

GUICtrlCreateLabel("Please select an task to perform.", 5, 5)

$buttonInstall = GUICtrlCreateButton("Start", 95, 75, 60)

$comboInstallType = GUICtrlCreateCombo("Backup", 93, 40, 65)

GUICtrlSetData($comboInstallType, "Recover")

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $buttonInstall

If GUICtrlRead($comboInstallType) = "Backup" Then

_BackupFiles()

EndIf

If GUICtrlRead($comboInstallType) = "Recover" Then

_RecoverFiles()

EndIf

ExitLoop

EndSelect

WEnd

Func _BackupFiles()

$copyLoc = "C:/Copy/Files/"

$backupLoc = "C:/Copy/Backup/"

$recovery = InputBox("BackIt","Please specify the room number and location of the room. This is very important that you type the correct information! (Ex: A201, D13, B101)", "")

MsgBox(4096, "BackIt", $backupLoc & $recovery & "/", 10)

_FileCopy($copyLoc , $backupLoc & $recovery & "/")

EndFunc

Func _RecoverFiles()

MsgBox(4096, "BackIt", "Files have been recovered!", 10)

EndFunc

Func _FileCopy($fromFile,$tofile)

Local $FOF_RESPOND_YES = 16

Local $FOF_SIMPLEPROGRESS = 256

$winShell = ObjCreate("shell.application")

$winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)

EndFunc

It compiles with no errors and also does not start copying. If I specify the location by use of a string, it works fine... It's when I add & $recovery that makes it not work.

I was wrong about you trying to backup into a child folder. Source = C:/Copy/Files/, Destination = C:/Copy/Backup/, so that is not the problem. I should have read it more closely.

So, what do you get in the SciTE console when you RUN it?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

i know this message is a 'little belated' lol... but couldn't someone just tell the poor guy to add "#include <File.au3>" to get the UDF commands working -.-

p.s sorry for bumping a 2year old post

Edited by reecieboy

Share this post


Link to post
Share on other sites

i know this message is a 'little belated' lol... but couldn't someone just tell the poor guy to add "#include <File.au3>" to get the UDF commands working -.-

But there's no code from that include used. Read the code, or even run it and you'll see it's just fine as it is.

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