• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Syntax Help with ELSE

             
In the statement below I cannot figure out how to end the else statement on either of the logtext(s). It simply runs to the last Logtext and will not unload or stop on the first one. I did try putting unload there and it still runs to the last one, printing out two copies. It should only print one, if it would stop where it should.
NOTE:The two end if's are correct where they are as this is only a portion of the code.


***********************************
      Else
          MsgBox (pin.GetResultMessage(nRes))
       
                If (ApprovalCode) = True Then
              Call PrintLayout6
                 End If
               If (ApprovalCode) = False Then
               Exit Sub
                 End If
      End If
      End If

               
          LogText ("PromptCreditCardEntry Unsuccessfull")
                     
          Customers.Command13.Value = True
          Customers.Command21.Value = True
           Customers.CmdClear.Value = True
          Customers.CmdSale3.Value = True
          pin.Close (ccTransact.hwnd)
                              Unload Me
          LogText ("XCDebitPurchase Unsuccessfull - " + ErrorMsg)
                 
         
            Customers.Command13.Value = True
           Customers.Command21.Value = True
            Customers.CmdClear.Value = True
              Customers.CmdSale3.Value = True
                 Command8_Click 'this is a print command for the logtext
                              pin.Close (ccTransact.hwnd)
                              Unload Me
           

    End Sub
0
mindserve
Asked:
mindserve
1 Solution
 
samstarkeyCommented:
Can you place the whole If, Else statement here?

On what you have shown, you could try this

 Else
          MsgBox (pin.GetResultMessage(nRes))
   
                If (ApprovalCode)  Call PrintLayout6
                Else
                      Exit Sub
                End If
      End If
      End If
0
 
mindserveAuthor Commented:
No , that didn't work,  then I get an invalid procedure call...
I need it to stop not on the approval code, which it would with the code I have, but on the unsuccessfull Logtext's..... That is where the error is. It simply runs on past without stopping until the last logtext.

I have a similar one running on Credit which does work, but for some reason this code does not   because of this :MsgBox (pin.GetResultMessage(nRes))

So here is the code that does work for credit but not for debit. They look similar, but the debit does not function like the credit. The only difference is the Else statement beginning later on in the code...

Credit portion of code:

330               If (ApprovalCode) = True Then
340                Call PrintLayout7

350                End If
360                 If (ApprovalCode) = False Then
            'Clear the customers screen from any entries as it was not approved, then exit sub and close the screen.
                   
370                 Exit Sub

380                 End If
390          Else
                 
400              LogText ("XCPurchase Unsuccessfull - " + ErrorMsg)
'410             Command8_Click
410             Customers.Command16.Value = True
420            Customers.Command21.Value = True
430             Customers.CmdClear.Value = True
440            Customers.CmdSale3.Value = True
450                Command8_Click
460                    pin.Close (ccTransact.hwnd)
470                         Unload Me
480          End If
490       Else
               
500          LogText ("PromptCreditCardEntry Unsuccessfull")

510             Customers.Command16.Value = True
520              Customers.Command21.Value = True
530              Customers.CmdClear.Value = True
540              Customers.CmdSale3.Value = True

560                    pin.Close (ccTransact.hwnd)
570                         Unload Me
580      End If
       
0
 
mindserveAuthor Commented:
Here is both the credit and debit portion of the code.
The credit does stop on the logtext for the else end if portion...however; the debit does not stop and I cannot get an else end if statement in there.

This one is oK
Private Sub mnuPurchase_Click()

      ' Procedure : mnuPurchase_Click
      ' DateTime  : 5/12/2006 04:40
      ' Author    :
      ' Purpose   :CREDIT PURCHASE
      '--------------------------------------------------------
      '


            Dim sTmp As String
            Dim Dtmp As String
