Wicked_Caty

Unicode code of an array

11 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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 "")

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Which data is assigned ´to $test? And also without any include the script has not 357 lines. May be you have to change to 

For $i = 0 To $len-1 ;Step 1 not nececary

if not post the complete script.

Edited by AutoBert

Share this post


Link to post
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).

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

I see $Text isn't a array

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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
1 person likes this

Share this post


Link to post
Share on other sites

Thanks :D it works now :D

Had to #include <StringConstants.au3> though :) 

Thanks for the awesome help!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Easy task and much better as to decrypt boter's wishes. AutoIt is not the first programming langue? i think C or Pascal was first?

Edited by AutoBert

Share this post


Link to post
Share on other sites

I indeed tried some other programming languages first :) I did C++, vbs and python before, but switched to autoit because it's enough for my basic needs and A LOT easier than C++ for example.

Share this post


Link to post
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.

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

  • Similar Content

    • rootx
      By rootx
      I need help with unicode char ü I get some text from online json but if try to read 4 example Zürich I heave  Zürich.
      How can I convert with autoit unicode to a clear character readable? thx
    • rootx
      By rootx
      I write this script to compare to array, well Do you have a better way to do it?
      #include <Constants.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> $a = FileSelectFolder("seleziona cartella A",@ScriptDir) $fold_A = _FileListToArrayRec($a,"*",2,1,0,1) $b = FileSelectFolder("seleziona cartella B",@ScriptDir) $fold_B = _FileListToArrayRec($b,"*",2,1,0,1) $tota = UBound($fold_A)-1 $totb = UBound($fold_B)-1 If $tota > $totb Then findx($fold_A,$fold_B) Else findx($fold_B,$fold_A) EndIf Func findx($min,$max) For $i = 0 To UBound($min)-1 $found = _ArraySearch($max, $min[$i]) If $found = -1 Then ConsoleWrite($min[$i]&@CRLF) EndIf Next EndFunc  
    • Jibberish
      By Jibberish
      I am trying to add data to an array and I keep getting the error "Subscript used on non-accessible variable ".
      #include <array.au3> ; Includes, etc ~ ~ ~ Local $aOptionsArray[3] $aOptionsArray = CheckboxesAndRadioButtons() _ArrayDisplay($aOptionsArray) Func CheckboxesAndRadioButtons() ; Create Checkboxes and Radio Buttons and read the results ~ ~ ~ ; Radio Buttons to Array ; $aOptions[0] = $bTestSelectForever ; $aOptions[1] = $bTestSelect3Times ; $aOptions[2] = $bTestSelectOnce If $bSelect1 = 1 Then $aOptions[0] = "True" Else $aOptions[0] = "False" <<< This is where the error occurs. EndIf If $bSelect2 = 1 Then $aOptions[1] = "True" Else $aOptions[1] = "False" EndIf If $bSelect3 = 1 Then $aOptions[2] = "True" Else $aOptions[2] = "False" EndIf Return $aOptions EndFunc Is putting data into an array while in a If - Then - Else illegal?
    • JustinZandee
      By JustinZandee
      I need a random string generator which creates 15 letters/numbers.
      How can I make that?
    • anoig
      By anoig
      Hi all, 

      First, I want to give a huge shout-out to the community. I'm completely self-taught, and have never had to actually ask a question before because the forum is that good at answering questions and explaining things. However, I'm kind of stumped here, and I've been stuck on this problem for almost a full day.

      I'm working on a script to populate drafts of deeds at work. I have the main GUI and  a function (ctrl($n) and read()) for adding fields to find and data to replace it with to an array for later use with _word_docfindreplace. All of that works. However, due to the way I have the forms set up, I need to create additional fields and info based on the data that's there. Specifically, if there's only one buyer, I need to add the field [Buyer1&2] and the data in $aArray_Base for [Buyer 1]. I also need to add a field [Buyer 2] and have a blank data set in the next column over in the array, and I need to do the same for the Seller. To this end, the function parties() sets boolean variables $2buyers and $2sellers accordingly. Then, I have buyers() and sellers() to populate the data. 

      The problem that I'm running into is that each function works... when ONLY the buyer 1 name field is filled, and when ONLY the seller 1 field is filled.

      So if I fill Buyer 1 Name and save it, the data is populated correctly. But when I fill Buyer 1 and Seller 1 name, only the buyer 1 data populates correctly. Worse, when I fill several fields, neither populate correctly. I have no idea why this happens. I've added messageboxes to debug throughout the entire process and can't pinpoint what's causing the issue. The entire script is below. The function(s) in question are buyers() and sellers(). Only Sellers() has messageboxes throughout.

      Can someone help walk me through what might be causing this and help me find a solution? Thanks a ton in advance, and sorry for the wall of text.
      -Anoig