Jump to content

using an input variable to define the name of another variable


Recommended Posts

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

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)
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...