Question on Scripting in Visual Basic

  • Thread starter Time Traveler
  • Start date
  • Tags
    Visual
In summary, the person is trying to loop over a set of files without having to manually change the file name each time. They are relatively new to Visual Basic and are looking for input on how to approach this problem. They have shared a code snippet but it is not working as expected. Suggestions have been given to use the dir() function and to properly format the file names in the code.
  • #1
Time Traveler
4
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
  • #2
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?
 
  • #3
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
 
  • #4
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".
 

1. What is scripting in Visual Basic?

Scripting in Visual Basic refers to the process of writing code in the Visual Basic programming language to automate repetitive tasks or create small programs that can be executed within a larger application.

2. What are the benefits of using scripting in Visual Basic?

Some benefits of using scripting in Visual Basic include increased productivity, easier debugging and maintenance, and the ability to integrate with other applications and technologies.

3. How do I start scripting in Visual Basic?

To start scripting in Visual Basic, you will need a basic understanding of the language and a development environment, such as Visual Studio. You can then create a new project or open an existing one and start writing code in the "Script" or "Macro" section.

4. Can I use scripting in Visual Basic for web development?

Yes, you can use scripting in Visual Basic for web development. Visual Basic can be used to create web applications using ASP.NET and can also be used for client-side scripting with the use of VBScript.

5. Is scripting in Visual Basic still relevant?

While there are newer languages and technologies available, scripting in Visual Basic is still widely used in various industries and has a large community of developers. It is also supported by Microsoft and continues to be updated with new features and improvements.

Similar threads

  • Programming and Computer Science
Replies
19
Views
1K
  • Programming and Computer Science
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Advanced Physics Homework Help
Replies
6
Views
1K
  • Programming and Computer Science
Replies
2
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Programming and Computer Science
Replies
5
Views
10K
  • Programming and Computer Science
Replies
9
Views
1K
  • Beyond the Standard Models
Replies
25
Views
5K
Back
Top