10            txtLog = vbNullString
20    If txtAmt.Text = "" Then
30    txtAmt.Text = "0.00"
40    End If
50    If TxtTips.Text = "" Then
60    TxtTips.Text = "0.00"
70    End If
80    If txtFields(0).Text = vbNullString Then
90    Call MsgBox("You must choose a CreditCard payment type from the drop down " _
            & vbCrLf & "box before you can complete the transaction." _
            , vbExclamation, "Credit Card Payment Type")

100   Exit Sub
110   End If
120                 If txtFields(0).Text = "CreditCard" Then
                 
130             End If

140    If txtFields(0).Text <> "CreditCard" Then
150    Call MsgBox("You have changed payment types. " _
                   & vbCrLf & "The drop down box shows a different " _
                   & vbCrLf & "payment type than the one you are now trying to process. " _
                   & vbCrLf & "If you wish to change the payment type, click the C button " _
                   & vbCrLf & "and then change the payment type and proceed with processing." _
                   , vbCritical, "Payment Type Error on Drop Down Box")
       
160    Exit Sub
170    End If
180       LogStartFunction ("XCharge")
         
190       If (XCTran.PromptCreditCardEntry(ccTransact.hwnd, "Credit Card Purchase Information", False, _
                      False, False, Swipe, Track1, Track2, CC, CCTypeName, ExpirationMonth, _
                      ExpirationYear, CardHolderName, ZIP, Address, CVV)) Then
                     
200         If (XCTran.XCPurchase(ccTransact.hwnd, txtTranFolder.Text, "Purchase", _
                      chkShowStatus.Value, chkShowResult.Value, txtClerk.Text, txtRcpt.Text, CC, _
                      ExpirationYear + ExpirationMonth, Swipe, txtAmt.Text, ZIP, _
                      Address, CVV, ErrorMsg, ApprovalCode, AVSResult, CVVResult)) Then
210               LogText ("ApprovalCode = " + ApprovalCode)
220               LogText ("CC = " + CCTypeName)
230               sTmp = CC
240               Mid(sTmp, 1, 12) = "XXXXXXXXXXXX"
250               LogText ("CC = " + sTmp)
260               LogText ("TicketID= " + txtRcpt.Text)
270               LogText ("Employee = " + txtClerk.Text)
280               LogText ("Tip Amount= " + FormatCurrency(CCur(TxtTips))) 'Jamie Test May 15 -06
290               LogText ("Ticket Amount= " + Customers.txtticketfields(9).Text)
300               LogText ("Total Amount(Plus Tip)= " + FormatCurrency(CCur(txtAmt)))
310               Dtmp = Format$(Now, "Short Date")
320               LogText ("Date= " + Dtmp)

330               If (ApprovalCode) = True Then
340                Call PrintLayout7

350                End If
360                 If (ApprovalCode) = False Then
            'Clear the customers screen from any entries as it was not approved, then exit sub and close the screen.
                   
370                 Exit Sub

380                 End If
390          Else
                 
400              LogText ("XCPurchase Unsuccessfull - " + ErrorMsg)
'410             Command8_Click
410             Customers.Command16.Value = True
420            Customers.Command21.Value = True
430             Customers.CmdClear.Value = True
440            Customers.CmdSale3.Value = True
450                Command8_Click
460                    pin.Close (ccTransact.hwnd)
470                         Unload Me
480          End If
490       Else
               
500          LogText ("PromptCreditCardEntry Unsuccessfull")

510             Customers.Command16.Value = True
520              Customers.Command21.Value = True
530              Customers.CmdClear.Value = True
540              Customers.CmdSale3.Value = True

560                    pin.Close (ccTransact.hwnd)
570                         Unload Me
580      End If
**************************************



This is NOT ok
DEBIT PURCHASE

************************************
Private Sub mnuDebitPurchase_Click()

      Dim PINBlock As String
          Dim PINKey As String
            Dim sTmp As String
      Dim Dtmp As String
 

