Solved

Stickey Variables?

Posted on 2001-06-13
9
167 Views
Last Modified: 2010-05-02
Ok..this is my last of the points...

Desining program that will be used by multiple users to automate word.  Most of the varibles will change from use to use (its a will program, where the attorney inputs data from client)

WOUld like to have method for the attorney to enter his personal info (Name, etc) so it will remain in the program for his use (i guess like a constant) each time he restarts the program.   But if another attny needs to use, he would be able to change this variable...(and agian it would remain constant until changed)

This is my first visual basic program, and any help is appreciated

thanks!
0
Comment
Question by:phred_the_cat
[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
9 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 50 total points
ID: 6187763
Create a form for settings.  Add text fields and OK/Cancel buttons.  The OK button does this:

SaveSetting "NameofProg", "PersonalSettings", "Name", txtName
SaveSetting "NameofProg", "PersonalSettings", "Phone", txtPhone

etc.

Then in the main program, use GetSetting to retrieve the info into variables

strName = GetSetting("NameofProg", "PersonalSettings", "Name")
0
 
LVL 4

Expert Comment

by:beckingh
ID: 6187772
Many ways to do it.  The most accepted would be to store it in the registry.  Easiest is probably storing it in an INI file.

The INI file can be loaded at startup and written to at shutdown (or when a value changes).



Here's some sample code:



Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

' *****************************************************************************************************
'  SUBROUTINE       :   GetMyProfileString
'  DESCRIPTION      :   Returns a value from an INI file.
'  INPUTS           :   ByVal lpApplicationName - Name of the application
'                   :   ByVal lpKeyName         - Name of the key to look up in the INI File
'                   :   ByVal lpDefault         - Default value if no value found
'                   :   ByRef lpReturnedString  - String returned from the ini file (OUTPUT actually)
'                   :   ByVal nSize             - Number of characters to retrieve (usually 255)
'                   :   ByVal lpFileName        - Filename of the ini file. (usually App.Path & "\" & name)
'  OUTPUTS          :   RetVal                  - String returned from the ini file
'  REVISIONS        :   1.0.0 CB 04/01/2001 Original version.
' *****************************************************************************************************
Public Function GetMyProfileString(ByVal lpApplicationName As String, ByVal lpKeyName As String, _
                  ByVal lpDefault As String, ByRef lpReturnedString As String, ByVal nSize As Integer, _
                   ByVal lpFileName As String) As String
   
    Dim rc As Integer
   
    lpReturnedString = String$(255, 32)
    rc = GetPrivateProfileString(lpApplicationName, lpKeyName, lpDefault, lpReturnedString, nSize, lpFileName)
    lpReturnedString = Trim$(Left$(lpReturnedString, rc))
   
    GetMyProfileString = lpReturnedString
    Exit Function

End Function


Call the function like this:

Public Sub Main()
   Dim lsValue as string

   lsValue= GetMyProfileString("Settings", "Value", "", lsValue, 255, App.Path & "\MyINIFile.ini")
   

End Sub

Ini file looks like:

[Settings]
Value=MYVALUE!
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6187776
Remember to check for valid data before saving it or using it in the program.  The last field of GetSetting is a default that you can use to put in a default in case no setting has ever been saved.

strName = GetSetting("NameofProg", "PersonalSettings", "Name", "John Smith")
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 4

Expert Comment

by:beckingh
ID: 6187778
PaulHews just showed you how to store it in the registry...  which as i said is probably the more accepted way of doing it.

Either way'll work though.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6187794
>Either way'll work though.

Agreed.  If you ever need to edit the setting outside of the program an INI file is the way to go (using notepad is so much less threatening for your users than regedit.)
0
 
LVL 1

Expert Comment

by:alaplume
ID: 6188777
Try using SetSetting to save the registry.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6190035
One comment to add to Paul's suggestion. This in fact works better than you would imagine: the SaveSetting/GetSetting functions work with the HKEY_CURRENT_USER Hive of the registry, this means that if you have different users logging in to the machine then the values that you store will be stored for these specific users and will automatically be different depending on who is logged into the computer.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7136069
Hi phred_the_cat@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept PaulHews's comment(s) as an answer.

phred_the_cat@devx, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7168407
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

690 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