Jump to content

Recommended Posts

Posted (edited)

Okay so if I have this code right here:

Global $input = InputBox("Letter", "State a letter")

if $input = "A" Then
   MsgBox(0,"Output","1")
EndIf
if $input = "B" Then
   MsgBox(0,"Output","2")
EndIf

It's going to say 1 if I type A, 2 if I type B and so on once I add more. But I want to make it to where I can type in "A B" or similar (same input box), and it'll come out with "1 2".

That's basically it. I'm not sure if this is even possible but I sure hope it is.

Edited by Cookid
Solved
Posted (edited)

Do the message box after the if statements.   use stringinstr ontheif statements and concat your outputs into a variable.   done.

 

Edit.  how complex are your strings? Do you just want to convert alpha characters to numbers, starting at 1?

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted
13 minutes ago, jdelaney said:

Do the message box after the if statements.   use stringinstr ontheif statements and concat your outputs into a variable.   done

Isn't stringinstr supposed to tell you the location of the letter? I'm not sure how that would end up being converted, even if it can be converted it's still a problem that there could be infinite A's instead of a set amount in the optional parameter.

Posted
1 minute ago, jdelaney said:

Sounds like you just need to stringreplace. Or, better define your problem.

It's kinda basic,

lets say A = 1, B = 2, C = 3.

I enter in the input: A C B.

So i'd want the output to be 1 3 2. But I want this to work for anything I put it. So it's infinite length and any one of the 26 letters.

 

Posted (edited)

ezpz

ConsoleWrite(ReplaceAlpha("a c b") & @CRLF)
ConsoleWrite(ReplaceAlpha("aadsfdsaf c b") & @CRLF)
ConsoleWrite(ReplaceAlpha("a asdfasdffsadfdsa b") & @CRLF)
ConsoleWrite(ReplaceAlpha("aasdf c sdfasdfasdfasfddsafb") & @CRLF)


Func ReplaceAlpha($s)
    For $i = 65 To 65+26
        $s = StringReplace($s,Chr($i),$i-64)
    Next
    Return $s
EndFunc

output:

1 3 2
11419641916 3 2
1 11946119466191464191 2
111946 3 1946119461194611964419162

 

Edit: this conversion is obviously not case sensitive

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted (edited)
2 minutes ago, jdelaney said:

ezpz

ConsoleWrite(ReplaceAlpha("a c b") & @CRLF)
ConsoleWrite(ReplaceAlpha("aadsfdsaf c b") & @CRLF)
ConsoleWrite(ReplaceAlpha("a asdfasdffsadfdsa b") & @CRLF)
ConsoleWrite(ReplaceAlpha("aasdf c sdfasdfasdfasfddsafb") & @CRLF)


Func ReplaceAlpha($s)
    For $i = 65 To 65+26
        $s = StringReplace($s,Chr($i),$i-64)
    Next
    Return $s
EndFunc

output:

1 3 2
11419641916 3 2
1 11946119466191464191 2
111946 3 1946119461194611964419162

That's exactly what I need but I did say "lets say A = 1, ect", I can't give each letter a custom number from that variable. I guess i should of been more specific, sorry

Edited by Cookid
Posted (edited)

Didn't you already post a similar question for that?  You can create an array 'key' and loop through that, and use string replace.

 

Example (you fill in the rest of the conversion values in the array):

Local $a[][]=[['A',6],['B',9],['C',5]]

ConsoleWrite(ReplaceAlpha("a c b") & @CRLF)
ConsoleWrite(ReplaceAlpha("aadsfdsaf c b") & @CRLF)
ConsoleWrite(ReplaceAlpha("a asdfasdffsadfdsa b") & @CRLF)
ConsoleWrite(ReplaceAlpha("aasdf c sdfasdfasdfasfddsafb") & @CRLF)

ConsoleWrite(ReplaceAlpha("a c b",$a) & @CRLF)
ConsoleWrite(ReplaceAlpha("aadsfdsaf c b",$a) & @CRLF)
ConsoleWrite(ReplaceAlpha("a asdfasdffsadfdsa b",$a) & @CRLF)
ConsoleWrite(ReplaceAlpha("aasdf c sdfasdfasdfasfddsafb",$a) & @CRLF)

Func ReplaceAlpha($s,$aKey=Default)
    If UBound($aKey,0)=2 Then
        For $i = 0 To UBound($a)-1
            $s = StringReplace($s,$a[$i][0],$a[$i][1])
        Next
    Else
        For $i = 65 To 65+26
            $s = StringReplace($s,Chr($i),$i-64)
        Next
    EndIf
    Return $s
EndFunc

output:

1 3 2
11419641916 3 2
1 11946119466191464191 2
111946 3 1946119461194611964419162


6 5 9
66dsfds6f 5 9
6 6sdf6sdffs6dfds6 9
66sdf 5 sdf6sdf6sdf6sfdds6f9

edited the array to display better contrast.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted
33 minutes ago, jdelaney said:

Didn't you already post a similar question for that?  You can create an array 'key' and loop through that, and use string replace.

 

Example (you fill in the rest of the conversion values in the array):

Local $a[][]=[['A',6],['B',9],['C',5]]

ConsoleWrite(ReplaceAlpha("a c b") & @CRLF)
ConsoleWrite(ReplaceAlpha("aadsfdsaf c b") & @CRLF)
ConsoleWrite(ReplaceAlpha("a asdfasdffsadfdsa b") & @CRLF)
ConsoleWrite(ReplaceAlpha("aasdf c sdfasdfasdfasfddsafb") & @CRLF)

ConsoleWrite(ReplaceAlpha("a c b",$a) & @CRLF)
ConsoleWrite(ReplaceAlpha("aadsfdsaf c b",$a) & @CRLF)
ConsoleWrite(ReplaceAlpha("a asdfasdffsadfdsa b",$a) & @CRLF)
ConsoleWrite(ReplaceAlpha("aasdf c sdfasdfasdfasfddsafb",$a) & @CRLF)

Func ReplaceAlpha($s,$aKey=Default)
    If UBound($aKey,0)=2 Then
        For $i = 0 To UBound($a)-1
            $s = StringReplace($s,$a[$i][0],$a[$i][1])
        Next
    Else
        For $i = 65 To 65+26
            $s = StringReplace($s,Chr($i),$i-64)
        Next
    EndIf
    Return $s
EndFunc

output:

1 3 2
11419641916 3 2
1 11946119466191464191 2
111946 3 1946119461194611964419162


6 5 9
66dsfds6f 5 9
6 6sdf6sdffs6dfds6 9
66sdf 5 sdf6sdf6sdf6sfdds6f9

edited the array to display better contrast.

This ended up working, thanks for all the help! Sorry I ended up double posting but I felt the original one was asked wrong and kinda had a wrong setup and I wasnt really understanding the other stuff. You saved my day.

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
  • Recently Browsing   0 members

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