1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

VB Help

Discussion in 'HTML, Graphics & Programming' started by DJMK4, 25 Feb 2006.

  1. DJMK4

    Capodecina

    Joined: 1 Dec 2004

    Posts: 21,939

    Location: S.Wales cardiff

    iv been doing a project where iv created a simple VB front end and connected it to an Access database but now things are going slightly out of my reach

    i havent done any vb or C++ for quite sometime so it seems im looking at it the wrong way

    basically my current task is as follows. Iv created a Login form to the program, the user enters a username an password and it was fine. But now it needs to be more detailed. So iv added 'user group' where the user selects whether they are Admin or User to which the program determines access rights e.g. some buttons will be disabled under user


    so iv thought about it and i think i need a few global variables in each of the other forms? which is passing the values throughout the program?

    could anyone please help me with what i need to write?
     
  2. sfx

    Hitman

    Joined: 13 Dec 2004

    Posts: 926

    There maybe better ways but this is a really simple way and will probably do what you are after.

    In a Module put...
    Code:
    Public strUsername As String
    Public strGroup As String
    Then in you button click event handler (could be any handler depends what you are doing) add something like this...
    Code:
    Private Sub Command1_Click()
        Select Case strGroup
            Case "Admin"
                Load Form1
                Form1.Show
            Case "User"
                MsgBox "Sorry you do not have the required permissions to access this form!", vbExclamation, "You Application name"
        End Select
    End Sub
    So basically what is happening is the user logs in and if it is successful you will assign the username and group to required variable. So if it is an Admin that has logged in then strGroup will = "Admin". Upon clicking button one you check for the group that is logged in, if it is an Admin then you show then the form otherwise display a message box.

    You could do other things to like if it is just a user logged in, instead of not allowing them access to the form just disable some controls etc...

    Hope this helps,

    sfx
     
  3. acidstrato

    Associate

    Joined: 24 Feb 2006

    Posts: 3

    hi it was actually me doing the vb but i was awaiting account activation

    iv done it as above and it works great :) was abit hard working out what was needed in the login form but i got there in the end and my login is working just the way i wanted it to
    thanks for ** input
     
  4. acidstrato

    Associate

    Joined: 24 Feb 2006

    Posts: 3

    need more help :(

    can anyone help me with the code needed to read usernames & passwords from a text file??

    and also perhaps how i could encrypt that file...without 3rd party software
     
  5. acidstrato

    Associate

    Joined: 24 Feb 2006

    Posts: 3

    found some code and have got it working thanks anyway
     
  6. sfx

    Hitman

    Joined: 13 Dec 2004

    Posts: 926

    If you are already using a Database I would store the Username and Password in the Database and password protect the Database.

    sfx