10    txtLog = vbNullString
20    If txtAmt.Text = "" Then
30    txtAmt.Text = "0.00"
40    End If
50    If TxtTips.Text = "" Then
60    TxtTips.Text = "0.00"
70    End If
80    If txtFields(0).Text = vbNullString Then
90    Call MsgBox("You must choose Debit Purchase payment type from the drop down " _
            & vbCrLf & "box before you can complete the transaction." _
            , vbExclamation, "Debit Purchase Payment Type")

100   Exit Sub
110   End If
120                 If txtFields(0).Text = "DebitCard" Then
                 
130             End If

140    If txtFields(0).Text <> "DebitCard" Then
150    Call MsgBox("You have changed payment types. " _
                   & vbCrLf & "The drop down box shows a different " _
                   & vbCrLf & "payment type than the one you are now trying to process. " _
                   & vbCrLf & "If you wish to change the payment type, click the C button " _
                   & vbCrLf & "and then change the payment type and proceed with processing." _
                   , vbCritical, "Payment Type Error on Drop Down Box")
       
160    Exit Sub
170    End If
                   
180     LogStartFunction ("XCDebitPurchase")
190       If (GetDebitSwipe(Track2, CC)) Then
200           nRes = pin.PromptDebitPIN(ccTransact.hwnd, CC, txtAmt.Text, PINBlock, PINKey)
210           If (nRes = 0) Then
220               Call DisplayProcessingMessage
230               Call XCTran.XCDebitPurchase(ccTransact.hwnd, txtTranFolder.Text, "Debit Card Purchase Information ", _
                          True, True, txtClerk.Text, txtRcpt.Text, txtAmt.Text, _
                          "0.00", txtAmt.Text, CC, Track2, PINBlock, PINKey, ErrorMsg, ApprovalCode)
240               Call ShowLogo
250               LogText ("ApprovalCode = " + ApprovalCode)
260
270               LogText ("CC = " + CCTypeName)
280             sTmp = CC
290               Mid(sTmp, 1, 12) = "XXXXXXXXXXXX"
300               LogText ("CC = " + sTmp)
310              LogText ("TicketID= " + txtRcpt.Text)
320               LogText (Employee = " " + txtClerk.Text)
330              LogText ("Tip Amount= " + FormatCurrency(CCur(TxtTips)))
340               LogText ("Ticket Amount= " + Customers.txtticketfields(9).Text)
350                 LogText ("Total Amount(Plus Tip)= " + FormatCurrency(CCur(txtAmt)))
360                Dtmp = Format$(Now, "Short Date")
370               LogText ("Date= " + Dtmp)
                 
380                 Else
390             MsgBox (pin.GetResultMessage(nRes))

400                If (ApprovalCode) = True Then
410                Call PrintLayout6
420                 End If
430                 If (ApprovalCode) = False Then
440                 Exit Sub
450                 End If
460    End If
470      End If

               
480           LogText ("PromptCreditCardEntry Unsuccessfull")
                     
490           Customers.Command13.Value = True
500           Customers.Command21.Value = True
510           Customers.CmdClear.Value = True
520            Customers.CmdSale3.Value = True

530            LogText ("XCDebitPurchase Unsuccessfull - " + ErrorMsg)
                 
         
540            Customers.Command13.Value = True
550            Customers.Command21.Value = True
560             Customers.CmdClear.Value = True
570               Customers.CmdSale3.Value = True
580                 Command8_Click
590                    pin.Close (ccTransact.hwnd)
600                         Unload Me
           
         
End Sub
       
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
EDDYKTCommented:
may be replace

460    End If
470      End If

               
480           LogText ("PromptCreditCardEntry Unsuccessfull")
                     
490           Customers.Command13.Value = True
500           Customers.Command21.Value = True
510           Customers.CmdClear.Value = True
520            Customers.CmdSale3.Value = True

530            LogText ("XCDebitPurchase Unsuccessfull - " + ErrorMsg)
                 
         
540            Customers.Command13.Value = True
550            Customers.Command21.Value = True
560             Customers.CmdClear.Value = True
570               Customers.CmdSale3.Value = True
580                 Command8_Click
590                    pin.Close (ccTransact.hwnd)
600                         Unload Me


