Jump to content

StringSplit hits a CR or LF


cw3
 Share

Recommended Posts

SB.au3 (26) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

I get the above error on an String split when there is a LF / CR character incountered in the String. The split stops at that point.

I have tried using the StringsplitCR with no success

Here is my script.

#include <file.au3>

Dim $aRecords

Dim $Location

Dim $Status_Text

Dim $Longitude

Dim $Long_Deg_Min

Dim $Latitude

Dim $Long_Deg_Min

Dim $Result

Dim $Array[7]

Dim $Address[3]

Dim $x

If Not _FileReadToArray("TX_SB.csv",$aRecords) Then

MsgBox(4096,"Error", " Error reading file to Array - error:" & @error)

Exit

EndIf

FileOpen("SBTX.pos",2)

For $x = 1 to $aRecords[0]

$Array = StringSplit($aRecords[$x],",")

$Address = StringSplit($aRecords[$x],'"')

$Longitude = Number($Array[1])

$Latitude = Number($Array[2])

$Longitude = Abs($Array[1])

$Long_Deg_Min = Round((Int($Longitude)&INT(($Longitude-Int($Longitude))*60*1000)/1000),2)

$Lat_Deg_Min = Round((Int($Latitude)&INT(($Latitude-Int($Latitude))*60*1000)/1000),2)

$Location = $Array[3] & "!" & $Lat_Deg_Min & "N/"& $Long_Deg_Min & 'W"'

$Status_Text = $Array[3] & ">" & $Address[2]

FileWriteLine("SBTX.pos",$Location & @CRLF)

FileWriteLine("SBTX.pos",$Status_Text & @CRLF)

Next

FileClose("SBTX.pos")

Here is a line (1 record) from the data file I am processing.

98.98155783,31.72842802,"300 W. Commerce

Brownwood, Texas 76801

325-641-0431"

When viewed in excel the above is all on a single line with a block character showing where the CRLF is.

Any suggestions? I really don't want to edit each line in the file, there are a bunch.

I would like to figure out how to get each record on a single line or figure a way to work around the CRLF block.

Thanks

Link to comment
Share on other sites

  • Moderators

If you use StringReplace($string, @CRLF, Chr(1)) at the beginning (before any stringsplit() and the reverse at the end (before you FileWrite), does that help?

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

Hi,

this way you 'll see your problem:

#include <file.au3>
#include <array.au3>

Dim $aRecords
Dim $Location
Dim $Status_Text
Dim $Longitude
Dim $Long_Deg_Min
Dim $Latitude
Dim $Long_Deg_Min
Dim $Result
Dim $Array[7]
Dim $Address[3]
Dim $x
If Not _FileReadToArray("ForumTests\SBtx.csv", $aRecords) Then
    MsgBox(4096, "Error", " Error reading file to Array - error:" & @error)
    Exit
EndIf

For $x = 1 To $aRecords[0]-1
    $Array = StringSplit($aRecords[$x], ",")
    $Address = StringSplit($aRecords[$x], '"')
    _ArrayDisplay($Array,"")
    _ArrayDisplay($Address,"")
    $Longitude = Number($Array[1])
    $Latitude = Number($Array[2])
    $Longitude = Abs($Array[1])
    $Long_Deg_Min = Round((Int($Longitude) & Int(($Longitude - Int($Longitude)) * 60 * 1000) / 1000), 2)
    $Lat_Deg_Min = Round((Int($Latitude) & Int(($Latitude - Int($Latitude)) * 60 * 1000) / 1000), 2)
    
    $Location = $Array[3] & "!" & $Lat_Deg_Min & "N/" & $Long_Deg_Min & 'W"'
    $Status_Text = $Array[3] & ">" & $Address[2]
    FileWriteLine("SBTX.pos", $Location & @CRLF)
    FileWriteLine("SBTX.pos", $Status_Text & @CRLF)
Next

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

Ahh, so you want to view it in excell? Then try StringReplace($string, @CRLF, ',') or whatever delimeter you are using to view in excel.

Also, there is no StringSplitCR() function, and please use AutoIt tags when posting code, I didn't read your example because everything runs together.

before code>><<After code

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