2
$Number1Prt2 = "####   "
$Number1Prt3 = "  ##   "
$Number1Prt4 = "  ##   "
$Number1Prt5 = "  ##   "
$Number1Prt6 = "  ##   "
$Number1Prt7 = "###### " 

$Number2Prt1 = " #######  "
$Number2Prt2 = "##     ## "
$Number2Prt3 = "       ## "
$Number2Prt4 = " #######  "
$Number2Prt5 = "##        "
$Number2Prt6 = "##        "
$Number2Prt7 = "######### "

$Number3Prt1 = " #######  "
$Number3Prt2 = "##     ## "
$Number3Prt3 = "       ## "
$Number3Prt4 = " #######  "
$Number3Prt5 = "       ## "
$Number3Prt6 = "##     ## "
$Number3Prt7 = " #######  "

$Number4Prt1 = "##        "
$Number4Prt2 = "##    ##  "
$Number4Prt3 = "##    ##  "
$Number4Prt4 = "##    ##  "
$Number4Prt5 = "######### "
$Number4Prt6 = "      ##  "
$Number4Prt7 = "      ##  "

$Number5Prt1 = "######## "
$Number5Prt2 = "##       "
$Number5Prt3 = "##       "
$Number5Prt4 = "#######  "
$Number5Prt5 = "      ## "
$Number5Prt6 = "##    ## "
$Number5Prt7 = " ######  "

$Number6Prt1 = " #######  "
$Number6Prt2 = "##     ## "
$Number6Prt3 = "##        "
$Number6Prt4 = "########  "
$Number6Prt5 = "##     ## "
$Number6Prt6 = "##     ## "
$Number6Prt7 = " #######  "

$Number7Prt1 = "######## "
$Number7Prt2 = "##    ## "
$Number7Prt3 = "    ##   "
$Number7Prt4 = "   ##    "
$Number7Prt5 = "  ##     "
$Number7Prt6 = "  ##     "
$Number7Prt7 = "  ##     "

$Number8Prt1 = " #######  "
$Number8Prt2 = "##     ## "
$Number8Prt3 = "##     ## "
$Number8Prt4 = " #######  "
$Number8Prt5 = "##     ## "
$Number8Prt6 = "##     ## "
$Number8Prt7 = " #######  "

$Number9Prt1 = " #######  "
$Number9Prt2 = "##     ## "
$Number9Prt3 = "##     ## "
$Number9Prt4 = " ######## "
$Number9Prt5 = "       ## "
$Number9Prt6 = "##     ## "
$Number9Prt7 = " #######  "

$Number0Prt1 = "  #####   "
$Number0Prt2 = " ##   ##  "
$Number0Prt3 = "##     ## "
$Number0Prt4 = "##     ## "
$Number0Prt5 = "##     ## "
$Number0Prt6 = " ##   ##  "
$Number0Prt7 = "  #####   "

$IDNumber = "9873453"
$CharArray =$IDNumber.ToCharArray()

#Creating variables
foreach ($CharArray in [char[]]$CharArray) { $NumberArray += ("$"+"Number"+$CharArray+"Prt"+"1")}

basically what I am trying to achieve is foreach character in $IDNumber it will spit out a string along the lines of $number9prt1 and place it into a array, then move onto the next character in $IDNumber and so on.

when this is done I want to foreach string in the array get the variables for each of those string.

example the first one would look in variable $Number9Prt1 then $Number8Prt1 then $Number7Prt1 .....

Simply put, I have an array with values like Number9Prt1 then Number8Prt1 then Number7Prt1. Is there a way I can take a value from the array, convert it into a variable, grab the string from the variable and place that into a array.

I've been trying for days but no luck ... any help would be hugely appreciated.

Thank you

Novice coder, Luke

Reason: I use the console window at my workplace for a kind of "GUI" and having bigger text would be helpful.

6
  • First, you are using the chararray variable as your iteration variable when it’s supposed to be just the char array. Change that to foreach($char in $chararray){... do something with $char...} Commented Nov 4, 2020 at 17:33
  • Second, you can simply increase the font size of the console, why do all this instead? Commented Nov 4, 2020 at 17:33
  • Third, you don’t want to include the $ as part of the variable name. Commented Nov 4, 2020 at 17:34
  • I will try the First and I am not the admin so i cant save any system changes but for some reason when ever the computer is restarted all values go back to the defaults. Commented Nov 4, 2020 at 17:36
  • Just curious. [Reason: I use the console window at my workplace for a kind of "GUI" and having bigger text would be helpful.] Why? Verses just using the builtin GUI features Powershell give you via say Out-GridView, Show-Command, and message boxes? From a GUI, especially human accessibility (screen readers, screen resolution, etc, ) use cases. Your approach would be a real issue. Commented Nov 4, 2020 at 19:42

