views:

602

answers:

3

Hi, 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.

A: 

This blog post should explain it sufficiently. Running a process in VB

Its System.Diagnostics.Process that you are most interested in.

Serapth
Thanx, I've got that part. But what about the checkboxes? Got any examples?
Kenny Bones
Your pseudocode for checking if a checkbox is checked is basically valid. I am not sure what it is you need? I assume you have some kind of button or action that starts this process off, like a button OnClick even handler, in which you would implement your tests if checkboxs are checked or not. What part is it you are having trouble with, as I am not really sure what I would be giving you an example of?
Serapth
A: 

Check this link to a SO question that I asked recently: http://stackoverflow.com/questions/737444/start-another-exe-in-managed-code

JFV

JFV
A: 

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
Kenny Bones
Nevertheless that you found the answer to your question I don't think it is a "good idea"(TM) anyway. Users are expecting to (de)select something when they deal with checkboxes; they don't expect that something happens when they check or uncheck them. It would be better to have a separate "apply" button that executes all the checked scripts. Just my 2c :-)
lothar
Yes of course :) This is the code that's executed on a buttons Click event. This doesn't happen as the user check or uncheck the checkboxes :)
Kenny Bones
"2c" By: Lothar:How do we write the cent symbol on our keyboards? Hmmm...? lol
baeltazor