Jump to content

Cannot split variables


Recommended Posts

Hello,

my Autoit file works when I open the file with F5 in the SciTE Script Editor. But when I open the file with two left clicks, StringSplit cannot execute and gives the file in a message window: "Variable used without being declared." back when i use a variable,
which was previously split with StringSplit.

 

Link to comment
Share on other sites

  • Moderators

XGamerGuide,

Welcome to the AutoIt forums.

The problem is obviously in line #347...

.

.

Seriously, how can we help if you do not post the code you are using - see here how to do it. And from where do you get the value you are attempting to split?

M23

Edited by Melba23
Added welcome

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

somehow the text is not formatted correctly.
II'll try it this way:

ConsoleWrite(">Starte" & @CRLF)
FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @CRLF & @CRLF & @CRLF & @CRLF & @CRLF & @CRLF & @CRLF & @CRLF & @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & ">Starte" & @CRLF)

;variablen
ConsoleWrite(">Lade Variablen" & @CRLF)
$itime = 0
MsgBox(0, "", $itime)
$bsprint = False
ConsoleWrite(">Reading Code" & @CRLF)
$vdatei = FileRead(FileRead("script"))
$vstring = StringSplit($vdatei, @CRLF)
$vline = StringSplit($vstring[1], ";")
$vFone = $vline[1]
$vFtwo = $vline[2]
$vagain = $vline[3]
$vinstantStart = $vline[4]
$vone = StringSplit($vFone, "=")
$vtwo = StringSplit($vFtwo, "=")
$va = StringSplit($vagain, "=")
$viS = StringSplit($vinstantStart, "=")
$ilange = $vstring[0] + 1
$ilange = $ilange / 2
$ihelp = 2
$izahler = 3
$bcmd = False

If $viS[2] = "true" Then
    ConsoleWrite("Instant Start ist an" & @CRLF)
    FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "Instant Start ist an" & @CRLF)
    $bon = True
Else
    ConsoleWrite("Instant Start ist aus" & @CRLF)
    FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "Instant Start ist aus" & @CRLF)
    $bon = False
EndIf

;Funktionen
ConsoleWrite(">Lade Funktionen" & @CRLF)
FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & ">Lade Funktionen" & @CRLF)
Func switchThis()
    If $bon = False Then
        ConsoleWrite("+++ Bot aktiv +++" & @CRLF)
        FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "+++ Bot aktiv +++" & @CRLF)
        $bon = True
    Else
        ConsoleWrite("+++ Bot inaktiv +++" & @CRLF)
        FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "+++ Bot inaktiv +++" & @CRLF)
        $bon = False
    EndIf
EndFunc   ;==>switchThis

Func esc()
    ConsoleWrite("+++ Beende [GEPLANT]: Mit Hotkey beendet +++" & @CRLF)
    FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "+++ Beende [GEPLANT]: Mit Hotkey beendet +++" & @CRLF)
    Exit 0
EndFunc   ;==>esc

Func E()
    If $bon = True Then
        ConsoleWrite("-Sende E. Zeit: " & $itime & @CRLF)
        FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "-Sende E. Zeit: " & $itime & @CRLF)
        Send("{E down}")
        Sleep($itime)
        Send("{E up}")
    EndIf
EndFunc   ;==>E

Func W()
    If $bon = True Then
        ConsoleWrite("-Sende W. Zeit: " & $itime & @CRLF)
        FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "-Sende W. Zeit: " & $itime & @CRLF)
        Send("{W down}")
        Sleep($itime)
        Send("{W up}")
    EndIf
EndFunc   ;==>W

Func A()
    If $bon = True Then
        ConsoleWrite("-Sende A. Zeit: " & $itime & @CRLF)
        FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "-Sende A. Zeit: " & $itime & @CRLF)
        Send("{A down}")
        Sleep($itime)
        Send("{A up}")
    EndIf
EndFunc   ;==>A

Func S()
    If $bon = True Then
        ConsoleWrite("-Sende S. Zeit: " & $itime & @CRLF)
        FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "-Sende S. Zeit: " & $itime & @CRLF)
        Send("{S down}")
        Sleep($itime)
        Send("{S up}")
    EndIf
EndFunc   ;==>S

Func D()
    If $bon = True Then
        ConsoleWrite("-Sende D. Zeit: " & $itime & @CRLF)
        FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "-Sende D. Zeit: " & $itime & @CRLF)
        Send("{D down}")
        Sleep($itime)
        Send("{D up}")
    EndIf
