Jump to content

Array variable has incorrect number of subscripts


87450kalle
 Share

Recommended Posts

  • Moderators

This doesn't look right..

$var2 = FileOpenDialog($message, "C:\Windows\system32\drivers\", "All files (*.*)")

From help it looks like it may look like this:

$var2 = FileOpenDialog($message, "C:\Windows\system32\drivers\", "All (*.*)")

Anyway... Cleaned up a your code a bit too... Tidy is a wonderful thing ;)

#include <file.au3>
#include <GuiConstants.au3>
Global $msg
Global $Button_next
Global $Label_select
Global $selectmodell
Global $Combo
Global $Combo2
Global $line
Global $startgui
Global $selecttype
Global $olddriver
Global $oldversion
Global $oldurl
Global $thirdgui
Global $fourthgui
Global $file
Global $newurl
Global $newurltemp
Global $newfilever
Global $var2
Global $newinfotemp
Global $newinfo
Global $l

Call("Start")

Func Start()
   
   $startgui = GUICreate("RIS - Driver Update Admin", 310, 200, (@DesktopWidth - 400) / 2, (@DesktopHeight - 400) / 2)
   
   $Group_1 = GUICtrlCreateGroup("RIS - PC Driver Update Admin ", 30, 20, 250, 60)
   $Label_start = GUICtrlCreateLabel("This wizard will help you to update the RIS - Drvier Update utility ", 40, 40, 190, 30)
   $Combo = GUICtrlCreateCombo("", 70, 110, 170, 21, $CBS_DROPDOWNLIST)
   GUICtrlSetData(-1, "Dell x200")
   GUICtrlSetData(-1, "Dell x300")
   GUICtrlSetData(-1, "Dell GX280")
   GUICtrlSetData(-1, "Dell 530")
   GUICtrlSetData(-1, "Dell 620")
   GUICtrlSetData(-1, "Dell m70")
   GUICtrlSetData(-1, "Dell d600")
   $Label_select = GUICtrlCreateLabel("1. Select Model", 70, 90, 130, 20)
   $Button_next = GUICtrlCreateButton("Next", 100, 155, 100, 25)
   GUISetState()
   Call("onselectModel")
   
EndFunc  ;==>Start 

Func onselectModel()
   While 1
      $msg = GUIGetMsg()
      If $msg = $Button_next Then
         $selectmodell = GUICtrlRead($Combo)
         Select
            Case $selectmodell = ""
               MsgBox(64, "RIS - Driver Update Admin", "Please, make a selection" & @LF & "before you press Next")
            Case $selectmodell = "Dell GX280"
               GUIDelete($startgui)
               Call("onselectType")
               ExitLoop
            Case $selectmodell = "Dell 530"
               GUIDelete($startgui)
               Call("onselectType")
               ExitLoop
            Case $selectmodell = "Dell x200"
               GUIDelete($startgui)
               Call("onselectType")
               ExitLoop
         EndSelect
      EndIf
   WEnd
   
EndFunc  ;==>onselectModel 

Func onselectType()
  ;Select Driver Type
   $secondgui = GUICreate("RIS - Driver Update Admin", 310, 200, (@DesktopWidth - 400) / 2, (@DesktopHeight - 400) / 2)
   $Group_1 = GUICtrlCreateGroup("RIS - PC Driver Update Admin ", 30, 20, 250, 60)
   $Label_start = GUICtrlCreateLabel("This wizard will help you to update the RIS - Drvier Update utility ", 40, 40, 190, 30)
   $Label_select2 = GUICtrlCreateLabel("2. Select Driver Type for " & $selectmodell, 70, 90, 190, 20)
   $Button_next = GUICtrlCreateButton("Next", 165, 155, 75, 25)
   $Button_back = GUICtrlCreateButton("Back", 75, 155, 75, 25)
   $Combo2 = GUICtrlCreateCombo("", 70, 110, 170, 21, $CBS_DROPDOWNLIST)
   GUICtrlSetData(-1, "Audio Driver " & $selectmodell)
   GUICtrlSetData(-1, "Video Driver " & $selectmodell)
   GUICtrlSetData(-1, "Chipset Driver " & $selectmodell)
   GUICtrlSetData(-1, "Nic Driver " & $selectmodell)
   GUISetState()
   
   While 1
      $msg = GUIGetMsg()
      If $msg = $Button_next Then
         $selecttype = GUICtrlRead($Combo2)
         Select
            Case $selecttype = ""
               MsgBox(64, "RIS - Driver Update Admin", "Please, make a selection" & @LF & "before you press Next")
            Case $selecttype = "Audio Driver " & $selectmodell
               ExitLoop
            Case $selecttype = "Video Driver " & $selectmodell
               ExitLoop
         EndSelect
      Else
         If $msg = $Button_back Then
            GUIDelete($secondgui)
            Call("Start")
            ExitLoop
         EndIf
      EndIf
      
   WEnd
   
   $file = FileOpen("RIS Driver Update.au3", 0)
   
  ; Check if file opened for reading OK
   If $file = -1 Then
      MsgBox(0, "Error", "Unable to open file.")
      Exit
   EndIf
   
   $oldurl = ""
   $oldurltemp = ""
   $oldversion = ""
   $oldversiontemp = ""
   $nextline = ""
   $nextlinetemp = ""
   $olddriver = ""
   $olddrivertemp = ""
   
   $i = 1
   While 1
      $i = $i + 1
      $line = FileReadLine($file)
      If @error = -1 Then ExitLoop
      
      If $nextline = 3 Then
         $oldurltemp = StringTrimLeft($line, 20)
         $oldurl = StringTrimRight($oldurltemp, 1)
         MsgBox(0, "", $oldurl)
         GUIDelete($secondgui)
         FileClose($file)
         Call("NewDriverDetails")
         ExitLoop
      EndIf
      If $nextline = 2 Then
         $oldversiontemp = StringTrimLeft($line, 17)
         $oldversion = StringTrimRight($oldversiontemp, 1)
         MsgBox(0, "", $oldversion)
         $nextline = 3
      EndIf
      If $nextline = 1 Then
         $olddrivertemp = StringTrimLeft($line, 18)
         $olddriver = StringTrimRight($olddrivertemp, 1)
         MsgBox(0, "", $olddriver)
         $nextline = 2
      EndIf
      $result2 = StringInStr($line, ";" & $selecttype)
      If $result2 = 1 Then
         MsgBox(0, "", $i)
         $nextline = 1
      EndIf
   WEnd
EndFunc  ;==>onselectType 

Func NewDriverDetails()
   $thirdgui = GUICreate("RIS - Driver Update Admin", 310, 300, (@DesktopWidth - 400) / 2, (@DesktopHeight - 400) / 2)
   GUICtrlCreateGroup("RIS - PC Driver Update Admin ", 30, 20, 250, 60)
   GUICtrlCreateLabel("This wizard will help you to update the RIS - Drvier Update utility ", 40, 40, 190, 30)
   GUICtrlCreateLabel("Old " & $selecttype & ":", 35, 90, 390, 15)
   GUICtrlCreateLabel("File = " & $olddriver, 35, 105, 390, 15)
   GUICtrlCreateLabel("Ver = " & $oldversion, 35, 120, 390, 15)
   
   GUICtrlCreateLabel("New " & $selecttype & ":", 35, 140, 390, 15)
   GUICtrlCreateLabel("File = ", 35, 155, 390, 15)
   GUICtrlCreateLabel("Ver = ", 35, 170, 390, 15)
   GUISetState(@SW_SHOW)
   
   $ver = FileGetVersion($olddriver)
   If $ver = "0.0.0.0" Then
      MsgBox(64, "RIS - Driver Update Admin", "The old driver file is removed." & @LF & "Press Change new Driver File" & @LF & "to select driver file")
   ElseIf $ver <= $oldversion Then
      MsgBox(64, "RIS - Driver Update Admin", "The old driver file verion is unchanged or older." & @LF & "Press Change new Driver File to select driver file")
   Else
      GUICtrlCreateLabel("New " & $selecttype & ":", 35, 140, 390, 15)
      GUICtrlCreateLabel("File = " & $olddriver, 35, 155, 390, 15)
      GUICtrlCreateLabel("Ver = " & $ver, 35, 170, 390, 15)
   EndIf
   
   $Button_browse = GUICtrlCreateButton("Change new Driver File", 75, 200, 165, 25)
   $Button_back = GUICtrlCreateButton("Back", 75, 250, 75, 25)
   $Button_next = GUICtrlCreateButton("Next", 165, 250, 75, 25)
   $var2 = $olddriver
   $newfilever = $ver
   
   While 1
      $msg = GUIGetMsg()
      If $msg = $Button_browse Then
         $message = "Select new driver file"
         $var2 = FileOpenDialog($message, "C:\Windows\system32\drivers\", "All (*.*)")
         If @error Then
           ;MsgBox(4096,"","No File(s) chosen")
         Else
            $var2 = StringReplace($var2, "|", @CRLF)
            $newfilever = FileGetVersion($var2)
            GUICtrlCreateLabel("File = " & $var2, 35, 155, 390, 15)
            GUICtrlCreateLabel("Ver = " & $newfilever, 35, 170, 390, 15)
         EndIf
      Else
         If $msg = $Button_back Then
            GUIDelete($thirdgui)
            Call("onselectType")
            ExitLoop
         Else
            If $msg = $Button_next Then
               GUIDelete($thirdgui)
               Call("OnEnterUrl")
               ExitLoop
            EndIf
         EndIf
      EndIf
   WEnd
   
   
   While 1
      Sleep(1000)
   WEnd
   
EndFunc  ;==>NewDriverDetails 

Func OnEnterUrl()
   
   $fourthgui = GUICreate("RIS - Driver Update Admin", 310, 235, (@DesktopWidth - 400) / 2, (@DesktopHeight - 400) / 2)
   GUICtrlCreateGroup("RIS - PC Driver Update Admin ", 30, 20, 250, 60)
   GUICtrlCreateLabel("This wizard will help you to update the RIS - Drvier Update utility ", 40, 40, 190, 30)
   GUICtrlCreateLabel("Old url for " & $selecttype & " file:", 35, 90, 390, 15)
   GUICtrlCreateLabel("Url = " & $oldurl, 35, 105, 390, 15)
   
   GUICtrlCreateLabel("Enter new url for " & $selecttype & " file:", 35, 125, 390, 15)
   $newurltemp = GUICtrlCreateInput("", 35, 145, 250, 20)
   
   $Button_back = GUICtrlCreateButton("Back", 75, 185, 75, 25)
   $Button_next = GUICtrlCreateButton("Next", 165, 185, 75, 25)
   
   
   GUISetState(@SW_SHOW)
   
   While 1
      $msg = GUIGetMsg()
      If $msg = $Button_back Then
         GUIDelete($fourthgui)
         Call("NewDriverDetails")
         ExitLoop
      Else
         If $msg = $Button_next Then
            If GUICtrlRead($newurltemp) = "" Then
               MsgBox(64, "RIS - Driver Update Admin", "Please, enter a new url" & @LF & "before you press Next")
            Else
               $newurl = GUICtrlRead($newurltemp)
               GUIDelete($fourthgui)
               Call("OnEnterInfo")
               ExitLoop
            EndIf
         EndIf
      EndIf
   WEnd
   
   While 1
      Sleep(1000)
   WEnd
   
EndFunc  ;==>OnEnterUrl 

Func OnEnterInfo()
   
   $5gui = GUICreate("RIS - Driver Update Admin", 415, 310, (@DesktopWidth - 500) / 2, (@DesktopHeight - 400) / 2)
   GUICtrlCreateGroup("RIS - PC Driver Update Admin ", 30, 20, 250, 60)
   GUICtrlCreateLabel("This wizard will help you to update the RIS - Drvier Update utility ", 40, 40, 190, 30)
   
   GUICtrlCreateLabel("Enter new Download Info Message for " & $selecttype, 12, 100, 390, 15)
   $newinfotemp = GUICtrlCreateInput("", 10, 120, 396, 112, BitOR($ES_WANTRETURN, $ES_MULTILINE))
   
   $Button_back = GUICtrlCreateButton("Back", 115, 260, 75, 25)
   $Button_next = GUICtrlCreateButton("Next", 205, 260, 75, 25)
   
   
   GUISetState(@SW_SHOW)
   
   While 1
      $msg = GUIGetMsg()
      If $msg = $Button_back Then
         GUIDelete($5gui)
         Call("OnEnterUrl")
         ExitLoop
      Else
         If $msg = $Button_next Then
            If GUICtrlRead($newinfotemp) = "" Then
               MsgBox(64, "RIS - Driver Update Admin", "Please, enter a new Driver Info" & @LF & "before you press Next")
            Else
               $newinfo = GUICtrlRead($newinfotemp)
               GUIDelete($5gui)
               Call("OnCompile")
               ExitLoop
            EndIf
         EndIf
      EndIf
   WEnd
   
   While 1
      Sleep(1000)
   WEnd
   
EndFunc  ;==>OnEnterInfo 

Func OnCompile()
   
   $6gui = GUICreate("RIS - Driver Update Admin", 415, 400, (@DesktopWidth - 500) / 2, (@DesktopHeight - 400) / 2)
   GUICtrlCreateGroup("RIS - PC Driver Update Admin ", 30, 20, 250, 60)
   GUICtrlCreateLabel("This wizard will help you to update the RIS - Drvier Update utility ", 40, 40, 190, 30)
   GUICtrlCreateLabel("Save Changes for " & $selecttype, 12, 90, 390, 15)
   
  ;GuiCtrlCreateLabel("File = " & $var2, 12, 105, 390, 15)
  ;GuiCtrlCreateLabel("Ver = " & $newfilever, 12, 120, 390, 15)
   GUICtrlCreateLabel("Url = " & $newurl, 12, 135, 390, 30)
   GUICtrlCreateLabel("Driver Info:", 12, 165, 390, 15)
   GUICtrlCreateInput($newinfo, 10, 182, 396, 112, BitOR($ES_READONLY, $ES_MULTILINE))
   
   _FileCreate("temp.pak")
   $temppak = FileOpen("temp.pak", 1)
   If $temppak = -1 Then
      MsgBox(0, "Error", "Unable to open file.")
      Exit
   EndIf
   FileWrite($temppak, $newinfo)
   FileClose($temppak)
   
   $l = 0
   $temppak = FileOpen("temp.pak", 0)
   While 1
      $l = $l + 1
      $line = FileReadLine($temppak)
      If @error = -1 Then ExitLoop
      If $l = 1 Then
         $line1 = $line
         MsgBox(0, "Line read:", $line1)
      ElseIf $l = 2 Then
         $line2 = $line
         MsgBox(0, "Line read:", $line2)
      ElseIf $l = 3 Then
         $line3 = $line
         MsgBox(0, "Line read:", $line3)
      ElseIf $l = 4 Then
         $line4 = $line
         MsgBox(0, "Line read:", $line4)
      ElseIf $l = 5 Then
         $line5 = $line
         MsgBox(0, "Line read:", $line5)
      ElseIf $l = 6 Then
         $line6 = $line
         MsgBox(0, "Line read:", $line6)
      ElseIf $l = 7 Then
         $line7 = $line
         MsgBox(0, "Line read:", $line7)
      ElseIf $l = 8 Then
         $line8 = $line
         MsgBox(0, "Line read:", $line8)
      EndIf
   WEnd
   FileClose($temppak)
   
   $Button_create = GUICtrlCreateButton("Compile EXE", 115, 320, 165, 25)
   $Button_back = GUICtrlCreateButton("Back", 115, 355, 75, 25)
   $Button_cancel = GUICtrlCreateButton("Cancel", 205, 355, 75, 25)
   
   
   GUISetState(@SW_SHOW)
   
   While 1
      $msg = GUIGetMsg()
      If $msg = $Button_back Then
         GUIDelete($6gui)
         Call("OnEnterInfo")
         ExitLoop
      Else
         If $msg = $Button_create Then
            GUIDelete($6gui)
            Call("OnCompileFile")
            ExitLoop
         Else
            If $msg = $Button_cancel Then
               Exit
            EndIf
         EndIf
      EndIf
   WEnd
   
   While 1
      Sleep(1000)
   WEnd
   
EndFunc  ;==>OnCompile 

Func OnCompileFile()
   
  ;$au3file = "Copy of RIS Driver Update.au3"
   $au3file = "admin1.au3"
   $au3filenew = "tempau3.au3"
   
  ; read in the file
   $list1 = FileRead($au3file, FileGetSize($au3file))
  ;If @error = 1 Then
  ;MsgBox (0, "", "Error reading from " & $au3file)
  ;Exit 1
  ;EndIf
  ; split into lines
   $list = StringSplit($list1, @CRLF, 1)
  ; replace specific line
   $linenum = 5
   $list[$linenum] = "This is the text on the replaced line."
  ; overwrite the file
   $handle = FileOpen($au3filenew, 1)
   If $handle = -1 Then
      MsgBox(0, "Error", "Unable to open file.")
      Exit 1
   EndIf
   
   For $i = 1 To $list[0]
      FileWriteLine($handle, $list[$i])
   Next
   MsgBox(0, "", "har skrivit till filen")
   FileClose($handle)
EndFunc  ;==>OnCompileFile

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...