Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.lang.visual-basic > #18943 > unrolled thread

aiuto su codice vbs

Started byTommy <barta@quipo.it>
First post2016-12-29 15:20 +0100
Last post2017-01-02 21:30 +0100
Articles 4 — 2 participants

Back to article view | Back to it.comp.lang.visual-basic


Contents

  aiuto su codice vbs Tommy <barta@quipo.it> - 2016-12-29 15:20 +0100
    Re: aiuto su codice vbs Luca D <antaniserse@yahoo.it> - 2016-12-29 16:28 -0800
    Re: aiuto su codice vbs Luca D <antaniserse@yahoo.it> - 2016-12-29 16:30 -0800
      Re: aiuto su codice vbs Tommy <barta@quipo.it> - 2017-01-02 21:30 +0100

#18943 — aiuto su codice vbs

FromTommy <barta@quipo.it>
Date2016-12-29 15:20 +0100
Subjectaiuto su codice vbs
Message-ID<o43643$ha1$1@gioia.aioe.org>
ciao, una cosa da vero principiante...

ho il sequente pezzo di codice:


		if Fso.FolderExists ("D:\000") then
                 FSO.CopyFolder "D:\000", CopiaCDsuHD
		end if

		if Fso.FolderExists ("D:\CDSURF") then
		FSO.CopyFolder "D:\CDSURF", CopiaCDsuHD
		end if

                 if Fso.FolderExists ("D:\DATA") then
		FSO.CopyFolder "D:\DATA", CopiaCDsuHD
		end if

		if Fso.FolderExists ("D:\DICOM") then
		FSO.CopyFolder "D:\DICOM", CopiaCDsuHD
		end if

		if Fso.FolderExists ("D:\FILESET") then
		FSO.CopyFolder "D:\FILESET", CopiaCDsuHD
		end if

		if Fso.FolderExists ("D:\IMAGES") then
		FSO.CopyFolder "D:\IMAGES", CopiaCDsuHD
		end if

		if Fso.FolderExists ("D:\studies") then
		FSO.CopyFolder "D:\studies", CopiaCDsuHD
		end if

		if Fso.FolderExists ("D:\_STUDIES") then
		FSO.CopyFolder "D:\_STUDIES", CopiaCDsuHD
		end if

		if Fso.FolderExists ("D:\study000") then
		FSO.CopyFolder "D:\study000", CopiaCDsuHD
		end if

per ognuna delle condizioni, qualora venga trovata una delle 9 cartelle 
elencate (es. "D:\DICOM" o "D:\IMAGES" ecc. ecc.)
tale cartella viene copiata su hard disk tramite il comando CopiaCDsuHD

è possibile riscrivere il codice in modo più "sintetico" ovvero anzichè 
ripetere 9 blocchi di codice quasi uguali, averne uno solo che dice che 
qualora una qualunque di quelle 9 cartelle sia presente su CD va 
ricopiata su HD?

ho provato con
if Fso.FolderExists ("D:\IMAGES") or ("D:\DICOM") or ecc. ecc.

ma non funzionava

grazie Tommy

[toc] | [next] | [standalone]


#18944

FromLuca D <antaniserse@yahoo.it>
Date2016-12-29 16:28 -0800
Message-ID<9c017934-a1a0-41dc-9839-e5c4e213d0e3@googlegroups.com>
In reply to#18943
On Thursday, December 29, 2016 at 3:20:53 PM UTC+1, Tommy wrote:
[CUT]
> è possibile riscrivere il codice in modo più "sintetico" ovvero anzichè 
> ripetere 9 blocchi di codice quasi uguali, averne uno solo che dice che 
> qualora una qualunque di quelle 9 cartelle sia presente su CD va 
> ricopiata su HD?
> 
> ho provato con
> if Fso.FolderExists ("D:\IMAGES") or ("D:\DICOM") or ecc. ecc.
> 
> ma non funzionava

