Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Very simple question from newbie 2

Status
Not open for further replies.

jinxtx

Programmer
Aug 13, 2002
4
0
0
US
Hi Guys, my question is this...
I create a form and add a text box to it.
I set the text property to blank and when the user runs the program I want them to be able to type in whatever they want and be able to save it.
then open it again and change the value if they so wish.
I don't want to use a commondialog1 or save as control, I just want the user to be able to click save in the menu bar
and a msgbox pop up up saying file saved. Is there anyway to do this????
Any help would be greatly appreciated!
Thx,
Jinx
 
holler if you need more help

from MSDN:

Managing Application Settings


In Microsoft Windows 3.1 and earlier versions of Windows, program settings like window positions, files used, and other items were commonly stored in .ini files. In Windows NT, Windows 95, and later versions of Windows these program settings are stored in the system registry.

Visual Basic provides a standard registry location for storing program information for applications created in Visual Basic:

HKEY_CURRENT_USER\Software\VB and VBA Program Settings\appname\section\key

Visual Basic also provides four statements and functions to manipulate the settings stored in your application's registry location.

Function or Statement Description
GetSetting function Retrieves registry settings.
SaveSetting statement Saves or creates registry settings.
GetAllSettings function Returns an array containing multiple registry settings.
DeleteSetting statement Deletes registry settings.


Note To view registry entries, use the Regedit application, included with Windows 95/98 and Windows NT.

To read more about using application settings, see the following topics:

Creating or Saving Application Settings Explains how to save new values for registry keys stored in your application's registry location.


Retrieving Application Settings Explains how to retrieve registry values stored in your application's registry location.


Deleting Application Settings Explains how to delete registry keys, sections, or an application's registry location.

--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.

SaveSetting Statement


Saves or creates an application entry in the application's entry in the Windows registry.

Syntax

SaveSetting appname, section, key, setting

The SaveSetting statement syntax has these named arguments:

Part Description
appname Required. String expression containing the name of the application or project to which the setting applies.
section Required. String expression containing the name of the section where the key setting is being saved.
key Required. String expression containing the name of the key setting being saved.
setting Required. Expression containing the value that key is being set to.


Remarks

An error occurs if the key setting can’t be saved for any reason.


--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.

SaveSetting Statement Example
The following example first uses the SaveSetting statement to make entries in the Windows registry (or .ini file on 16-bit Windows platforms) for the MyApp application, and then uses the DeleteSetting statement to remove them.

' Place some settings in the registry.
SaveSetting appname := "MyApp", section := "Startup", _
key := "Top", setting := 75
SaveSetting "MyApp","Startup", "Left", 50
' Remove section and all its settings from registry.
DeleteSetting "MyApp", "Startup"


--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.

GetSetting Function


Returns a key setting value from an application's entry in the Windows registry.

Syntax

GetSetting(appname, section, key[, default])

The GetSetting function syntax has these named arguments:

Part Description
appname Required. String expression containing the name of the application or project whose key setting is requested.
section Required. String expression containing the name of the section where the key setting is found.
key Required. String expression containing the name of the key setting to return.
default Optional. Expression containing the value to return if no value is set in the key setting. If omitted, default is assumed to be a zero-length string ("").


Remarks

If any of the items named in the GetSetting arguments do not exist, GetSetting returns the value of default.


--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.

GetSetting Function Example
This example first uses the SaveSetting statement to make entries in the Windows registry (or .ini file on 16-bit Windows platforms) for the application specified as appname, and then uses the GetSetting function to display one of the settings. Because the default argument is specified, some value is guaranteed to be returned. Note that section names can't be retrieved with GetSetting. Finally, the DeleteSetting statement removes all the application's entries.

' Variant to hold 2-dimensional array returned by GetSetting.
Dim MySettings As Variant
' Place some settings in the registry.
SaveSetting "MyApp","Startup", "Top", 75
SaveSetting "MyApp","Startup", "Left", 50

Debug.Print GetSetting(appname := "MyApp", section := "Startup", _
key := "Left", default := "25")

DeleteSetting "MyApp", "Startup"
 
Thanks for the quick reply Justin. I'll have to study it a bit and mess around with it but if it works i'll be very greatful.
Thx again,

Jinx
 
how about this... might be easyer thats more for settings.. you wanted liek a multi line textbox? like a text file save... i think.. so here ya go




FileID = FreeFile
Directory$ = "C:\mytextfile.txt"

Open Directory$ for Output as FileID
Input #FileID, Text1
Close FileID






hope this helps :) in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
Ya, UB I tried it but I keep getting "Variable not defined error" I dunno, I'm Going To sleep now now but i'll be working on it tommorow.
Thx again for the help UB,
Jinx
 
here use this...

'saving text from textbox
Dim FileID As Integer
Dim Directory As String

FileID = FreeFile
Directory = "C:\mytextfile.txt"
'change directory to the path/file you want.

Open Directory For Output As FileID
Print #FileID, Text1
Close FileID

MsgBox "Finished Saving!", vbOKOnly



it is because your form must have option explicit in the (general declorations) so you must dim all your variables which helps speed up time sorry i didnt dim them.. but they are in the code above :) have fun :)... to open the file you would use...




'loading the text into the textbox
Dim FileID As Integer
Dim Directory, MyString As String

FileID = FreeFile
Directory = "C:\mytextfile.txt"
'change directory to the path/file you want.

Open Directory For Input As FileID
MyString = Input(LOF(FileID), FileID)
Close #FileID
Text1.Text = MyString


MsgBox "Finished Loading!", vbOKOnly





this will work :) hehe hope you enjoy... can easily be made into a bas sub also .. have fun :) thanks for start btw :) in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
Just use a text file to store the string. So just use the following code (changing names accordingly) and it will work.

Private Sub Form_load()

Dim a As String

Open App.Path & "\String.Text" For Input As #1
Input #1, a
Close #1
Text1.Text = a

End Sub

Private Sub Form_Unload(Cancel As Integer)

Open App.Path & "\String.Text" For Output As #1
Write #1, Text1.Text
Close #1

End Sub
 
I think the real Question here is; or what I believe he is asking is...

Can you store a/any value(s) in a program(?.exe) ?

Hoping to help clear this up...

Mav

"Hacker by Heart"
saenzcorp@hotpop.com
 
Other options include resource files and registry entries. The latter requires use of the API.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top