botanic Posted September 2, 2007 Share Posted September 2, 2007 (edited) I am getting the "Badly formatted variable or macro" error from "$a[$trackon][$j] = $content[1]" any ideas? if StringInStr ( $content, "pitch" ) = true Then $content = StringSplit($content,"|") $j = $j+1 $a[$trackon][$j] = $content[1] $b[$trackon][$j] = $content[2] $c[$trackon][$j] = $content[3] $d[$trackon][$j] = $content[4] if $a = " " Then $e[$trackon][$j] = $content[5] EndIf if $a <> " " Then if $b = "On Note " then $e[$trackon][$j] = $content[5] EndIf EndIf EndIf Edited September 2, 2007 by botanic Link to comment Share on other sites More sharing options...
Nahuel Posted September 2, 2007 Share Posted September 2, 2007 (edited) I'm not sure I can help you here, but if I add "Global $trackon, $content" so I don't get the undeclared variables error, nothing happens. It seems to work. So maybe it has to do with what kinds of variables $trackon and $content are? I think you should post the whole script so the experts can help you Edited September 2, 2007 by Nahuel Link to comment Share on other sites More sharing options...
botanic Posted September 2, 2007 Author Share Posted September 2, 2007 (edited) well here is all of it ^.^ EDIT I also attached the txt file that it will be parsing expandcollapse popup#include <File.au3> #include <GUIConstants.au3> Global $jass, $file, $Progress, $ProgressID, $ProgressID2, $Percent2 global $difernce, $update, $somx, $i, $filelist, $filesize, $Progress, $updt Func _init() local $check, $name $file = FileOpen("midi.txt",0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file. Make shure it is named midi.txt in the same folder as this tool.") Exit EndIf $name = "test.txt";InputBox("Name", "Imput the filename that the midi will be converted to.") if FileExists($name) Then $check = MsgBox( 4, "Overwrite", "File exists overwrite?") if $check = 7 Then _init() Else FileDelete($name) EndIf EndIf $jass = FileOpen($name, 1) ; Check if file opened for writing OK If $jass = 0 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf EndFunc Func CreateProgress($x, $y, $w, $h, $Label="") Dim $Progress[3] $Progress[0] = GuiCtrlCreateProgress($x, $y, $w, $h, $PBS_SMOOTH ) $Progress[1] = GuiCtrlCreateLabel($Label, $x, $y+5, $w, $h, $SS_CENTER ) $Progress[2] = GuiCtrlCreateLabel( " ", $x, $y+35, $w, $h, $SS_CENTER ) GUICtrlSetBkColor($Progress[1], $GUI_BKCOLOR_TRANSPARENT) Return $Progress EndFunc Func CreateProgress2($x, $y, $w, $h, $Label="") Dim $Progress2[4] $Progress2[0] = GuiCtrlCreateProgress($x, $y+90, $w, $h, $PBS_SMOOTH ) $Progress2[1] = GuiCtrlCreateLabel($Label, $x, $y+95, $w, $h, $SS_CENTER ) $Progress2[2] = GuiCtrlCreateLabel( " ", $x, $y+125, $w, $h, $SS_CENTER ) $Progress2[3] = GuiCtrlCreateLabel("Overall Progress", $x, $y+65, $w, $h, $SS_CENTER ) GUICtrlSetBkColor($Progress2[1], $GUI_BKCOLOR_TRANSPARENT) Return $Progress2 EndFunc Func UpdateProgress($ProgressID,$ProgressID2, $Percent, $1line, $1filesize, $content, $action) GUICtrlSetData($ProgressID[0], $Percent) if $Percent < 10 Then $Percent = " " & StringLeft( $Percent, 4) ElseIf $Percent < 100 then $Percent = StringLeft( $Percent, 5) EndIf GUICtrlSetData($ProgressID[1], $1line & "/" & $1filesize & " " & $Percent & "%") GUICtrlSetData($ProgressID[2],$content) $Percent2 = $Percent/3 if $Percent2 < 10 Then $Percent2 = " " & StringLeft( $Percent2, 4) ElseIf $Percent2 < 100 then $Percent2 = StringLeft( $Percent2, 5) EndIf GUICtrlSetData($ProgressID2[0], $Percent2) GUICtrlSetData($ProgressID2[1], $Percent2) GUICtrlSetData($ProgressID2[2], $action) GUICtrlSetData($ProgressID2[3],"Overall Progress:") EndFunc func _readwrite() local $line, $content, $jassline, $tempstring, $tracks, $i, $trackon, $a, $b, $c, $d, $e, $startchan, $j, $BPM local $decide $line = 0 $jassline = 1 $trackon = 0 $j= 0 $file = FileOpen("midi.txt",0) $filesize = _FileCountLines ("midi.txt") $Form1 = GUICreate( "Midi JASS Tool", 392, 170, 193, 115 ) $Progress1 = CreateProgress( 16, 16, 353, 25 ) $Progress2 = CreateProgress2( 16, 16, 353, 25 ) GUICtrlSetData( -1, 25 ) GUISetState( @SW_SHOW ) While 1=1 $line = $line + 1 $content = FileReadLine( $file, $line) If @error = -1 Then ExitLoop $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch UpdateProgress($Progress1, $Progress2, $line / $filesize * 100, $line, $filesize, $content, "Gathering Variables") if StringLeft( $content, 5) = "MThd " then $tempstring = StringTrimLeft($content, 30) $tempstring = StringTrimRight($tempstring, 15) $tracks = $tempstring EndIf For $i = 5 to 1 Step -1 if $content = "Track #" & $i &" ******************************************" then $trackon = $i EndIf Next if StringInStr ( $content, "BPM=" ) = true Then $tempstring = StringSplit($content, "BPM=") $BPM = StringRight($tempstring, 3) EndIf if StringInStr ( $content, "pitch" ) = true Then $content = StringSplit($content,"|") $j = $j+1 $a[$trackon][$j] = $content[1] $b[$trackon][$j] = $content[2] $c[$trackon][$j] = $content[3] $d[$trackon][$j] = $content[4] if $a = " " Then $e[$trackon][$j] = $content[5] EndIf if $a <> " " Then if $b = "On Note " then $e[$trackon][$j] = $content[5] EndIf EndIf ; EndIf WEnd FileWrite($jass, "function tracks takes nothing returns integer" & @CRLF & " return " & $tracks & @CRLF & "endfunction" & @CRLF & @CRLF & @CRLF) EndFunc _init() _readwrite() Edited September 2, 2007 by botanic Link to comment Share on other sites More sharing options...
Nahuel Posted September 2, 2007 Share Posted September 2, 2007 I run it and I don't get the error... But I have no idea what it did :eek: Link to comment Share on other sites More sharing options...
botanic Posted September 2, 2007 Author Share Posted September 2, 2007 I had included ;'s before the problem statement so you wouldn't error untill you remove them. i took them out of the above post now. PS: what it does is take the attacked txt file that is a converted midi file and write a JASS program from it Link to comment Share on other sites More sharing options...
therks Posted September 2, 2007 Share Posted September 2, 2007 (edited) Excuse me, but are you assuming that code like this is going to work?$a[0][0] = 'variable'Cus it's not. An array has to be predefined before you can fill it with values. You didn't come from a PHP background by any chance, did you? Cus if you did, you're better off forgetting pretty much everything about arrays. PHP arrays (and also Javascript's, in case you've used that) are totally different from AutoIt's. It took me a long time to get used to that fact.*Edit: Whoops I posted instead of previewing. Edited September 2, 2007 by Saunders My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
botanic Posted September 2, 2007 Author Share Posted September 2, 2007 (edited) No :/ but humm that leave a problem for me.... Any idea how I can go about defining the correct number or arrays based on the number of lines in the largest track block... I could just set it to the total lines in the txt file but that would take insane amounts of ram (or so it would seem) EDIT: I did it with using total lines as the max array size and it seems to have worked and only used 80 or so MB of ram so that should be fine :/ still would like to optimize it tho if that is possible EDIT2 : wait no it doesn't work when I changed it to use the max lines :/ I think I might have hit the max array size... EDIT3: Ok well after reading up on the "subscript dimension range exceeded" im still lost :/ ne ways here is the updated code expandcollapse popup#include <File.au3> #include <string.au3> #include <GUIConstants.au3> Global $jass, $file, $Progress, $ProgressID, $ProgressID2, $Percent2, $trackon, $j global $difernce, $update, $somx, $i, $filelist, $filesize, $Progress, $updt, $number $number = 0 Func _init() local $check, $name $file = FileOpen("midi.txt",0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file. Make shure it is named midi.txt in the same folder as this tool.") Exit EndIf $name = "test.txt";InputBox("Name", "Imput the filename that the midi will be converted to.") if FileExists($name) Then $check = MsgBox( 4, "Overwrite", "File exists overwrite?") if $check = 7 Then _init() Else FileDelete($name) EndIf EndIf $jass = FileOpen($name, 1) ; Check if file opened for writing OK If $jass = 0 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf EndFunc Func CreateProgress($x, $y, $w, $h, $Label="") Dim $Progress[3] $Progress[0] = GuiCtrlCreateProgress($x, $y, $w, $h, $PBS_SMOOTH ) $Progress[1] = GuiCtrlCreateLabel($Label, $x, $y+5, $w, $h, $SS_CENTER ) $Progress[2] = GuiCtrlCreateLabel( " ", $x, $y+35, $w, $h, $SS_CENTER ) GUICtrlSetBkColor($Progress[1], $GUI_BKCOLOR_TRANSPARENT) Return $Progress EndFunc Func CreateProgress2($x, $y, $w, $h, $Label="") Dim $Progress2[4] $Progress2[0] = GuiCtrlCreateProgress($x, $y+90, $w, $h, $PBS_SMOOTH ) $Progress2[1] = GuiCtrlCreateLabel($Label, $x, $y+95, $w, $h, $SS_CENTER ) $Progress2[2] = GuiCtrlCreateLabel( " ", $x, $y+125, $w, $h, $SS_CENTER ) $Progress2[3] = GuiCtrlCreateLabel("Overall Progress", $x, $y+65, $w, $h, $SS_CENTER ) GUICtrlSetBkColor($Progress2[1], $GUI_BKCOLOR_TRANSPARENT) Return $Progress2 EndFunc Func UpdateProgress($ProgressID,$ProgressID2, $Percent, $1line, $1filesize, $content, $action, $number) Local $total GUICtrlSetData($ProgressID[0], $Percent) if $Percent < 10 Then $Percent = " " & StringLeft( $Percent, 4) ElseIf $Percent < 100 then $Percent = StringLeft( $Percent, 5) EndIf GUICtrlSetData($ProgressID[1], $1line & "/" & $1filesize & " " & $Percent & "%") GUICtrlSetData($ProgressID[2],$content) $Percent2 = $Percent/3 $total = ($number * (1/3) * 100) + $Percent2 if $total < 10 Then $total = " " & StringLeft( $total, 4) ElseIf $total < 100 then $total = StringLeft( $total, 5) EndIf GUICtrlSetData($ProgressID2[0], $total) GUICtrlSetData($ProgressID2[1], $total & "%") GUICtrlSetData($ProgressID2[2], $action) GUICtrlSetData($ProgressID2[3],"Overall Progress:") EndFunc func _readwrite() local $line, $content, $jassline, $tempstring, $tracks, $i, $a, $b, $c, $d, $e, $startchan, $BPM local $decide, $all $all =0 $line = 0 $jassline = 1 $trackon = 0 $j= 0 $file = FileOpen("midi.txt",0) $filesize = _FileCountLines ("midi.txt") $Form1 = GUICreate( "Midi JASS Tool", 392, 170, 193, 115 ) $Progress1 = CreateProgress( 16, 16, 353, 25 ) $Progress2 = CreateProgress2( 16, 16, 353, 25 ) GUICtrlSetData( -1, 25 ) GUISetState( @SW_SHOW ) While 1=1 $line = $line + 1 $content = FileReadLine( $file, $line) If @error = -1 Then ExitLoop $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch UpdateProgress($Progress1, $Progress2, $line / $filesize * 100, $line, $filesize, $content, "Gathering Variables",0) if StringLeft( $content, 5) = "MThd " then $tempstring = StringTrimLeft($content, 30) $tempstring = StringTrimRight($tempstring, 15) $tracks = $tempstring Dim $a[$tracks][$filesize] Dim $b[$tracks][$filesize] Dim $c[$tracks][$filesize] Dim $d[$tracks][$filesize] Dim $e[$tracks][$filesize] EndIf For $i = 5 to 1 Step -1 if $content = "Track #" & $i &" ******************************************" then $trackon = $i EndIf Next if StringInStr ( $content, "BPM=" ) = true Then $oRstring=$content&" " $String1=_StringBetween($oRstring,"="," ") $String2=_StringBetween($oRstring,"quarter="," ") $BPM = $String1[0] EndIf if StringInStr ( $content, "pitch" ) = true Then $content = StringSplit($content,"|") $all = $all+1 $j = $j+1 $a[$trackon][$j] = $content[1] $b[$trackon][$j] = $content[2] $c[$trackon][$j] = $content[3] $d[$trackon][$j] = $content[4] if $content[0] = 5 Then $e[$trackon][$j] = $content[5] EndIf EndIf WEnd FileWrite($jass, "function tracks takes nothing returns integer" & @CRLF & " return " & $tracks & @CRLF & "endfunction" & @CRLF & @CRLF & @CRLF) For $i = 1 to $all For $trackon = 1 to $tracks $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch $tempstring = $i FileWrite($jass, $a[$trackon][$i]) FileWrite($jass, $b[$trackon][$i]) FileWrite($jass, $c[$trackon][$i]) FileWrite($jass, $d[$trackon][$i]) FileWrite($jass, $e[$trackon][$i]) UpdateProgress($Progress1, $Progress2, ($i*5) / $all * 100, ($i*5), $all, $tempstring, "Writing Note Functions",1) Next Next EndFunc _init() _readwrite() Edited September 2, 2007 by botanic Link to comment Share on other sites More sharing options...
therks Posted September 2, 2007 Share Posted September 2, 2007 Oooh crap, I thought I hit Add Reply before I left... oh well, here's the post I started a few hours ago... You can redefine the size of an array as you go. Personally, I've been using a bit of code like this. Dim $array[10] ; We'll start with 10 for now. Dim $arrayCounter = 0 ; Something to keep track of where we are in the array. For $i = 1 to 50 ; We add the new value at the index specified by $arrayCounter. $array[$arrayCounter] = Random(1, 100, 1) ; We increment $arrayCounter by 1. $arrayCounter += 1 ; Here's the magic part, since we incremented $arrayCounter ; we check here to see if it's breached the size of the array ; if it has, we resize the array with the "ReDim" keyword. ; This keyword allows you to resize the array, while keeping ; all of it's data. If $arrayCounter >= UBound($array) Then ; We'll increase the size by 10. ; I prefer to do it in larger steps like this instead of one ; at a time because I believe it was brought up before that it's ; more intensive to resize the array on every loop ReDim $array[$arrayCounter + 10] EndIf Next ; This step isn't required, but I think it makes the array a little cleaner ; This just trims it down to the size of the actual data within. Since we were ; going up by chunks of 10 at a time, if the array hit say 41 entries, that's 9 ; blank items in the array. ReDim'ing down to 41 just trims off those blanks. ReDim $array[$arrayCounter] My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now