Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check boxes 1

Status
Not open for further replies.

cheetahz

Technical User
Dec 4, 2008
101
US
I need to know when a checkbox is checked and run some code for each checkbox checked (different code) 20 checkboxes and not run the code if not checked.

i have tried both of these
If DlgValue("CheckBox1")=True then
'If CheckBox1 = True Then

neither works?

and if anyone can help with some kind of loop to get this working i would be so thankfull
 
From the help file:
Code:
Dialog (function) Example
<Close> <Copy> <Print>

This example creates a dialog box with a drop down combo box in it and three buttons: OK, Cancel, and Help. The Dialog function used here enables the subroutine to trap when the user clicks on any of these buttons.

Sub main
   Dim cchoices as String
   cchoices="All"+Chr$(9)+"Nothing"
    Begin Dialog UserDialog 180, 95, "E! Basic Dialog Box"
       ButtonGroup .ButtonGroup1
       Text  9, 3, 69, 13, "Filename:", .Text1
       ComboBox  9, 17, 111, 41, cchoices, .ComboBox1
       OKButton  131, 8, 42, 13
       CancelButton  131, 27, 42, 13
       PushButton 132, 48, 42, 13, "Help", .Push1
    End Dialog
   Dim mydialogbox As UserDialog
   answer= Dialog(mydialogbox)

   Select Case answer
      Case -1
         MsgBox "You pressed OK"
      Case 0
         MsgBox "You pressed Cancel"
      Case 1
         MsgBox "You pressed Help"
   End Select
End Sub

Maybe SELECT - CASE is something for you?
 
yes i seen that in the help file, but what i need is to run code if a checkbox is checked and yes maybe CASE is they way to go but what would that look like?

As i said i dont know how to tell if a checkbox is checked and if it is run some code


thanks for the help
 
please.
nobody can help me with this
how to see if check box is checked and run code if it is
 
It would be something like:

If DlgValue.CheckBox1 = 1 Then
Run Code
End If
 
Code:
Sub Main
   Begin Dialog UserDialog 300, 100, "Checkboxes"
      ButtonGroup .ButtonPressed
      OkButton 5, 40, 20, 12, .BtnOK

      Checkbox 5,   5,  20, 12, "1",  .chk1
      Checkbox 30,  5,  20, 12, "2",  .chk2
      Checkbox 55,  5,  20, 12, "3",  .chk3
      Checkbox 80,  5,  20, 12, "4",  .chk4
      Checkbox 105, 5,  20, 12, "5",  .chk5
      Checkbox 130, 5,  20, 12, "6",  .chk6
      Checkbox 155, 5,  20, 12, "7",  .chk7
      Checkbox 180, 5,  20, 12, "8",  .chk8
      Checkbox 205, 5,  20, 12, "9",  .chk9
      Checkbox 230, 5,  20, 12, "10", .chk10
   End Dialog

   On Error Resume Next

   Dim my_dialog as UserDialog
   Dialog my_dialog
   
   If my_dialog.chk1  Then Msgbox "RUN CODE FOR .chk1"
   If my_dialog.chk2  Then Msgbox "RUN CODE FOR .chk2"
   If my_dialog.chk3  Then Msgbox "RUN CODE FOR .chk3"
   If my_dialog.chk4  Then Msgbox "RUN CODE FOR .chk4"
   If my_dialog.chk5  Then Msgbox "RUN CODE FOR .chk5"
   If my_dialog.chk6  Then Msgbox "RUN CODE FOR .chk6"
   If my_dialog.chk7  Then Msgbox "RUN CODE FOR .chk7"
   If my_dialog.chk8  Then Msgbox "RUN CODE FOR .chk8"
   If my_dialog.chk9  Then Msgbox "RUN CODE FOR .chk9"
   If my_dialog.chk10 Then Msgbox "RUN CODE FOR .chk10"
End Sub
 
thank you i will try this.

wont i need and else or at least an end if?
 
another question do i have to use a message box or can i have it just run the code in order?

how do i get it to just run say checkbox 1 then when finished rund checkbox 2 code like that.?

again thanks
 
it is working somewhat!

but i have this for checkbox two and it is not working?
ElseIf my_dialog.CheckBox2 Then 'Msgbox "RUN CODE FOR .CheckBox2"

would i not use an ElseIf for each checkbox?

 
So sorry for all the posts i should have just worked with it first.

I got it!
thanks for all the help

just an If statement for each one and it works fine
 
Well it is not working if say checkbox 1 and 8 is checked even chaeckbox 1 and 3 it stops after checkbox1??

Please help
Thanks again
 
OK, again sorry for all the posts

if i check the boxes in order it works fine but as i said if i skip o checkbox it stop and doesnt run the rest that are checked.

I tried ElseIF and that did not work either,
I am at a loss
 