1 Answer 1

2

I would personally just use arrays for this. Each index of the array can represent the number:

# For simplicity, I only created 0,1,2,3 indices.
# Each index number matches the graphical number it stores.
$Numbers = @("  #####   "," ##   ##  ","##     ## ","##     ## ","##     ## "," ##   ##  ","  #####   "),
           @("####   ","  ##   ","  ##   ","  ##   ","  ##   ","  ##   ","###### "),
           @(" #######  ","##     ## ","       ## "," #######  ","##        ","##        ","######### "),
           @(" #######  ","##     ## ","       ## "," #######  ","       ## ","##     ## "," #######  ")

$IDNumbers = '20012'
$IDNumbers.ToCharArray() | Foreach-Object { $Numbers["$_"] }

# Output
 #######
##     ##
       ##
 #######
##
##
#########
  #####
 ##   ##
##     ##
##     ##
##     ##
 ##   ##
  #####
  #####
 ##   ##
##     ##
##     ##
##     ##
 ##   ##
  #####
####
  ##
  ##
  ##
  ##
  ##
######
 #######
##     ##
       ##
 #######
##
##
#########

Explanation:

$Numbers is an array where its indexes each contain an array that represents a numerical graphic. So $Numbers['0'] contains array elements that make up the 0 graphic, $Numbers['1'] contains array elements that make up the 1 graphic, etc. Now you only need to retrieve the index of $Numbers that contains your target graphic.

If visual representation within the shell matters to you, you can still maintain that:

$Numbers = @(
"  #####   ",
" ##   ##  ",
"##     ## ",
"##     ## ",
"##     ## ",
" ##   ##  ",
"  #####   "
),
@(
"####   ",
"  ##   ",
"  ##   ",
"  ##   ",
"  ##   ",
"  ##   ",
"###### "
),
@(
" #######  ",
"##     ## ",
"       ## ",
" #######  ",
"##        ",
"##        ",
"######### "
),
@(
" #######  ",
"##     ## ",
"       ## ",
" #######  ",
"       ## ",
"##     ## ",
" #######  "
)

You can build on this approach for horizontal display:

$Numbers = @("  #####   "," ##   ##  ","##     ## ","##     ## ","##     ## "," ##   ##  ","  #####   "),
           @("####   ","  ##   ","  ##   ","  ##   ","  ##   ","  ##   ","###### "),
           @(" #######  ","##     ## ","       ## "," #######  ","##        ","##        ","######### "),
           @(" #######  ","##     ## ","       ## "," #######  ","       ## ","##     ## "," #######  ")

$IDNumbers = '20012'
for ($i = 0; $i -lt 7; $i++) {
    ($IDNumbers.ToCharArray() | Foreach-Object { $Numbers["$_"][$i] }) -join "`t"
}

You can simply just change the joining characters (tab here) to any one or group of characters. Since each graphic has 7 parts, you can loop through each part (indices 0-6). Since we created each part as an element of the array, you have an array of nested arrays. So graphic 0 part 1 would be $Numbers['0'][0], graphic 3 part 4 would be $Numbers['3'][3].


Edit: Working with Letters and Numbers

You can use a hash table instead of an array to hold your graphics. Then you can access each graphic array by the hash table key.

$hash = [ordered]@{}
$hash['A'] = @('      ####      ','     ##  ##     ','    ##    ##    ','   ##########   ','  ##        ##  ',' ##          ## ','##            ##')
$hash['0'] = @("  #####   "," ##   ##  ","##     ## ","##     ## ","##     ## "," ##   ##  ","  #####   ")
$hash['1'] = @("####   ","  ##   ","  ##   ","  ##   ","  ##   ","  ##   ","###### ")
$hash['2'] = @(" #######  ","##     ## ","       ## "," #######  ","##        ","##        ","######### ")
$hash['3'] = @(" #######  ","##     ## ","       ## "," #######  ","       ## ","##     ## "," #######  ")

$IDNumbers = 'A23012'
for ($i = 0; $i -lt 7; $i++) {
    ($IDNumbers.ToCharArray() | Foreach-Object { $hash["$_"][$i] }) -join "`t"
}
Sign up to request clarification or add additional context in comments.

10 Comments

This is brilliant don't get me wrong but I'm doing this so it will line the variables up and display then horizontally. but I fully appreciate your answer.
I added how you can make it display in the shell as you are creating the variable.
In the shell it doesn't really bother me how they are displayed but in the console window I am trying to get them to display horizontally. in the code I am grabbing the top line of values adding a 'n, then I will create a loop and move onto the second lines, then the third ..... then display the characters horizontally
I added a horizontal way of displaying it.
Well that is just witch craft. perfect. thank you very much
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.