to


460    else

               
480           LogText ("PromptCreditCardEntry Unsuccessfull")
                     
490           Customers.Command13.Value = True
500           Customers.Command21.Value = True
510           Customers.CmdClear.Value = True
520            Customers.CmdSale3.Value = True

530            LogText ("XCDebitPurchase Unsuccessfull - " + ErrorMsg)
                 
         
540            Customers.Command13.Value = True
550            Customers.Command21.Value = True
560             Customers.CmdClear.Value = True
570               Customers.CmdSale3.Value = True
580                 Command8_Click
590                    pin.Close (ccTransact.hwnd)
600                         Unload Me
610 end if
620 end if
0
 
mindserveAuthor Commented:
I get an invalid procedure code error message and it runs to

400                If (ApprovalCode) = True Then
0
 
samstarkeyCommented:
Can you run the following and tell me what happens??


Private Sub mnuDebitPurchase_Click()

Dim PINBlock As String
Dim PINKey As String
Dim sTmp As String
Dim Dtmp As String
 
txtLog = vbNullString
If txtAmt.Text = "" Then txtAmt.Text = "0.00"

If TxtTips.Text = "" Then TxtTips.Text = "0.00"

If txtFields(0).Text = vbNullString Then
    Call MsgBox("You must choose Debit Purchase payment type from the drop down " _
            & vbCrLf & "box before you can complete the transaction." _
            , vbExclamation, "Debit Purchase Payment Type")
    Exit Sub
End If

If txtFields(0).Text = "CreditCard" Then ' <<< whats this for???
End If

If txtFields(0).Text <> "DebitCard" Then
    Call MsgBox("You have changed payment types. " _
                   & vbCrLf & "The drop down box shows a different " _
                   & vbCrLf & "payment type than the one you are now trying to process. " _
                   & vbCrLf & "If you wish to change the payment type, click the C button " _
                   & vbCrLf & "and then change the payment type and proceed with processing." _
                   , vbCritical, "Payment Type Error on Drop Down Box")
       
    Exit Sub
End If
                   
LogStartFunction ("XCDebitPurchase")
If (GetDebitSwipe(Track2, CC)) Then
    nRes = pin.PromptDebitPIN(ccTransact.hWnd, CC, txtAmt.Text, PINBlock, PINKey)
        If (nRes = 0) Then
            Call DisplayProcessingMessage
            Call XCTran.XCDebitPurchase(ccTransact.hWnd, txtTranFolder.Text, "Debit Card Purchase Information ", _
            True, True, txtClerk.Text, txtRcpt.Text, txtAmt.Text, _
            "0.00", txtAmt.Text, CC, Track2, PINBlock, PINKey, ErrorMsg, approvalcode)
            Call ShowLogo
            LogText ("ApprovalCode = " + approvalcode)
            LogText ("CC = " + CCTypeName)
            sTmp = CC
            Mid(sTmp, 1, 12) = "XXXXXXXXXXXX"
            LogText ("CC = " + sTmp)
            LogText ("TicketID= " + txtRcpt.Text)
            LogText (Employee = " " + txtClerk.Text)
            LogText ("Tip Amount= " + FormatCurrency(CCur(TxtTips)))
            LogText ("Ticket Amount= " + Customers.txtticketfields(9).Text)
            LogText ("Total Amount(Plus Tip)= " + FormatCurrency(CCur(txtAmt)))
            Dtmp = Format$(Now, "Short Date")
            LogText ("Date= " + Dtmp)
        Else
            MsgBox (pin.GetResultMessage(nRes))
           
            If approvalcode = True Then
           
                MsgBox "Approvalcode is true", , "This is a debug"
                'Call PrintLayout6
            Else
                MsgBox "Approvalcode is false", , "This is a debug"
                Exit Sub
            End If
        End If