Code:
If my_dialog.chk1 Then Msgbox "RUN CODE FOR .chk1"
is the same as
Code:
If my_dialog.chk1 Then
   Msgbox "RUN CODE FOR .chk1"
End If
Why do you need an ElseIf? The code above says, "If chk1 is checked, Msgbox "RUN CODE FOR .chk1." If chk1 is not checked, do nothing. What are you trying to achieve?
 
well, as i said it seems to work fine if all checkboxes are checked (like 1,2,3,4,5 etc.) like that but if i check box 1 and then skip checkbox 2 and then check checkbox 3 it stops running code after checkbox1


So i was just trying to get it to work.
 
i tried to run it without cheking box 1 and it does nothing?

so it has to be check 1 or 1,2,3,4,5 like that
 
Here is the code i have
--------------------------

' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$

Sub Main()
'--------------------------------------------------------------------------------
' Get the main system object
Dim Sessions As Object
Dim System As Object

Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System is Nothing) Then
Msgbox "Could not create the EXTRA System object. Stopping macro playback."
STOP
End If
Set Sessions = System.Sessions

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Stopping macro playback."
STOP
End If
'--------------------------------------------------------------------------------






Begin Dialog cbdlg 99, 130, 185, 396, "test"
ButtonGroup .bg
OkButton 131, 74, 50, 14
CancelButton 132, 109, 50, 14
CheckBox 0, 0, 40, 10, "LINE1", .CheckBox1
CheckBox 0, 18, 40, 10, "LINE2", .CheckBox2
CheckBox 0, 39, 40, 10, "LINE3", .CheckBox3
CheckBox 0, 59, 40, 10, "LINE4", .CheckBox4
CheckBox 1, 77, 40, 10, "LINE5", .CheckBox5
CheckBox 0, 99, 40, 10, "LINE6", .CheckBox6
CheckBox 0, 121, 40, 10, "LINE7", .CheckBox7
CheckBox 0, 141, 40, 10, "LINE8", .CheckBox8
CheckBox 0, 161, 40, 10, "LINE9", .CheckBox9
CheckBox 0, 181, 40, 10, "LINE10", .CheckBox10
CheckBox 0, 201, 40, 10, "LINE11", .CheckBox11
CheckBox 0, 221, 40, 10, "LINE12", .CheckBox12
CheckBox 0, 241, 40, 10, "LINE13", .CheckBox13
CheckBox 0, 261, 40, 10, "LINE14", .CheckBox14
CheckBox 0, 283, 40, 10, "LINE15", .CheckBox15
CheckBox 0, 303, 40, 10, "LINE16", .CheckBox16
CheckBox 0, 324, 40, 10, "LINE17", .CheckBox17
Text 44, 34, 96, 8, "Please check the checkboxes"
Text 42, 46, 120, 9, " test "
Text 44, 59, 135, 10, " test"
CheckBox 0, 346, 40, 10, "LINE18", .CheckBox18
CheckBox 0, 366, 40, 10, "LINE19", .CheckBox19
CheckBox 0, 385, 40, 10, "LINE20", .CheckBox20
Picture 135, 0, 47, 32, "H:\My Pictures\test.bmp", 16, .test
Text 45, 78, 76, 8, "And then click OK -->"
End Dialog












Dim my_dialog as cbdlg
On Error Resume Next
Dialog my_dialog
If Err=102 then
MsgBox "canceled."
End If



' Set the default wait timeout value
g_HostSettleTime = 400 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If (Sess0 is Nothing) Then
Msgbox "Could not create the Session object. Stopping macro playback."
STOP
End If
If Not Sess0.Visible Then Sess0.Visible = TRUE




If my_dialog.CheckBox1 Then


' This section of code contains the recorded events
Sess0.Screen.Sendkeys("<Home>CCM 01 4837 999<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Tab><Tab><Tab><Tab>DS<Tab><Tab><Tab>02<Tab><Tab><Tab><Tab><Tab>TEST<Tab>02100<Enter>")