Un semplice OR dovrebbe funzionare, ma devi ripetere l'istruzione completa ("Fso.FolderExists(xxx) or Fso.FolderExists(yyy) or ...."

In ogni caso, puoi renderla più compatta facendo una piccola funzione e un ciclo, ad esempio con:

dim fso, folders, i

Set fso = CreateObject("Scripting.FileSystemObject")
folders = Array("D:\000","D:\CDSURF","D:\DATA","D:\DICOM","D:\IMAGES","D:\studies","D:\_STUDIES","D:\study000")

for i = 0 to UBound(folders)
    If CheckFolder(folders(i)) Then CopiaCDsuHD
next

Function CheckFolder(path)
    CheckFolder = fso.FolderExists(path)
End Function

[toc] | [prev] | [next] | [standalone]


#18945

FromLuca D <antaniserse@yahoo.it>
Date2016-12-29 16:30 -0800
Message-ID<716db4a2-0873-4adc-ab54-a2172aee8f1c@googlegroups.com>
In reply to#18943
On Thursday, December 29, 2016 at 3:20:53 PM UTC+1, Tommy wrote:
[CUT]
> è possibile riscrivere il codice in modo più "sintetico" ovvero anzichè 
> ripetere 9 blocchi di codice quasi uguali, averne uno solo che dice che 
> qualora una qualunque di quelle 9 cartelle sia presente su CD va 
> ricopiata su HD?
> 
> ho provato con
> if Fso.FolderExists ("D:\IMAGES") or ("D:\DICOM") or ecc. ecc.
> 
> ma non funzionava


Un semplice OR dovrebbe funzionare, ma devi ripetere l'istruzione completa ("Fso.FolderExists(xxx) or Fso.FolderExists(yyy) or ...."

In ogni caso, puoi renderla più compatta con un ciclo, ad esempio con:

dim fso, folders, i

Set fso = CreateObject("Scripting.FileSystemObject")
folders = Array("D:\000","D:\CDSURF","D:\DATA","D:\DICOM","D:\IMAGES","D:\studies","D:\_STUDIES","D:\study000")

for i = 0 to UBound(folders)
    If fso.FolderExists(folders(i)) Then CopiaCDsuHD
next

[toc] | [prev] | [next] | [standalone]


#18946

FromTommy <barta@quipo.it>
Date2017-01-02 21:30 +0100
Message-ID<o4ed94$1a3j$1@gioia.aioe.org>
In reply to#18945
Luca D wrote:
> On Thursday, December 29, 2016 at 3:20:53 PM UTC+1, Tommy wrote:
> [CUT]
>> è possibile riscrivere il codice in modo più "sintetico" ovvero anzichè
>> ripetere 9 blocchi di codice quasi uguali, averne uno solo che dice che
>> qualora una qualunque di quelle 9 cartelle sia presente su CD va
>> ricopiata su HD?
>>
>> ho provato con
>> if Fso.FolderExists ("D:\IMAGES") or ("D:\DICOM") or ecc. ecc.
>>
>> ma non funzionava
>
>
> Un semplice OR dovrebbe funzionare, ma devi ripetere l'istruzione completa ("Fso.FolderExists(xxx) or Fso.FolderExists(yyy) or ...."
>
> In ogni caso, puoi renderla più compatta con un ciclo, ad esempio con:
>
> dim fso, folders, i
>
> Set fso = CreateObject("Scripting.FileSystemObject")
> folders = Array("D:\000","D:\CDSURF","D:\DATA","D:\DICOM","D:\IMAGES","D:\studies","D:\_STUDIES","D:\study000")
>
> for i = 0 to UBound(folders)
>     If fso.FolderExists(folders(i)) Then CopiaCDsuHD
> next
>

grazie, funziona!!!

[toc] | [prev] | [standalone]


Back to top | Article view | it.comp.lang.visual-basic


csiph-web