Attempt to make code more readable not working

Status
Not open for further replies.

karmacable

Registered User.
Local time
Today, 09:53
Joined
Sep 13, 2011
Messages
32
I have some long code which I'm attempting to simplify through variables, but I'm not achieving success. Here's the original code;

PHP:
Dim Cameras As String
 
If Me.cmb1stCamACam & Me.cmb1stCamBCam <> 0 Then
   If Me.cmb1stCamACam = Me.cmb1stCamBCam Then
      Cameras = "2 x " & Me.cmb1stCamACam.Column(1)
      Me.lbl1stCameras.Caption = Cameras
   Else
      Cameras = "1 x " & Me.cmb1stCamACam.Column(1) & vbNewLine & "1 x " & Me.cmb1stCamBCam.Column(1)
      Me.lbl1stCameras.Caption = Cameras
   End If
Else
   lbl1stCamera.Caption = ""
End If

It works great. Now, when I try to setup variable for the long Me.xxx names and such like this;

PHP:
Dim Cameras As String
Dim CamA As Integer
Dim CamB As Integer
Dim CamAName As String
Dim CamBName As String
Dim Caption As String
 
CamA = Me.cmb1stCamACam
CamB = Me.cmb1stCamBCam
CamAName = Me.cmb1stCamACam.Column(1)
CamBName = Me.cmb1stCamBCam.Column(1)
Caption = Me.lbl1stCameras.Caption
 
 
If CamA & CamB <> 0 Then
    If CamA = CamB Then
        Cameras = "2 x " & CamAName
        Caption = Cameras
    Else
        Cameras = "1 x " & CamAName & vbNewLine & "1 x " & CamBName
        Caption = Cameras
    End If
Else
    Caption = ""
End If

Nothing happens! I even tried setting all the variable as 'Variant', but again the code doesn't run. Any suggestions?
 
Last edited:
I believe the first change to make is from this line:

If CamA & CamB <> 0 Then

to

If CamA <> 0 And CamB <> 0 Then

 
Tried it, but nothing different happens
 
Put a breakpoint and then F8 through watching what it is doing and what the various values are.
 
Status
Not open for further replies.

Users who are viewing this thread

Back
Top Bottom