Sess0.Screen.Sendkeys("<Clear>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
'Sess0.Screen.Sendkeys("CDS<Enter>")
'Sess0.Screen.WaitHostQuiet(g_HostSettleTime)


'This section of code contains the recorded events
Sess0.Screen.Sendkeys("<Home>CSD4 01<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Tab><Tab><Tab>01<Tab><Tab><Tab><Tab><Tab><Tab>1<Tab><Tab><Tab><Tab><Tab><Tab>11<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>u<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Clear>")





If my_dialog.CheckBox2 Then


' This section of code contains the recorded events
Sess0.Screen.Sendkeys("<Home>CCM 02 4837 999<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Tab><Tab><Tab><Tab>DS<Tab><Tab><Tab>02<Tab><Tab><Tab><Tab><Tab>UNAUTH TRANS<Tab>02100<Enter>")

Sess0.Screen.Sendkeys("<Clear>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
'Sess0.Screen.Sendkeys("CDS<Enter>")
'Sess0.Screen.WaitHostQuiet(g_HostSettleTime)


'This section of code contains the recorded events
Sess0.Screen.Sendkeys("<Home>CSD4 02<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Tab><Tab><Tab>01<Tab><Tab><Tab><Tab><Tab><Tab>1<Tab><Tab><Tab><Tab><Tab><Tab>11<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>u<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Clear>")



If my_dialog.CheckBox3 Then


' This section of code contains the recorded events
Sess0.Screen.Sendkeys("<Home>CCM 03 4837 999<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Tab><Tab><Tab><Tab>DS<Tab><Tab><Tab>02<Tab><Tab><Tab><Tab><Tab>TEST<Tab>02100<Enter>")

Sess0.Screen.Sendkeys("<Clear>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
'Sess0.Screen.Sendkeys("CDS<Enter>")
'Sess0.Screen.WaitHostQuiet(g_HostSettleTime)


'This section of code contains the recorded events
Sess0.Screen.Sendkeys("<Home>CSD4 03<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Tab><Tab><Tab>01<Tab><Tab><Tab><Tab><Tab><Tab>1<Tab><Tab><Tab><Tab><Tab><Tab>11<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>u<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.Sendkeys("<Clear>")


System.TimeoutValue = OldSystemTimeout


End If

End If
End If
End Sub
 
Try this instead.
Code:
If my_dialog.CheckBox1 Then
   Sess0.Screen.Sendkeys("<Home>CCM 01 4837 999<Enter>")    
   Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
   Sess0.Screen.Sendkeys("<Tab><Tab><Tab><Tab>DS<Tab><Tab><Tab>02<Tab><Tab><Tab><Tab><Tab>TEST<Tab>02100<Enter>")    
   Sess0.Screen.Sendkeys("<Clear>")    
   Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
   'Sess0.Screen.Sendkeys("CDS<Enter>")    
   'Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
   Sess0.Screen.Sendkeys("<Home>CSD4 01<Enter>")    
   Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
   Sess0.Screen.Sendkeys("<Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Tab><Tab><Tab>01<Tab><Tab><Tab><Tab><Tab><Tab>1<Tab><Tab><Tab><Tab><Tab><Tab>11<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>u<Enter>")    
   Sess0.Screen.WaitHostQuiet(g_HostSettleTime)    
   Sess0.Screen.Sendkeys("<Clear>")
End If
        
If my_dialog.CheckBox2 Then 
   Sess0.Screen.Sendkeys("<Home>CCM 02 4837 999<Enter>")    
   Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
   Sess0.Screen.Sendkeys("<Tab><Tab><Tab><Tab>DS<Tab><Tab><Tab>02<Tab><Tab><Tab><Tab><Tab>UNAUTH TRANS<Tab>02100<Enter>")    
   Sess0.Screen.Sendkeys("<Clear>")    
   Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
   'Sess0.Screen.Sendkeys("CDS<Enter>")    
   'Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
   Sess0.Screen.Sendkeys("<Home>CSD4 02<Enter>")    
   Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
   Sess0.Screen.Sendkeys("<Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Tab><Tab><Tab>01<Tab><Tab><Tab><Tab><Tab><Tab>1<Tab><Tab><Tab><Tab><Tab><Tab>11<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>u<Enter>")    
   Sess0.Screen.WaitHostQuiet(g_HostSettleTime)    
   Sess0.Screen.Sendkeys("<Clear>")
End If
        
If my_dialog.CheckBox3 Then 
   Sess0.Screen.Sendkeys("<Home>CCM 03 4837 999<Enter>")    
   Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
   Sess0.Screen.Sendkeys("<Tab><Tab><Tab><Tab>DS<Tab><Tab><Tab>02<Tab><Tab><Tab><Tab><Tab>TEST<Tab>02100<Enter>")    
   Sess0.Screen.Sendkeys("<Clear>")    
   Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
   'Sess0.Screen.Sendkeys("CDS<Enter>")    
   'Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
   Sess0.Screen.Sendkeys("<Home>CSD4 03<Enter>")    
   Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
   Sess0.Screen.Sendkeys("<Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Tab><Tab><Tab>01<Tab><Tab><Tab><Tab><Tab><Tab>1<Tab><Tab><Tab><Tab><Tab><Tab>11<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>u<Enter>")    
   Sess0.Screen.WaitHostQuiet(g_HostSettleTime)    
   Sess0.Screen.Sendkeys("<Clear>")
End If
 
thank you so much that is working perfectly on my pc.
but when i try to run it on other pc's nothing works
is there something other than macro and .ETB file that needs copied?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top