Jump to content

UBound Loops


Recommended Posts

Hello,

I'm trying to write the following variables to 3 separate text files. I got the first one down but not sure how to make it loop again for the next 2 files.;):):idiot:

Global $var[9][1]
$var[0][0] = "Arizona-Phoenix"
$var[1][0] = "Arizona-Scottsdale"
$var[2][0] = "Arizona-Tempe"
$var[3][0] = "California-San-Francisco"
$var[4][0] = "California-Los-Angeles"
$var[5][0] = "California-Sacramento"
$var[6][0] = "California-San-Diego"
$var[7][0] = "Colorado-Denver"
$var[8][0] = "Colorado-Fort-Collins"

$Dissect = StringSplit($var [0][0], '-', 1)
Local $First_State = $Dissect[1]
$State = $First_State
msgbox(0,"First State",$First_State)
 
 If $State = $First_State Then
  If FileExists("Cities in " & $State & ".txt") Then FileDelete("Cities in " & $State & ".txt")
  $Open_Text = FileOpen("Cities in " & $State & ".txt", 1)
  FileWrite($Open_Text, "Cities I've visited in " & $State & @CRLF)
  
  For $i = 0 To UBound($var) -1
   $Dissect = StringSplit($var [$i][0], '-', 1)
   If $State = $Dissect[1] Then FileWrite($Open_Text, $var [$i][0] & @CRLF)
   msgbox(0,"Current State",$State)

  Next
   FileWrite($Open_Text, "(These trips were all part of the ASCC Youth Foundation)" & @CRLF)
   FileClose($Open_Text) 
 EndIf


 ;If $State <> $First_State Then $State = $First_State
Link to comment
Share on other sites

I'm trying to write the following variables to 3 separate text files. I got the first one down but not sure how to make it loop again for the next 2 files

Yes, Never got past the first state.

Try:

#include <Array.au3>

Global $var[9][1]
$var[0][0] = "Arizona-Phoenix"
$var[1][0] = "Arizona-Scottsdale"
$var[2][0] = "Arizona-Tempe"
$var[3][0] = "California-San-Francisco"
$var[4][0] = "California-Los-Angeles"
$var[5][0] = "California-Sacramento"
$var[6][0] = "California-San-Diego"
$var[7][0] = "Colorado-Denver"
$var[8][0] = "Colorado-Fort-Collins"
Global $State[UBound($var)]
$1 = -1


Do
    $1 += 1
    $Dissect = StringSplit($var[$1][0], '-', 1)
    Local $First_State = $Dissect[1]
    $State[$1] = $First_State
    Until $1 = UBound($var) - 1
$states = _ArrayUnique($State)

_ArrayDisplay($states);Got rid of duplicates

For $1 = 1 To $states[0]

    If FileExists("Cities in " & $states[$1] & ".txt") Then FileDelete("Cities in " & $states[$1] & ".txt")
    $Open_Text = FileOpen("Cities in " & $states[$1] & ".txt", 1)
    If $Open_Text = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf


    FileWrite($Open_Text, "Cities I've visited in " & $states[$1] & @CRLF)

    For $i = 0 To UBound($var) - 1
        $Dissect = StringSplit($var[$i][0], '-', 1)
        If $states[$1] = $Dissect[1] Then FileWrite($Open_Text, $var[$i][0] & @CRLF)
        MsgBox(0, "Current State", $states[$1])

    Next
    FileWrite($Open_Text, "(These trips were all part of the ASCC Youth Foundation)" & @CRLF)
    FileClose($Open_Text)


Next
;If $State <> $First_State Then $State = $First_State
Edited by JoHanatCent
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...