Jump to content
Sign in to follow this  
RogerRabbitsClone

using an input variable to define the name of another variable

Recommended Posts

RogerRabbitsClone

hey autoiters,

i dont know how to explain it much better than whats in the title. heres a simple example followed by my actual code.

$quantity = user input

$type = user input

$sub = $($quantity)($type)sub

any help is greatly appreciated.

$250colorsub = 44
$500colorsub = 70
$1000colorsub = 122


$250blacksub = 26
$500blacksub = 34
$1000blacksub = 50

$500foilsub = 150
$1000foilsub = 255
$quantity = inputbox ("quantity", "how many cards? answer can be 250, 500 or 1000)
$type = inputbox("type", "what kind? answers can be the following: " & @crlf & "color" & @crlf & "black" & @crlf & "foil")

$sub = $($quantity)($type)sub

$tax = $sub * .0875
$total = $sub + $tax

<--a good way to start you day

Share this post


Link to post
Share on other sites
DW1

Not sure what the scenario is here, so I could be wrong, but there are probably better ways to do this than rely on a variables name.

If for some reason this is what you want instead of, for instance, using an array to reference a string to a numeric value, then you could use Execute():

Local $quantity, $type

$250colorsub = 44
$500colorsub = 70
$1000colorsub = 122

$250blacksub = 26
$500blacksub = 34
$1000blacksub = 50

$500foilsub = 150
$1000foilsub = 255

While Not StringRegExp($quantity, "^(250|500|1000)$")
    $quantity = InputBox("quantity", "how many cards? answer can be 250, 500 or 1000")
WEnd
While Not StringRegExp($type, "^(color|black|foil)$")
    $type = InputBox("type", "what kind? answers can be the following: " & @CRLF & "color" & @CRLF & "black" & @CRLF & "foil")
WEnd

$sSub = '$' & $quantity & $type & 'sub'
$sub = Execute($sSub)

$tax = $sub * .0875
$total = $sub + $tax
MsgBox(0, 'test', 'Total = ' & $total & @CRLF & $sSub & ' = ' & $sub)

Share this post


Link to post
Share on other sites
RogerRabbitsClone

@danwilli thats exactly what i needed. THANK YOU GUYS!

$sSub = '$' & $quantity & $type & 'sub'
$sub = Execute($sSub)

<--a good way to start you day

Share this post


Link to post
Share on other sites
RogerRabbitsClone

one more thing, im pasting these into indesign, how do i force them to be 2 decimal points? i know python would be:

hours = 16.189
print(format(hours, ".2f"))
>>>16.19

Edited by RogerRabbitsClone

<--a good way to start you day

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  

×