Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Stickey Variables?

Posted on 2001-06-13
9
Medium Priority
?
170 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 200 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

618 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