Thanks, Witto. It would have been a little bit easier for me to see what solved the initial problem actually, if you have left your cosmetics aside, but ok. 
To be honest, i dont get these "no vars, macros in stings"- hype. I always found it a feature to dont have to type all these little "+"'s. Where is the disadvantage?
Anyway, the key for the problem was to place the "add to dict"-part at the end after scanning one line. As it is the same code as above i placed it in a function (think in functions?
) And now it works fine. Sometimes you dont see what is right in front of you. Thanks again.
For the quote-check: I fixed that, i just forgot to change it in the code i posted here. (Its just the "and not"-statement before setting quote1 or 2.
Code:
; ===========================================================================================
;
; Script Information
;
$Title = "VarScan 1.1b
; Author: therob / Function combsort () by Shawn Tassie
; Description: Scans kixfiles for Variables and missing quotes and writes a reportfile
; -> Syntax of the reportfile: [variable] - [linenumbers in which the variable is used]
;
; ===========================================================================================
Break On
;.. variables
$match = 0
$Var = "$"
$stopchars = " <>()+-.,'#;:?=/&\}][{*!@@"
$TextMode = 1
$dictAllVars = CreateObject ("Scripting.Dictionary")
$dictAllVars.CompareMode = $TextMode
$allLines = "none"
$VarCount = 0
$orphans = ""
$orphcount = 0
$linecount = 0
$quote1 = 0
$quote2 = 0
;... select source
$System = CreateObject("Kixtart.System")
$openFile = $System.openFileDialog()
$openFile.Title = "Open a script to scan"
$openFile.InitialDirectory = @curDIR
$openFile.Filter = "KiX Files(*.kix;*.udf;*.scr)|*.kix;*.udf;*.scr|All files (*.*)|*.*"
$openFile.Title = "Select a kixfile to scan..."
$openFile.DefaultExt = "kix"
$ = $openFile.ShowDialog()
$input = $OpenFile.FileName
$report = $input + "-VarScanReport.txt"
If $input = ""
$ = MessageBox("No file selected.", "Whoo", 262208, 5)
Quit
EndIf
; ..
; ... scan file
$=Open (1,$input,2)
$Line = ReadLine(1)
While NOT @error
If $quote1 = 1 OR $quote2 =1
$quoterror = $quoterror + "Attention: Presumably a missing quotation mark in: "+ @CRLF + $linecount + " " + $curline + @crlf +@crlf
$quoteErrCount = $quoteErrCount + 1
EndIf
$quote1 = 0 $quote2 = 0
$linecount = $linecount + 1
For $c = 1 to Len($Line)
$Char = SubStr ($Line, $c, 1)
If $Char = ";" AND NOT ($quote1 = 1 OR $quote2 = 1)
$c = Len($Line)
EndIf
If $Char = "$"
$match = 1
EndIf
If $match = 1 AND NOT $char ="$"
If InStr ($stopchars,$char) <> 0 OR Asc ($char) = 34
addtodict ()
Else
$Var = $var + $char
EndIf
EndIf
Select ;look for --> "
Case $Char = '"' AND $quote1 = 1
$quote1 = 0
Case $Char = '"' AND NOT $quote2 = 1
$quote1 = 1
$curline = $line
EndSelect
Select ;look for --> '
Case $Char = "'" AND $quote2 = 1
$quote2 = 0
Case $Char = "'" AND NOT $quote1 = 1
$quote2 = 1
$curline = $line
EndSelect
Next
:readAline
Select
Case Len ($linecount) = 1 $wslinecount = "000" + $linecount
Case Len ($linecount) = 2 $wslinecount = "00" + $linecount
Case Len ($linecount) = 3 $wslinecount = "0" + $linecount
Case 1 $wslinecount = $linecount
EndSelect
$wholescript = $wholescript + $wslinecount + " " + $line + @CRLF
If $match = 1
addtodict ()
EndIf
$Line = ReadLine(1)
Loop
; ..
; ... sort and write report
If Exist ($report) Del $report EndIf
$ = Open (2,$report,5)
$ = WriteLine (2, $Title + " / Scanned file: "+$input+ @CRLF+ @CRLF)
; ..Sort Dict
For Each $VarNameA In $dictAllVars.Keys
$VarCount = $VarCount + 1
$VarString = $VarString + "," + $VarNameA
Next
$varArray = combsort (Split (SubStr ($VarString,2),","))
;... search for orphans and export the variables
For Each $VarName In $varArray
$VarLines = $dictAllVars.Item ($VarName)
If NOT InStr ($Varlines,",")
$orphans = $orphans + $varname + " " + $Varlines + @CRLF
$orphcount = $orphcount + 1
EndIf
$reportline = $Varname + " " + $VarLines + @CRLF
$ = WriteLine (2,$reportline)
Next
;... export rest
$ = WriteLine (2, "-----------------------"+@CRLF+ "All Variables: "+ $VarCount )
$ = WriteLine (2, @CRLF+@CRLF+ @CRLF+ "Orphans: " + $orphcount + @CRLF+ "-----------------------"+ @CRLF + $orphans)
If $quoteErrCount > 0
$ = WriteLine (2, @CRLF+@CRLF+ @CRLF+ "Possible Quote-Errors: " + $quoteErrCount + @CRLF+ "-----------------------"+ @CRLF+ $quoterror)
Else
$ = WriteLine (2, @CRLF+@CRLF+ @CRLF+ "No Quote-Errors found.")
EndIf
$ = WriteLine (2, @CRLF+@CRLF+ @CRLF+ "Scanned script:"+ @CRLF+ "-------------------------"+ @CRLF + $wholescript)
$=Close (1)
$=Close (2)
Run "%COMSPEC% /c " + $report
Quit 0
; ..
;... functions
Function Addtodict ()
; .. add to Dict
If $dictAllVars.Exists($var)
$tempLines = $dictAllVars.Item ($var)
$allLines = $tempLines + ", " + $linecount
DictionarySet ($dictAllVars,"$var","$allLines")
Else
$allLines = $linecount
DictionarySet ($dictAllVars,"$var","$allLines")
EndIf
$Match = 0 $Var = "$"
EndFunction
Function DictionarySet ($DictionaryObject, $key, $value)
If VarTypeName($key) = "Empty"
Quit 13
EndIf
If $DictionaryObject.Exists($key)
$DictionaryObject.Remove($key)
EndIf
$DictionaryObject.Add($key, $value)
Exit @error
EndFunction
Function combsort($v, optional $o)
Dim $i,$j,$m,$s,$g
$n=Ubound($v)
$g=$n
If $g
While $g > 1 OR NOT $s
$g=($g*1000)/1279
If $g < 1
$g=1
EndIf
$s=1
For $i = 0 to $n-$g
$j=$i+$g
If ($v[$i] > $v[$j] AND NOT $o) OR ($v[$i] < $v[$j] AND $o)
$m = $v[$i]
$v[$i] = $v[$j]
$v[$j] = $m
$s=0
EndIf
Next
Loop
$combsort = $v
Else
$combsort = 0
EndIf
EndFunction
Export:
Code:
VarScan 1.1b / Scanned file: E:\scripte\mixed\scanKixforVariables\tes3.kix
$emessage 1, 3
$errcount 2, 3
$rc 3
$test 5, 5
$TextBox4 2
-----------------------
All Variables: 5
Orphans: 2
-----------------------
$rc 3
$TextBox4 2
Possible Quote-Errors: 1
-----------------------
Attention: Presumably a missing quotation mark in:
2 $TextBox4.Text = $errcount " ; <--- real quoteerror here
Scanned script:
-------------------------
0001 Function ermes ($emessage)
0002 $TextBox4.Text = $errcount " ; <--- real quoteerror here
0003 $rc= WriteLine (9," @time ;Fehler $errcount ; "+$emessage+" ###@CRLF")
0004 ; this is a $variable and a " in a comment
0005 $test = $test + "a quote in a quote --> ' <--"
0006 EndFunction
0007