If the checkbox is checked, run "something"

I have a simple Visual Basic 2008 Express Edition form that looks like this: [link Screenshot of a simple form] [1]

I need help with a skeleton script that checks if each checkbox is checked or not. I have a set of Word templates that contain a macro. And I want to run a macro of each template if the template exists.

So, basically something like the following (including probably a lot of bugs):

    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 is not entirely correct because I am kind of a beginner and designer over programmer. But I've just started learning and I know it's pretty simple. He just gets an overview of the programming logic. And I think learning how to do it will help me in other things as well.

+1


a source to share


2 answers


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

      

+1


a source


This blog post should explain it enough. Starting a process in VB



System.Diagnostics.Process that interests you the most.

0


a source







All Articles