James Posted December 11, 2008 Posted December 11, 2008 Hi guys, I haven't been using AutoIt for a couple of months now as I have been working with PHP a lot and college work has got in the way. Today, a study day I have decided to complete or near complete OEMWizard. I have fixed a couple of bugs and changed some things around. I have now thought about including a function which will covert ~VER to @OSVERSION which from the feedback I have had from friends and the companys whom use OEMWizard would like. So this is my code: ; This function is our "in-program" tags lexer Func LexTags($lexControl) Local $Tags[3][2] = [["~VER", @OSVersion], ["~SERVICE", @OSServicePack], ["~DATE", @MDAY & "/" & @MON & "/" & @YEAR]] For $lex = 1 to 3 If StringInStr(GUICtrlRead($lexControl), $Tags[$lex][1], 1) Then StringReplace(GUICtrlRead($LexControl), $Tags[$Lex][1], $Tags[$Lex][2]) EndIf Next EndFunc No errors when starting the script obviously but when the function gets called I get this error, C:\Documents and Settings\James\My Documents\Programming\AutoIt\Projects\OEMWizard\OEMWiz.au3 (516) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Local $Tags[2][3] = [["~VER", @OSVersion], ["~SERVICE", @OSServicePack], ["~DATE", @MDAY & "/" & @MON & "/" & @YEAR]] Local $Tags[2][3] = [["~VER", @OSVersion], ["~SERVICE", @OSServicePack], [^ ERROR And I cannot see why it's showing that one and not any others. Please help James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
James Posted December 11, 2008 Author Posted December 11, 2008 Well this doesn't error but it doesn't replace the tags either. ; This function is our "in-program" tags lexer Func LexTags($lexControl) Local $Tags[3][2] = [["~VER", @OSVersion], ["~SERVICE", @OSServicePack], ["~DATE", @MDAY & "/" & @MON & "/" & @YEAR]] For $lex = 0 to 2 If StringInStr(GUICtrlRead($lexControl), $Tags[$lex][1]) Then StringReplace(GUICtrlRead($LexControl), $Tags[$Lex][1], $Tags[$Lex][2]) EndIf Next EndFunc I'm guessing arrays declared like above, their index is 0. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
Malkey Posted December 11, 2008 Posted December 11, 2008 Well this doesn't error but it doesn't replace the tags either. ; This function is our "in-program" tags lexer Func LexTags($lexControl) Local $Tags[3][2] = [["~VER", @OSVersion], ["~SERVICE", @OSServicePack], ["~DATE", @MDAY & "/" & @MON & "/" & @YEAR]] For $lex = 0 to 2 If StringInStr(GUICtrlRead($lexControl), $Tags[$lex][1]) Then StringReplace(GUICtrlRead($LexControl), $Tags[$Lex][1], $Tags[$Lex][2]) EndIf Next EndFunc I'm guessing arrays declared like above, their index is 0.Local $Tags[3][2] = [["~VER", @OSVersion], ["~SERVICE", @OSServicePack], ["~DATE", @MDAY & "/" & @MON & "/" & @YEAR]] $Tags has elements in 3 rows and 2 columns. The counting of the index of the array starts at zero, then one, then two. This equates to 3 rows. Base zero For $lex = 1 to 3 If StringInStr(GUICtrlRead($lexControl), $Tags[$lex][1], 1) Then NOTICE $Tags[$lex][1] will be $Tags[3][1] The 3 subscript dimension range exceeded. Maximium indexes or "subscript dimension ranges" allowed with Local $Tags[3][2] declaration is $Tags[2][1] In your script above, StringReplace(GUICtrlRead($LexControl), $Tags[$Lex][1], $Tags[$Lex][2]), you can not have $Tags[$Lex][2]. The 2 subscript dimension range exceeded. #Include <Array.au3> Local $Tags[3][2] = [["~VER", @OSVersion], ["~SERVICE", @OSServicePack], ["~DATE", @MDAY & "/" & @MON & "/" & @YEAR]] ConsoleWrite($Tags[0][0] & @CRLF) _ArrayDisplay($Tags)
James Posted December 11, 2008 Author Posted December 11, 2008 Oh I see, well now I have this: ; This function is our "in-program" tags lexer ; This function is our "in-program" tags lexer Func LexTags($lexControl) Local $Tags[3][2] = [["~VER", @OSVersion], ["~SERVICE", @OSServicePack], ["~DATE", @MDAY & "/" & @MON & "/" & @YEAR]] For $lex = 0 to 2 If StringInStr(GUICtrlRead($lexControl), $Tags[$lex][0]) Then StringReplace(StringInStr(GUICtrlRead($LexControl), $Tags[$lex][0]), $Tags[$Lex][0], $Tags[$Lex][1]) EndIf Next EndFunc But now it replaces everything with a 0 even if I was to put "Version: ~VER" this is probably really blindingly simple but I cannot see it. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
Malkey Posted December 11, 2008 Posted December 11, 2008 Oh I see, well now I have this: ; For $lex = 0 to 2 If StringInStr(GUICtrlRead($lexControl), $Tags[$lex][0]) Then StringReplace(StringInStr(GUICtrlRead($LexControl), $Tags[$lex][0]), $Tags[$Lex][0], $Tags[$Lex][1]) EndIf Next But now it replaces everything with a 0 even if I was to put "Version: ~VER" this is probably really blindingly simple but I cannot see it.Look up StringInStr() in help. Return Value Success: Returns the position of the substring.
Malkey Posted December 11, 2008 Posted December 11, 2008 Try this. ; This function is our "in-program" tags lexer Func LexTags($lexControl) Local $Tags[3][2] = [["~VER", @OSVersion], ["~SERVICE", @OSServicePack], ["~DATE", @MDAY & "/" & @MON & "/" & @YEAR]] For $lex = 0 to 2 If StringInStr(GUICtrlRead($lexControl), $Tags[$lex][0]) > 0 Then StringReplace(GUICtrlRead($LexControl), $Tags[$Lex][0], $Tags[$Lex][1]) EndIf Next EndFunc
James Posted December 11, 2008 Author Posted December 11, 2008 Nope, this is still converting, "Version: ~VER" to 0. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
Kip Posted December 11, 2008 Posted December 11, 2008 (edited) Func LexTags($lexControl) Local $Tags[3][2] = [["~VER", @OSVersion], ["~SERVICE", @OSServicePack], ["~DATE", @MDAY & "/" & @MON & "/" & @YEAR]] For $lex = 0 to UBound($Tags)-1 $sRead = GUICtrlRead($lexControl) If StringInStr($sRead, $Tags[$lex][0]) Then GUICtrlSetData($lexControl,StringReplace($sRead, $Tags[$lex][0], $Tags[$lex][1])) EndIf Next EndFunc Should work. Edited December 11, 2008 by Kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
James Posted December 11, 2008 Author Posted December 11, 2008 Nope still 0 Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
James Posted December 11, 2008 Author Posted December 11, 2008 Fixed it. I forgot to return the value as well. Thanks guys! Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
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