Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

Comparing a Variable with 'text'

hey guys, this is simple question im sure, but i cant figure why this wont work:

ticketStatus = Me.CheckInTicketList.CurrentRow.Cells(Me.Status.Index).Value()
        If ticketStatus = "active" Then
           code
        Else : MessageBox.Show("There are No Ticket Under this PNR to check In!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        Else
            MessageBox.Show("Error - This Ticket is not Active, this ticket might already been used or is considered invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
        End If

it keeps give the messagebox. why? maybe im to used to pascal?
0
aborg85
Asked:
aborg85
  • 4
  • 4
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
Hi aborg85,

you have 1 IF, 2 ELSE, 2 ENDIF! That doesn't match! The syntax is:

 If ticketStatus = "active" Then
           code
 Else
        MessageBox.Show("There are No Ticket Under this PNR to check In!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If


Cheers!
0
 
aborg85Author Commented:
Sry i did a mistake when copying and pasteing

Dim ticketStatus As String
ticketStatus = Me.CheckInTicketList.CurrentRow.Cells(Me.Status.Index).Value()
        If ticketStatus = "active" Then
            Dim Name As String
            Dim Surname As String

            If Me.CheckInTicketList.RowCount > 0 Then
                code
            Else : MessageBox.Show("There are No Ticket Under this PNR to check In!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        Else
            MessageBox.Show("Error - This Ticket is not Active, this ticket might already been used or is considered invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
        End If
    End Sub
0
 
Éric MoreauSenior .Net ConsultantCommented:
Which messagebox do you always see? what is the value of ticketStatus? Notice that the comparison is case sensitive.

also change:
           Else : MessageBox.Show("There are No Ticket Under this PNR to check In!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)

to:
           Else
                MessageBox.Show("There are No Ticket Under this PNR to check In!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
aborg85Author Commented:
i always see this:

MessageBox.Show("Error - This Ticket is not Active, this ticket might already been used or is considered invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)

ticketstatus is a part of datagridview and is textboxcolumn.

I ve also arranged this piece as  u suggested,  Else : MessageBox.Show("There are No Ticket Under this PNR to check In!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
0
 
Éric MoreauSenior .Net ConsultantCommented:
and what is the value of ticketStatus ? You will find the exact value like this:

ticketStatus = Me.CheckInTicketList.CurrentRow.Cells(Me.Status.Index).Value()
message box.show(">>" & ticketStatus & "<<")
        If ticketStatus = "active" Then

rember that the comparison is case sensitive.
0
 
aborg85Author Commented:
infact its giving me "Active  ", and changed  the code to

if ticketstatus = "Active  " then

but still same messagebox
0
 
Éric MoreauSenior .Net ConsultantCommented:
what do you get if you do :
message box.show(">>" & ticketStatus.trim.toupper & "<<")

and

 If ticketStatus.trim.toupper = "ACTIVE" Then
0
 
aborg85Author Commented:
emoreau, YOUR A STAR!

Thanks!
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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