Vb.net – If checkbox is checked, run “something”

vb.net

I've got a simple Visual Basic 2008 Express Edition form which looks like this:
[link Screenshot of simple form][1]

I need some help with a skeleton script, which checks to see if each checkbox is checked or not.
I've got a set of Word templates which all contain a macro.
And I want to run the macro of each template, if the template exists.

So basically something like the following (including loads of errors, probably):

    Dim strFile1
    Dim strFile2
    Dim strFile3
    Dim strFile4
    Dim strFile5
    Dim strFile6

if checkbox1.Checked Then
try to run command (Winword.exe c:\temp\document.doc /mNameOfMacro)
On error MsgBox ("could not find file from checkbox1")

    if checkbox2.Checked Then
try to run command (Winword.exe c:\temp\document2.doc /mNameOfMacro)
On error MsgBox ("could not find file from checkbox2")

    if checkbox3.Checked Then
try to run command (Winword.exe c:\temp\document3.doc /mNameOfMacro)
On error MsgBox ("could not find file from checkbox3")

    if checkbox4.Checked Then
try to run command (Winword.exe c:\temp\document4.doc /mNameOfMacro)
On error MsgBox ("could not find file from checkbox4")


    if checkbox5.Checked Then
try to run command (Winword.exe c:\temp\document5.doc /mNameOfMacro)
On error MsgBox ("could not find file from checkbox5")

    if checkbox5.Checked Then
try to run command (Winword.exe c:\temp\document5.doc /mNameOfMacro)
On error MsgBox ("could not find file from checkbox5")

I know this pseudocode isn't correct at all, because I'm kind of a beginner, and designer over a programmer. But I've just started learning and I know this is pretty basic.
It's just getting an overview of the logics in programming. And I think that getting to learn how to do this will help me with other things as well.

Best Answer

Ok, just found the answer by doing this:

 Dim strFile1 = ("c:\temp\file3.txt")
 Dim strFile2 = ("c:\temp\file4.txt")

    If chkbxRapport.Checked Then
        If My.Computer.FileSystem.FileExists(strFile1) Then
            System.Diagnostics.Process.Start(strFile1)
        Else : MsgBox("Can't find the file" & " " & strFile1)
        End If
    End If

    If chkbxRapport_EN.Checked Then
        If My.Computer.FileSystem.FileExists(strFile2) Then
            System.Diagnostics.Process.Start(strFile2)
        Else : MsgBox("Can't find the file" & " " & strFile2)
        End If
    End If
Related Topic