Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

saving settings in visual basic

Posted on 2003-11-13
5
Medium Priority
?
459 Views
Last Modified: 2010-04-17
ello all!

again, its that damn IT coursework that just wont sort itself out! im sooo close, but i underestimated one lil thing...

basically ive got a login system. usernames are entered into a listbox (cunningly named lstUser) by an administrator. students can then log on to the program and take tests, the results of which are sent to the tutors email address so they can check the students progress.

i need to learn how to save settings so that the names in the listbox are remembered each time the program is opened. pretty pointless if the are lost each time the administrator closes the program!

in the same way, access to the admin section of the program is done via a password. this password can be changed (don't know why they would want to change it, but i thought it made a cool USP)

i need a way to save the settings so that this password is remembered, in much the same way as the data in the list box is entered. if it makes any difference, the password is stored in a label on the admin section, the names being in a listbox (as mentioned).

if its possible, would some kind person please give me a crash course in saving settings? code is great, but it would also help if it was fully explained (how and why it works) - im not too quick im afraid (damn welsh heritage) =)

thankee kindly all

dave
xXxx

ps. sorry its only 115 points - its all ive got =(
0
Comment
Question by:d-richardson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 7

Accepted Solution

by:
wsteegmans earned 345 total points
ID: 9743933
Where is your VB-Program located? On a shared folder ... so the students can start it form this shared folder? Or is every program (EXE) installed on each computer?

If I understand your question, you want that all the usernames entered by the Administrator are saved ... So, when a student starts the program, he can pick his username and log in ... Am I right?

For this purpose, you can use a database (for example Access or SQL-Server) where you store all your info (usernames, passwords, ...) or you can create a textfile where you save all your data. But I prefer the database.

Tutorial about VB and DB-programming (Part I through IV)
http://www.developer.com/net/vb/article.php/10926_1538901_1
http://www.developer.com/net/vb/article.php/1538911
http://www.developer.com/net/vb/article.php/1538921
http://www.developer.com/net/vb/article.php/1538931

If you want that everytime the program is started, the last entered studentname is shown (so your program remembers the last user), you can store it in the Windows Registry.
A nice tutorial about the Windows Registry and using it in VB:
http://www.devarticles.com/art/1/294
0
 

Author Comment

by:d-richardson
ID: 9743984
the program will eventually be in a shared folder.

If I understand your question, you want that all the usernames entered by the Administrator are saved ... So, when a student starts the program, he can pick his username and log in ... Am I right?

-spot on!

the article about the windows registry looks to be what im looking for. il have a play around, see what happens:) thank you for your help

dave

0
 
LVL 2

Expert Comment

by:Discofish
ID: 9744007
There are about 1,000 ways to do this - and you may want to consider using a database or XML if you want to maintain data about the different students.  The easiest way to solve this problem is to store the user names and passwords in a text file.
For example, you've got a file called "users.txt" in your application directory with the following lines:

Lisa
John
Billy
Marvin

You could populate the listbox like so:

Private Sub Form_Load()

Dim UserFile As Integer ' Reference to the file
Dim strUserName As String 'the user name from the file
UserFile = FreeFile       ' Get the first available file
'VB uses numbers to keep track of files

Open App.Path & "\" & "users.txt" For Input As UserFile 'Open the file "users.txt" thats in your program directory

Do While Not EOF(UserFile)
Line Input #UserFile, strUserName
'store the line from the file in strUserName
lstUsers.AddItem (strUserName) ' add the user name to the list
Loop

Close UserFile ' close the file so it can be accessed

End Sub






0
 

Author Comment

by:d-richardson
ID: 9747317
played around with what u suggested. the annotations were great! i actually understand what u mean!

however, the problem would be that if i have a file called "adminPswrd.txt" or something, some bright spark is probably going to think of having a look at it.. then changing it.. much to the annoyance of the tutor. similiarly, if i have a .txt file which contains the students usernames, someone is going to decide to have a laugh.

 being a student myself, i spend a lot of time trying to make the lives of the administrators of my college's IT department difficult! as a result, i know just what sort of treatment my program will recieve and have written it around them. for example, ive taken mesures to ensure that students cant use excel macros to guess the admin password etc.

i think using the windows registry will be my best bet. a friend gave me some code last night that does work:

Private Sub btnSave_Click()


Dim CatStr As String, i As Integer
  Dim allUser, dUser As Integer
 
  allUser = GetAllSettings("administration", "usernames")
 
  If IsArray(allUser) Then
    For dUser = LBound(allUser, 1) To UBound(allUser, 1)
      DeleteSetting "administration", "usernames", allUser(dUser, 0)
    Next
  End If
 
  CatStr = ""
 
  If AdminForm.lstUser.ListCount > 0 Then
    For i = 0 To AdminForm.lstUser.ListCount
      If Trim(AdminForm.lstUser.List(i)) <> "" Then
        SaveSetting "administration", "usernames", "Item_" & i, Trim(AdminForm.lstUser.List(i))
      End If
    Next
  End If
 
 
  End
 



End Sub

Private Sub Form_Load()

  Dim allUser, dUser As Integer
 
   allUser = GetAllSettings("administration", "usernames")
 
  If IsArray(allUser) Then
    For dPswrd = LBound(allUser, 1) To UBound(allUser, 1)
      lstUser.AddItem allUser(dUser, 1)
    Next
  End If

the problem being that i dont properly understand it! i keep playing around, but i cant make head or tails of it. the tutorial suggested in the first response to my question is helping, but still having trouble. any chance i can be a cheeky sod and ask an expert to explain? havnt got any points left to give im afraid, so dont want to waste anyones time

thanks

dave
xXxx

0
 

Author Comment

by:d-richardson
ID: 9747688
yay!!

i figured it all out! its all cool:)

just gotta hope i can access the windows registry on the computers at college... :|

ah well, thank you for all your help everyone. this place is amazing! must confess i dont understand anywhere near half of it, but i intend to persevere

cheers for all the help you've given to a naive programmer such as myself - much appreciated!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question