select ..case ...hardcoding ?

  • Thread starter Thread starter James
  • Start date Start date
J

James

i wrote a filewatcher application and inside the code, i've a select case
statement :
Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e As
System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created

Select Case UCase(e.Name)
Case "mytest.txt"
Process.Start("Encryption.bat")
EventLog1.WriteEntry("Filename " & e.Name & " created.")
Case "mytest1.txt"
Process.Start("Encryption1.bat")
EventLog1.WriteEntry("Filename " & e.Name & " created.")
End Select

end sub

this work because my user has informed me earlier what are the possible
filenames. However i would like to improve the code further such that i
don't want to hard-code filenames into my application. I created a
masterlist.txt file and my application read the file (streamreader) as
follows :

masterlist.txt
========
;allows user to flexibly put in any files to watch and execute the batch
file accordingly
mytest.txt=encryption.bat
mytest1.txt=encryption1.bat

After reading it into different variables (how do i split into an array ?) ,
does anyone know the ALTERNATIVE SELECT-CASE codes to write such that when
mytest.txt appears, filewatcher will execute encryption.bat and other batch
files respectively ?

Eg

if mytest.txt = true then process.start("encryption.bat") ?

or something of this nature ?

if array(1) = true then process.start array(1.1)
if array(2) = true then process.start array(2.1)
 
James said:
Select Case UCase(e.Name)
Case "mytest.txt"

UCase...."mytest.txt".... can you see a potential problem there?
I created a masterlist.txt file and my application read the file
(streamreader) as follows After reading it into different variables (how
do i split into an array ?) ,

What parts of "it" do you read into "different variables"? What is the "it"
you want to split() into an array?

Andrew
 
[snip]
masterlist.txt
========
;allows user to flexibly put in any files to watch and execute the batch
file accordingly
mytest.txt=encryption.bat
mytest1.txt=encryption1.bat

After reading it into different variables (how do i split into an array ?)
,

Split()

Example code for a button using it:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
'Test string can be replaced:
Dim myString As String = "mytest.txt=encryption.bat"

'Split string into an array (Without the "=")
Dim myArray() As String = Split(myString, "=")

'Get total of entries in array... because I can...
'If your gonna use this variable then it should be in a module as
public
' It would then be used as: myArrayCount = myArray.Length
Dim myArrayCount As Integer = myArray.Length

MsgBox(myArray(0).ToString + vbCrLf + myArray(1).ToString + vbCrLf _
+ "Total records: " + myArrayCount.ToString, MsgBoxStyle.OKOnly, _
"Example")
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top