End If

               
LogText ("PromptCreditCardEntry Unsuccessfull")
                     
Customers.Command13.Value = True
Customers.Command21.Value = True
Customers.CmdClear.Value = True
Customers.CmdSale3.Value = True

LogText ("XCDebitPurchase Unsuccessfull - " + ErrorMsg)
                 
         
Customers.Command13.Value = True
Customers.Command21.Value = True
Customers.CmdClear.Value = True
Customers.CmdSale3.Value = True
Command8_Click
pin.Close (ccTransact.hWnd)
Unload Me
           
End Sub
0
 
mindserveAuthor Commented:
The same thing happens as with the original code. It prints out some of the ticket information and says the same thing at the end for the print out as it did originally.
Which is:
Promptcreditcardentry unsuccessfull
XCdebitpurchase unsuccessfull

This is the code from the credit purchase which works perfectly. Note how the else end if statment block is around the logtext. This is what I need for the debit purchase but cannot get the block to work at all.... The code I have allows it to run through both logtext's but does not stop it. The code you posted does the same. Results were the same, nothing changed
--------------------------------------------------
         Else
                 
           LogText ("XCPurchase Unsuccessfull - " + ErrorMsg)

    Customers.Command16.Value = True
 Customers.Command21.Value = True
 Customers.CmdClear.Value = True
 Customers.CmdSale3.Value = True
  Command8_Click
pin.Close (ccTransact.hwnd)
   Unload Me
 End If

'//////////////////////////////////////////
  Else
               
  LogText ("PromptCreditCardEntry Unsuccessfull")

 Customers.Command16.Value = True
 Customers.Command21.Value = True
Customers.CmdClear.Value = True
  Customers.CmdSale3.Value = True
 pin.Close (ccTransact.hwnd)
  Unload Me
  End If
*********************************
0
 
mindserveAuthor Commented:
raising the points,,, this must be harder than I thought it would be.
0
 
samstarkeyCommented:
This is hard to debug as you have alot of procedure calls which I dont know what they do.

In the code i posted you should have got a message box apper as I placed this in the If Else statement you said you were having the problem with.  Are you sure the problem doesn't lie with one of the procedure calls?
0
 
mindserveAuthor Commented:
Didn't get a message box at all. The procedure calls would be the same except for one:

 Else
MsgBox (pin.GetResultMessage(nRes))
  but even with the end if and removing this call, I still can't get the syntax. Since it is just a msgbox , it should not affect the else statement.
         
0
 
dancebertCommented:
I cringe when I see code like this. If I have to maintain it the first thing I do is print it out and draw lines to connect all the IF - ELSE - END IF blocks.  I then copy and append the IF statement as a comment to the associated Else and End Ifs.

If <condition 1> then
    ..
    .. many lines of code
    ..
else    '' If <condition 1> then
    ..
    .. many lines of code
    ..
end if  '' If <condition 1> then

If there are several levels of nested IFs, it makes it a LOT easier to read.
0
 
mindserveAuthor Commented:
Shouldn't every else end with an end if block?
I mapped it out too...I get an Else without end if error message, but can't find the other end if...This is not my code btw, it's Xcharge's SDK code... All I am trying to do is figure out how to stop the else on the logtext for the Debit portion as it is in the Credit portion, which does work... and it's driving me nutz!

Else
                 
           LogText ("XCPurchase Unsuccessfull - " + ErrorMsg)
'These commands just clear textboxes on a customers screen, passed back from the CCtransact form. Otherwise they do nothing else.
    Customers.Command16.Value = True
 Customers.Command21.Value = True
 Customers.CmdClear.Value = True
 Customers.CmdSale3.Value = True
  Command8_Click
pin.Close (ccTransact.hwnd)
   Unload Me
 End If

0
 
mindserveAuthor Commented:
No one seems to have any answers to this one. Think I will have to ask to have it closed.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now