Question on Scripting in Visual Basic

  • Thread starter Thread starter Time Traveler
  • Start date Start date
  • Tags Tags
    Visual
Click For Summary

Discussion Overview

The discussion centers around scripting in Visual Basic, specifically focusing on automating the processing of multiple files without manually changing file names. Participants explore methods to loop through file names dynamically based on month and time variables.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant expresses difficulty in automating file name changes in a Visual Basic script and seeks assistance, noting that the script works for individual files but not for looping through multiple files.
  • Another participant questions the purpose of the analysis, asking for clarification on what the user intends to analyze.
  • A suggestion is made to use the dir() function to iterate through files in a directory, providing a code snippet as an example.
  • Another participant points out that the original string concatenation method used in the script does not substitute the values of the month and time variables, recommending a different approach to construct the file names dynamically.

Areas of Agreement / Disagreement

Participants have not reached a consensus on the best approach to automate the file processing, with differing suggestions and some uncertainty about the user's specific goals.

Contextual Notes

There are limitations regarding the clarity of the user's intended analysis and the specific requirements for file naming conventions. The discussion also reflects varying levels of familiarity with Visual Basic scripting.

Who May Find This Useful

Individuals interested in Visual Basic scripting, particularly those looking to automate file handling and processing tasks.

Time Traveler
Messages
4
Reaction score
0
I've been trying to figure this out for the past couple of days but I'm at a complete lost on it. I know I'm missing something or mayby it just can't be done but how can I loop over a set of files as seen in part of the script below instead of changing the file name manually?

I have a couple hundred files that I want to analyze but I don't want to have to change the time and month in the file name manually by editing the script after each run. I though something along the lines of what I have below would work but apperently it's not. Please note that I'm relatively new at Visual Basic so any imput would be appreciated.

Dim File As String
Dim File1 As String
Dim File2 As String
Dim File3 As String
Dim File4 As String

Dim Mth As Integer
Dim Tim As Integer

For Mth = 03 To 10 Step 1
For Tim = 17 To 22 Step 1
File = SurferApp.Path + "\Summer Project\data\2003"
File1 = File + "\diff\diff_2003_Mth_Tim"
File2 = File + "\Images\diff_2003_Mth_Tim"
File3 = File + "\Surfer Files\diff_2003_Mth_Tim"
File4 = File + "\Grid Files\diff_2003_Mth_Tim"

......

Next Tim
Next Mth


I should also note that the script works fine when I execute it one day at a time ... it does exactly what i want it to do ... it's only looping over all the files automatically that won't work.
 
Last edited:
Computer science news on Phys.org
perhaps its too late here for my to think clearly, but what exactly are you trying to do, you say analyze, but analyze for what?
 
Why don't you use the dir() function?

IE:

Dim temp as string
temp = dir("C:\*")
while temp <> ""
'do stuff to file (filepath = "C:\" & temp)
temp = dir() 'get next file matching last call
wend
 
Using the string "\diff\diff_2003_Mth_Tim" will not automatically substitute the values of Mth and Tim; it'll just give you a string that literally contains "\diff\diff_2003_Mth_Tim".

Instead, use something like "\diff\diff_2003_" & Mth & "_" & Tim, which will produce strings like "\diff\diff_2003_3_17".
 

Similar threads

  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
9K
  • · Replies 5 ·
Replies
5
Views
11K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 25 ·
Replies
25
Views
6K