Jump to content
Sign in to follow this  
mcclane654

Inputbox prompt string+variable

Recommended Posts

mcclane654

Global $messages = InputBox ("Title", "How many different messages?")

Global $message[$messages]
Local $creator
While $creator < $messages
$message[$creator] = InputBox ("Title", "what should message number $creator say?")
$creator=$creator+1
WEnd


the creator is going to display my number. but I can't get it to work as an variable since it's inside "". I have tried various methods without luck :( hope someone can help if this is possible. if you didn't understand please let me know and I'll try explaining it better ;)
 

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum!

Try this (untested):

Global $messages = InputBox ("Title", "How many different messages?")
If @error <> 0 Then Exit ; User cancelled
$messages= Number($messages)
If $messages <= 0 Then Exit ; Wrong input
Global $message[$messages]
For $creator = 0 to $messages - 1 ; - 1 because the index of an array starts at 0
    $message[$creator] = InputBox ("Title", "What should message number " &  $creator & " say?")
    If @error <> 0 Then Exit ; So the user can cancel the loop anytime
Next
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

BTW: Please enclose AutoIt code in tags. Use the blue icon with an "A" in the editor. Enhances readability ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
mcclane654

have more too my code than I posted ;)" &  $creator & " that worked :D my code is the same as yours with 2 exceptions.

is it important to

$messages= Number($messages)

write number after =?

and why do you write Next at the end?

Share this post


Link to post
Share on other sites
water

Number is needed because InputBox returns a string and to remove all non-numeric characters.

Next is needed to end the For statement.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
mcclane654

oh didn't use For xD is For better that while loop? inputbox dosen't return a string to me. at least it works fine. but if it removes all non numeric charaters I'll add it ;) thx

Share this post


Link to post
Share on other sites
dreamzboy

It's easier to manage an Array in a For loop than While Loop.  You can code it to work with While loop but it's a little bit lengthier.

Share this post


Link to post
Share on other sites
mcclane654

Ok thx! I'll look into it. I used while loop since I got som experience from javascript and have to use my knowlegde from that but ofc learn new stuff as long as I understand it 100%

Share this post


Link to post
Share on other sites
water

For better that while loop?

If For is used there is no need to define the counter variable. That's implicitely done by AutoIt. So For and While are equivalent.  For is for lazy people ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

inputbox dosen't return a string to me. at least it works fine. but if it removes all non numeric charaters I'll add it ;) thx

According to the docu InputBox returns a string. So if a user enters a number you get "3" (string) and not 3 (integer). Works fine until the user enters a character.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Ok thx! I'll look into it. I used while loop since I got som experience from javascript and have to use my knowlegde from that but ofc learn new stuff as long as I understand it 100%

You can chose between While, For and Do / Until. If it solves your problem, it's perfect.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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  

×