Jump to content

Unicode code of an array


Recommended Posts

I made a small program that should get the unicode code of an array, save it in a variable, and write it into an file. That should be done for every array of a string.

For $i = 0 To $len Step 1           ; $len is the length of the text I enter previously

    $tmp0 = ChrW($text[$i])         ; $text is the text
    FileWrite($f, $tmp0 & @CRLF)    ; $f is the file I write into
    $tmp0 = ""

Next

Building and compiling finish without raising warnings or errors, but the program fails when it's supposed to get the unicode code of that array... 

The error message says "Line 357 (File "D:\documents\coding\Crypt\Crypt.exe"): Error: Subscript used on non-accessible variable."

My code ends at line 141, so it's not a problem with my code as such. I'd say that ChrW() isn't able to handle the variable I give it. I don't think it's a problem with the string, but I suspect that it's because I use a variable as an index ($text[$i]).

If my clue was right, how do I fix it? If not, what could be the problem? Thanks for the help!

Edited by Wicked_Caty
Link to comment
Share on other sites

I don't know where and how you declared and defined $len. I don't know what the contents of $text are.

My only guess, based on the small snippet of code you posted, is you did $len as the full length of the string but forgot to subtract 1 (since string lengths start at 1 unless the string is "")

Link to comment
Share on other sites

Quote

I don't know where and how you declared and defined $len. I don't know what the contents of $text are.

Local $len = StringLen($text)
Local $text = InputBox("UCC", "Enter the text")

$text is entered by the user, but it will be plain text like "abc" or "test" or "hello". Sometimes there might be numbers in there too, but really nothing special (yet).

Quote

My only guess, based on the small snippet of code you posted, is you did $len as the full length of the string but forgot to subtract 1 (since string lengths start at 1 unless the string is "")

I didn't know that, thanks. Unfortunately, neither subtracting 1 from $len, nor using $i = 1 in the for-loop works (same error).

Link to comment
Share on other sites

Okay, here's the full script. Maybe you find the problem in there.

(before you tell me, yes, I know that this is probably the weakest encryption ever. It's just for learning autoit a bit better and hiding my personal notes from friends and family)

Crypt.au3

Edit: it's not fully finished yet, so please excuse some unnecessary things in there.

 

Edited by Wicked_Caty
Link to comment
Share on other sites

Func Encryption($log, $text, $file)

   Local $len = StringLen($text)
   Local $f = FileOpen($file, $FO_APPEND)
   Local $tmp0 = ""
   Local $tmp1 = ""
   Local $aText = StringSplit($text,'',2)

   For $i = 0 To UBound($aText)-1

      $tmp0 = ChrW($atext[$i])
      FileWrite($f, $tmp0 & @CRLF)
      $tmp0 = ""
      $tmp1 = ""

   Next

   FileWrite($log, "Text encrypted on " & @MDAY & "." & @MON & "." & @YEAR & " at " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)
   FileClose($f)

EndFunc

Just making string $Text to a array and work with should be the solution. But this is not crypted, see there for

_Crypt_EncryptData
Edited by AutoBert
Link to comment
Share on other sites

Idk about  A LOT easier than C++. What you're doing is very simple and pretty easy in C++ too. If all you're doing is some simple stuff for fun then AutoIt is fine. If you want to get into programming don't make AutoIt your go to. It's simple, easy, and the syntax is forgiving, but it's more of a supplement than a full course meal.

Python, I'm told, is a good beginner language, as is Java, and if you want to do something easy in .net than C# is another good one. C++ can be hard and difficult for a beginner but if you get a good book, and spend the time reading and understanding what it's trying to teach you, you will do fine. Also, classes and objects are like crack and a good IDE makes writing code so much better.

Just my two cents.

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

×
×
  • Create New...