Sign in to follow this  
Followers 0
Pa Callender

Vigenere Cipher - "For" has no matching "Next"...

4 posts in this topic

#1 ·  Posted (edited)

Could someone please identify why this script keeps throwing up this error:

C:\Documents and Settings\pmcallender\My Documents\My AutoIt Scripts\AutoEd (not au3)\tmp.au3 (31) : ==> "For" statement has no matching "Next" statement.:

Func alphavig($offset)

Here's the script:

#NoTrayIcon
#include <Array.au3>
Dim $VigCipher[26]
For $i = 0 to 25
$VigCipher[$i] = alphavig($i)
$askKword = StringUpper(InputBox("Keyword","Enter the keyword"))
$askString = StringUpper(InputBox("String","Enter the string"))
Dim $tempKword[Len($askKword)], $tempString[Len($askString)], $resString[Len($askString)]
For $num = 1 to Len($askKword)
   $tempKword[$num-1] = StringMid($askKword,$i,1)
Next
For $numi = 1 to Len($askString)
   $tempString[$num-1] = StringMid($askString,$i,1)
Next
Dim $kara = Len($askKword), $obili = 0
For $numit = 0 to Len($askString)-1
   If StringIsUpper($tempString[$numit]) = 1 Then
      $tempchar = alphanum($tempString[$numit])
      $tempytwo = alphanum($tempKword[$obili])
      $resString[$numit] = $VigCipher[$tempchar][$tempytwo]
      $obili = $obili + 1
      If $obili = Len($askKword)-1 Then
         $obili = 0
      EndIf
   Else
      $resString[$numit] = $tempString[$numit]
   EndIf
Next
MsgBox(0,"Completed!",_ArrayToString($resString,""))
Exit
Func alphavig($offset)
   Dim $vig[26], $res[26]
   $vig[0] = "A"
   $vig[1] = "B"
   $vig[2] = "C"
   $vig[3] = "D"
   $vig[4] = "E"
   $vig[5] = "F"
   $vig[6] = "G"
   $vig[7] = "H"
   $vig[8] = "I"
   $vig[9] = "J"
   $vig[10] = "K"
   $vig[11] = "L"
   $vig[12] = "M"
   $vig[13] = "N"
   $vig[14] = "O"
   $vig[15] = "P"
   $vig[16] = "Q"
   $vig[17] = "R"
   $vig[18] = "S"
   $vig[19] = "T"
   $vig[20] = "U"
   $vig[21] = "V"
   $vig[22] = "W"
   $vig[23] = "X"
   $vig[24] = "Y"
   $vig[25] = "Z"
   For $i = 0 to 25
      $res[$i] = $vig[$i+$offset]
   Next
   Return $res
EndFunc
Func Alphanum($in)
   Dim $out
   $mid = alphavig(0)
   If IsString($in) Then
      $out = _ArraySearch($mid,$in) + 1
   Else If IsNumber($in) Then
      $out = $mid[$in-1]
   Else
      SetError(1)
   EndIf
   Return $out
EndFunc

Apologies for the dodgy var names - they just came off the top of my head.

Thanks in advance

EDIT: Removed mis-interpreted UBB Font tags

Edited by Pa Callender

[size="4"]YOU SHALL NOT PARSE!![/size]

Share this post


Link to post
Share on other sites



Because you are missing a Next keyword. Correctly indented code shows the fault.

After a Tidy of script shows errors

#NoTrayIcon
#include <Array.au3>
Dim $VigCipher[26]
For $i = 0 To 25
    $VigCipher[$i] = alphavig($i)
    $askKword = StringUpper(InputBox("Keyword", "Enter the keyword"))
    $askString = StringUpper(InputBox("String", "Enter the string"))
    Dim $tempKword[Len ($askKword) ], $tempString[Len ($askString) ], $resString[Len ($askString) ]
    For $num = 1 To Len ($askKword)
        $tempKword[$num - 1] = StringMid($askKword, $i, 1)
    Next
    For $numi = 1 To Len ($askString)
        $tempString[$num - 1] = StringMid($askString, $i, 1)
    Next
    Dim $kara = Len ($askKword), $obili = 0
    For $numit = 0 To Len ($askString) - 1
        If StringIsUpper($tempString[$numit]) = 1 Then
            $tempchar = Alphanum($tempString[$numit])
            $tempytwo = Alphanum($tempKword[$obili])
            $resString[$numit] = $VigCipher[$tempchar][$tempytwo]
            $obili = $obili + 1
            If $obili = Len ($askKword) - 1 Then
                $obili = 0
            EndIf
        Else
            $resString[$numit] = $tempString[$numit]
        EndIf
    Next
    MsgBox(0, "Completed!", _ArrayToString($resString, ""))
    Exit
;### Tidy Error: Level error -> "For" Not closed before Func statement.
;### Tidy Error: Level error -> "Func" cannot be inside any IF/Do/While/For/Case/Func statement.
    Func alphavig($offset)
        Dim $vig[26], $res[26]
        $vig[0] = "A"
        $vig[1] = "B"
        $vig[2] = "C"
        $vig[3] = "D"
        $vig[4] = "E"
        $vig[5] = "F"
        $vig[6] = "G"
        $vig[7] = "H"
        $vig[8] = "I"
        $vig[9] = "J"
        $vig[10] = "K"
        $vig[11] = "L"
        $vig[12] = "M"
        $vig[13] = "N"
        $vig[14] = "O"
        $vig[15] = "P"
        $vig[16] = "Q"
        $vig[17] = "R"
        $vig[18] = "S"
        $vig[19] = "T"
        $vig[20] = "U"
        $vig[21] = "V"
        $vig[22] = "W"
        $vig[23] = "X"
        $vig[24] = "Y"
        $vig[25] = "Z"
        For $i = 0 To 25
            $res[$i] = $vig[$i + $offset]
        Next
        Return $res
    EndFunc
;### Tidy Error: Level error -> "For" Not closed before Func statement.
;### Tidy Error: Level error -> "Func" cannot be inside any IF/Do/While/For/Case/Func statement.
    Func Alphanum($in)
        Dim $out
        $mid = alphavig(0)
        If IsString($in) Then
            $out = _ArraySearch($mid, $in) + 1
        Else If IsNumber($in) Then
            $out = $mid[$in - 1]
        Else
            SetError(1)
        EndIf
        Return $out
    EndFunc
    
    Exit
    
;### Tidy Error: Level error -> "For" Not closed before Func statement.
;### Tidy Error: Level error -> "Func" cannot be inside any IF/Do/While/For/Case/Func statement.
    Func OnAutoItStart()
        If WinExists(@ScriptName & '_Interpreter') Then Exit
        AutoItWinSetTitle(@ScriptName & '_Interpreter')
    EndFunc

Fixing the Next where it should go could clear up the errors.

:whistle:

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thank you very much! I didn't indent the code correctly because I don't use SciTe4AutoIt3, so I don't have tidy. But thanks to you and your Tidyed version of my code, I realised where the mistake was. Thanyou very very much!

Edit: Also realised I'm still in the times when I thought KiXtart was god:

Len($askString)oÝ÷ Ûú®¢×¥u·ºÚ"µÍÝ[Ó[ ÌÍØÚÔÝ[Ê
Edited by Pa Callender

[size="4"]YOU SHALL NOT PARSE!![/size]

Share this post


Link to post
Share on other sites

Tidy can be used by other editors as an addon. You can download it from here. It just takes a path to the script as a parameter so is easy to setup.

:whistle:

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
Sign in to follow this  
Followers 0