Question on Loops!!

620
6
Jump to solution
05-17-2013 06:57 AM
MichelleCouden1
Occasional Contributor III
I created a program in ArcO that has a dialog box that users answer questions in to get an mxd to draw. I missed a step in the program. I have it written where if they choose Annual stations it will draw an mxd from the current year folder. I forgot to program in differeent years. For Example: If they choose Annual and 2010 then it needs to draw the mxd from the 2010 folder. I'm not to sure how to fix my loop. Should it be:

If cboStations.Text = "Annual" then
If cboYear.Text = "2010" Then
Select Case cboDistrict.Text
Case "Abilene"
  pApp.OpenDocument ("K: .........

Code is below:
Private Sub cmdMap_Click()           Dim UserValue As String     Dim Value As String     Dim Year As String     Dim pDoc As IDocument     Dim pApp As IApplication               Set pDoc = New MxDocument     Set pApp = pDoc.Parent          If cboStations.Text = "Annual" Then                            Select Case cboDistrict.Text         Case "Abilene"             pApp.OpenDocument ("K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\District_Maps\2012\Abilene\Abilene_Base_Map.mxd")         Case "Amarillo"             pApp.OpenDocument ("K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\District_Maps\2012\Amarillo\Amarillo_Base_Map.mxd")         Case "Atlanta"
0 Kudos
1 Solution

Accepted Solutions
MichelleCouden1
Occasional Contributor III
Figured it Out!! Yes, that is how you do the loop with Slect Case to get different years to draw up.

View solution in original post

0 Kudos
6 Replies
MichelleCouden1
Occasional Contributor III
Figured it Out!! Yes, that is how you do the loop with Slect Case to get different years to draw up.
0 Kudos
KenBuja
MVP Esteemed Contributor
You shouldn't need an extra loop for this. Is the code structured such that if they don't select a year, it will default to the current year? You could do something like this

Private Sub cmdMap_Click()

    
    Dim UserValue As String
    Dim Value As String
    Dim Year As String
    Dim pDoc As IDocument
    Dim pApp As IApplication
    
    
    Set pDoc = New MxDocument
    Set pApp = pDoc.Parent
    
    If cboYear.Text = "" then
        Year = Year(Date)
    Else
        Year = cboYear.Text
    End If

    If cboStations.Text = "Annual" Then
                      
    Select Case cboDistrict.Text
        Case "Abilene"
            pApp.OpenDocument ("K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\District_Maps\" & Year & "\Abilene\Abilene_Base_Map.mxd")
        Case "Amarillo"
            pApp.OpenDocument ("K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\District_Maps\" & Year & "\Amarillo\Amarillo_Base_Map.mxd")
        Case "Atlanta"



Depending on how your districts are set up, you could also get rid of the Select Case section and use something like this

If cboStations.Text = "Annual" Then
     pApp.OpenDocument ("K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\District_Maps\" & Year & "\" & cboDistrict.Text & "\" & cboDistrict.Text & "_Base_Map.mxd")
0 Kudos
LeoDonahue
Occasional Contributor III
If/Then and Switch statements aren't really loops because they don't repeat.  Yes, sure, a switch statement can have multiple execution paths, but the switch statement doesn't repeat itself like for and while loops can.

Where is the loop portion of the code you need help with?

It looks like you have three combo boxes?  Station, Year and District and the user can choose any combination of those values and you want them to open the correct mxd based on those three combinations?

Station = Annual
Year = 2010 (or whatever)
District = Ablene


If it were me, I would make those options part of the directory structure in which you store your mxds, which it looks like you are already, except for the Stations part.   I can't tell for sure.

You could restructure your directory and rename the "District_Maps" folder as the Station Name?  Maybe?

Then you could just issue one statement based on what was selected in the combo boxes and concatenate your OpenDocument string parameter.


pApp.OpenDocument ("K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\stations_variable\year_variable\district_variable\district_variable + "_Base_Map.mxd")
0 Kudos
LeoDonahue
Occasional Contributor III
ken, you beat me to it.  should I be concerned that we think alike? Do you have access to my computer? Are you watching me?  lol...  no really, are you?
0 Kudos
KenBuja
MVP Esteemed Contributor
ken, you beat me to it.  should I be concerned that we think alike? Do you have access to my computer? Are you watching me?  lol...  no really, are you?


What was that about great minds?
0 Kudos
LeoDonahue
Occasional Contributor III
What?  you have access to my mind?  That's it, I'm breaking out the tin foil hat.
0 Kudos