EndFunc   ;==>D

Func sprintOn()
    ConsoleWrite("-Sprinte" & @CRLF)
    FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "-Sprinte" & @CRLF)
    $bsprint = True
    Send("{LSHIFT down}")
EndFunc   ;==>sprintOn

Func sprintOff()
    ConsoleWrite("-Hoere auf zu sprinten" & @CRLF)
    FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "-Hoere auf zu sprinten" & @CRLF)
    $bsprint = False
    Send("{LSHIFT up}")
EndFunc   ;==>sprintOff

;Hotkeys
If $vone[2] = "true" Then
    ConsoleWrite("Hotkey F1 gesetzt" & @CRLF)
    FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "Hotkey F1 gesetzt" & @CRLF)
    HotKeySet("{F1}", "switchThis")
EndIf

If $vtwo[2] = "true" Then
    ConsoleWrite("Hotkey F2 gesetzt" & @CRLF)
    FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "Hotkey F2 gesetzt" & @CRLF)
    HotKeySet("{F2}", "esc")
EndIf

;Programm
ConsoleWrite(">Starte Programm" & @CRLF)
FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & ">Starte Programm" & @CRLF)
While True
    If $bon = True Then
        While $ilange >= $ihelp
            $vline = $vstring[$izahler]
            If $bon = True Then
                $bcmd = True
                ConsoleWrite("Verarbeite Zeile " & $ihelp & "" & @CRLF)
                FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "Verarbeite Zeile " & $ihelp & @CRLF)
                If $vline = "" Then
                    ConsoleWrite("Zeile lehr: Ignoriert" & @CRLF)
                    FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "Zeile lehr: Ignoriert" & @CRLF)
                    $bcmd = False
                EndIf
                $vline = $vline & "**************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************"
                $vline = StringSplit($vline, "")
                If $vline[1] = "/" Then
                    ConsoleWrite("Zeile beginnt mit einem /: Ignoriert" & @CRLF)
                    FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "Zeile beginnt mit einem /: Ignoriert" & @CRLF)
                    $bcmd = False
                EndIf
                   #cs If $bcmd = true and $vline[2] = "s" Then
                      ConsoleWrite("lol" & @CRLF)
                      ConsoleWrite("-Sprinte" & @CRLF)
                      $bsprint = true
                      ;Send("{LSHIFT down}")
                   EndIf
                #ce If $bcmd = true and $vline[2] = "s" Then
                If $bcmd = True And $vline[1] = "e" And $vline[2] = "x" And $vline[3] = "i" And $vline[4] = "t" Then
                    ConsoleWrite("+++ Beende [GEPLANT]: Das Programm wurde mit einer exit Anweisung beendet +++" & @CRLF)
                    FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "+++ Beende [GEPLANT]: Das Programm wurde mit einer exit Anweisung beendet +++" & @CRLF)
                    Exit 0
                EndIf
                If $bcmd = True And $vline[1] = "d" And $vline[2] = "i" And $vline[3] = "s" And $vline[4] = "a" And $vline[5] = "b" And $vline[6] = "l" And $vline[7] = "e" Then
                    ConsoleWrite("+++ Bot inaktiv (disable) +++" & @CRLF)
                    FileWrite(@LocalAppDataDir & "/AutoRun" & "\log.txt", @YEAR & "/" & @MON & "/" & @MDAY & @HOUR & "/" & @MIN & "/" & @SEC & "/" & @MSEC & ":" & "+++ Bot inaktiv (disable) +++" & @CRLF)
                    $bon = False
                EndIf
                $izahler = $izahler + 2
                $ihelp = $ihelp + 1
            EndIf
        WEnd
    EndIf
WEnd

MsgBox(0, "Error", "Beende [ERROR]: Code durchgelaufen (Escape from While)")
ConsoleWrite("Beende [ERROR]: Code durchgelaufen (Escape from While)" & @CRLF)
Exit 1

 

Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

XGamerGuide,

At a guess, you are running into problems with this line:

$vstring = StringSplit($vdatei, @CRLF)

As you have not set the $STR_ENTIRESPLIT flag, the function will split on both @CR and @LF - so you are probably not getting the array you think you are. Try using _ArrayDisplay to check what you do get and see if that is the case. Or post a copy of the file so we can test for ourselves.

M23

P.S. Have you read the Forum rules? If not, please do so before posting again.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...