problema con este c贸digo
Tengo este c贸digo en una accion de un bot贸n..
Y mi intenci贸n es utilizar los valores True y False,
Dim i As Integer
Dim u As String
u = ".0"
Set fs = CreateObject("Scripting.FileSystemObject")
For i = 1 To 10
If fs.folderexists("C:temp " & i & u) Then
Shell "EXPLORER ..MANUALMANUAL.PDF", vbNormalFocus
else
Shell "..softwaresetup.exe",vbNormalFocus
End If
Next i
End Sub
Me funciona correctamente, pero el problema est谩 cuando introduzco la opci贸n else en el if, porque me realiza la operaci贸n 9 veces (valor False) y 1 vez (valor True) y solamente quiero que me haga 1 vez (valor False) y se salga del bucle For Next...
驴C贸mo puedo hacerlo?
Y mi intenci贸n es utilizar los valores True y False,
Dim i As Integer
Dim u As String
u = ".0"
Set fs = CreateObject("Scripting.FileSystemObject")
For i = 1 To 10
If fs.folderexists("C:temp " & i & u) Then
Shell "EXPLORER ..MANUALMANUAL.PDF", vbNormalFocus
else
Shell "..softwaresetup.exe",vbNormalFocus
End If
Next i
End Sub
Me funciona correctamente, pero el problema est谩 cuando introduzco la opci贸n else en el if, porque me realiza la operaci贸n 9 veces (valor False) y 1 vez (valor True) y solamente quiero que me haga 1 vez (valor False) y se salga del bucle For Next...
驴C贸mo puedo hacerlo?
No estoy seguro de haber entendido la pregunta del todo, ya que tengo 2 dudas de como quieres hacerlo. Te propongo dos soluciones, elige la que te parezca m谩s adecuada.
Si cuando es false se sale del for y no lo ejecuta m谩s (por tanto, si no has ejecutado el true ya no se ejecutar谩, pues ha salido del for) usa la instrucci贸n Exit for
ser铆a algo as铆
*****************************
For i = 1 to 10
if fs.folderexists("C:temp" & i & u) then
shell "Explorer ..manualmanual.pdf", vbnormalfocus
else
shell "..softwaresetup.exe", vbnormalfocus
exit for
end if
next i
SiguientePaso:
*****************************
Aqu铆 la etiqueta SiguientePaso no hace nada, pero al ejecutar el Exit For saldr铆as del for y, por tanto, estar铆as en siguientepaso (es para dar a entender que al hacer el exit for finalizas el bucle)
Si lo que te interesa es que se ejecute una vez el shell cuando sea false pero que no salga del bucle, tendr铆as que usar una variable (un boolean, por ejemplo) que te haga saber si ya has ejecutado el false o no
Por ejemplo
******************
Dim i As Integer
Dim u As String
Dim blnSetup as boolean
blnSetup = false
u = ".0"
Set fs = CreateObject("Scripting.FileSystemObject")
For i = 1 To 10
If fs.folderexists("C:temp " & i & u) Then
Shell "EXPLORER ..MANUALMANUAL.PDF", vbNormalFocus
else
if blnSetup = false then ' a煤n no se ha ejecutado el shell de setup
Shell "..softwaresetup.exe",vbNormalFocus
blnSetup = true ' as铆 nos aseguramos que no se vuelva a ejecutar
end if
End If
Next i
End Sub
Si cuando es false se sale del for y no lo ejecuta m谩s (por tanto, si no has ejecutado el true ya no se ejecutar谩, pues ha salido del for) usa la instrucci贸n Exit for
ser铆a algo as铆
*****************************
For i = 1 to 10
if fs.folderexists("C:temp" & i & u) then
shell "Explorer ..manualmanual.pdf", vbnormalfocus
else
shell "..softwaresetup.exe", vbnormalfocus
exit for
end if
next i
SiguientePaso:
*****************************
Aqu铆 la etiqueta SiguientePaso no hace nada, pero al ejecutar el Exit For saldr铆as del for y, por tanto, estar铆as en siguientepaso (es para dar a entender que al hacer el exit for finalizas el bucle)
Si lo que te interesa es que se ejecute una vez el shell cuando sea false pero que no salga del bucle, tendr铆as que usar una variable (un boolean, por ejemplo) que te haga saber si ya has ejecutado el false o no
Por ejemplo
******************
Dim i As Integer
Dim u As String
Dim blnSetup as boolean
blnSetup = false
u = ".0"
Set fs = CreateObject("Scripting.FileSystemObject")
For i = 1 To 10
If fs.folderexists("C:temp " & i & u) Then
Shell "EXPLORER ..MANUALMANUAL.PDF", vbNormalFocus
else
if blnSetup = false then ' a煤n no se ha ejecutado el shell de setup
Shell "..softwaresetup.exe",vbNormalFocus
blnSetup = true ' as铆 nos aseguramos que no se vuelva a ejecutar
end if
End If
Next i
End Sub
Lo que quiero hacer es que me detecte si existe una carpeta c:temp *.0 y si existe que me explorer el fichero manual.pdf, si no existe que me aparezca el mensaje "no existe. 驴Desea instalar el software para poder ver el fichero?". El problema que yo tengo es que al meter un bucle For Next, se me ejecuta una de las opciones 9 veces. Yo quiero que si es True realice una acci贸n y si es False realice otra acci贸n.
