5 Replies - 987 Views - Last Post: 10 February 2011 - 02:27 PM Rate Topic: -----

#1 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 394
  • Joined: 04-January 11

Problem with my if...else condition First Code won't execute when

Posted 10 February 2011 - 01:07 PM

I have a form called LogIn.vb which has no errors.
After log-in, it opens the MainForm.vb which IsMDIContainer property is set to true.
From the MainMenu, it opens a child form called Assure_Benefits.vb
So far no problem up to this point.

When Assure_Benefits.vb loads, it displays 2 DataGridViews with datasourses from my 2 tables in my database.

There is still no problem with the loading.

Now, to show the difference between different user types, I only allow the admin to edit the DataGrid. SO I set the readonly property to true when UserType = "user".

I have no problem doing that.

My problem is I want to add some codes besides the readonly being set to true and false but other codes are not executed and the program does not display any errors at all. i tried to add messageboxes on the if and else conditions to try if added codes will work but even the messagebox does not appear though the codes next to it are properly executed.

When my Assure_Benefits.vb loads I call for the subroutine below.

    Private Sub SetControlProperties()
        If LogIn.UserType = "admin" Then
            MessageBox.Show("Yes") 'This line is not executed
            grid_LivingBenefits.ReadOnly = False 'Works perfectly fine 
            grid_DeathBenefits.ReadOnly = False 'Works perfectly fine 
        ElseIf LogIn.UserType = "user" Then
            MessageBox.Show("No") 'This line is not executed
            grid_LivingBenefits.ReadOnly = True 'Works perfectly fine 
            grid_DeathBenefits.ReadOnly = True 'Works perfectly fine 
        End If
    End Sub


I can't seem to understand why the first code is not executed when the next codes works fine.

This post has been edited by modi123_1: 10 February 2011 - 01:29 PM
Reason for edit:: please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Problem with my if...else condition First Code won't execute when

#2 Shadar  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 157
  • Joined: 26-May 09

Re: Problem with my if...else condition First Code won't execute when

Posted 10 February 2011 - 01:12 PM

Try putting a line in to see what exactly the "LogIn.UserType" is set to when the sub starts.
Put as first line before if statement.
msgbox (LogIn.UserType)


Edit: If I rememember correctly, the default setting is for binary comparison and therefore Admin in not the same as admin.

This post has been edited by Shadar: 10 February 2011 - 01:25 PM

Was This Post Helpful? 1
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Problem with my if...else condition First Code won't execute when

Posted 10 February 2011 - 01:13 PM

put a breakpoint on the If Login.UserType line and then step through the code to ensure that you are indeed hitting that code segment. Just click on the line and press f9 then run the code and it should stop when it hits that line. At that point you can use Debug|Step Into to see how the code is processing.

Edit:
Good Point Shadar. In case it doesn't equal either one

This post has been edited by CharlieMay: 10 February 2011 - 01:14 PM

Was This Post Helpful? 0
  • +
  • -

#4 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 394
  • Joined: 04-January 11

Re: Problem with my if...else condition First Code won't execute when

Posted 10 February 2011 - 02:08 PM

Thanks. I guess I forgot about the casing. :rolleyes:

Now to change the messagebox I placed in the

if usertype = "admin"

I actually want to make two columns of my DataGridView set to readonly. I have 8 columns in my DatagridView. Its readonly property is set to false but there are two columns in which even the admin shouldn't input data.

I tried using the following codes to see if it'll work in he first column...

Public Sub SetSomeColumnsReadOnly()

Dim RowCount As Integer = LivingBenefitsTable.Rows.Count

Dim RowCTR As Integer

   For RowCTR = 0 To RowCount - 1
      grid_LivingBenefits.CurrentCell = 
      grid_LivingBenefits.Item(0, RowCTR)
          grid_LivingBenefits.CurrentCell.ReadOnly = True
            
   Next

End Sub


It doesn't work though. Do you have any idea how to do it?

This post has been edited by AdamSpeight2008: 10 February 2011 - 02:13 PM
Reason for edit:: Please use the codetags.

Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Problem with my if...else condition First Code won't execute when

Posted 10 February 2011 - 02:17 PM

You can set an entire column as readonly using the index number
grid_livingBenefits.Columns(2).ReadOnly = True


Of course 2 would be changed to the column index you want to set as read only.
Was This Post Helpful? 2
  • +
  • -

#6 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 394
  • Joined: 04-January 11

Re: Problem with my if...else condition First Code won't execute when

Posted 10 February 2011 - 02:27 PM

Thanks for that. I have been searching the web for hours but I can't comprehend the lengthy looping they suggest.

And here you go with just a line to solve my problem.

Big thanks really.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1