473,396 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

New, Open, Save, Save As, Close

Hi VB fans

I'm working on a relatively large project in VB6 with about a dozen
forms, including graphs, labels, text boxes, etc. The software itself
is actually a flow simulator with more or less complex technical
calculations, several input variables. I would like to equipp the
starting panel with the usual New, Open, Save, Save As, Close etc.
menus (like in Excel, or Word, etc.) What is the best way to
accomplish Save, or Save As? Should be the variables behind the entry
fields be written to a binary file, or can the forms be saved directly
with all the controls and it contents to a file, or is there any other
solution? How professionals do it?

Any advice is highly appreciated. Tx in advance

Andras
Jul 17 '05 #1
4 24998

"Andras Gilicz" <ag*****@chello.hu> wrote in message
news:72**************************@posting.google.c om...
| Hi VB fans
|
| I'm working on a relatively large project in VB6 with about a dozen
| forms, including graphs, labels, text boxes, etc. The software itself
| is actually a flow simulator with more or less complex technical
| calculations, several input variables. I would like to equipp the
| starting panel with the usual New, Open, Save, Save As, Close etc.
| menus (like in Excel, or Word, etc.) What is the best way to
| accomplish Save, or Save As? Should be the variables behind the entry
| fields be written to a binary file, or can the forms be saved directly
| with all the controls and it contents to a file, or is there any other
| solution? How professionals do it?
|

I would certainly save the values of the entry variables, not make an
attempt to save the forms themselves.

You can choose an ordinary file, or even use an Access database if it
suits you.

For a file, I would write all variables in plain text, not in actual
binary. It makes debugging, etc. much easier. Using Input# and Write# to
read and write the file will produce this result, and take care of the
formatting. (Write# does not handle strings with embedded quotes,
however).


Jul 17 '05 #2
Andras Gilicz wrote:
Hi VB fans

I'm working on a relatively large project in VB6 with about a dozen
forms, including graphs, labels, text boxes, etc. The software itself
is actually a flow simulator with more or less complex technical
calculations, several input variables. I would like to equipp the
starting panel with the usual New, Open, Save, Save As, Close etc.
menus (like in Excel, or Word, etc.) What is the best way to
accomplish Save, or Save As? Should be the variables behind the entry
fields be written to a binary file, or can the forms be saved directly
with all the controls and it contents to a file, or is there any other
solution? How professionals do it?

Any advice is highly appreciated. Tx in advance

Andras

G'day Andras,
search the Help file for "Using Menus in Your Application" this topic is
well documened there.
and/or
Go to >Tools >Menu Editor
cheers,
build
Jul 17 '05 #3
build <bu*****@datafast.net.au> wrote in message news:<41******@news.alphalink.com.au>...
Andras Gilicz wrote:
Hi VB fans

I'm working on a relatively large project in VB6 with about a dozen
forms, including graphs, labels, text boxes, etc. The software itself
is actually a flow simulator with more or less complex technical
calculations, several input variables. I would like to equipp the
starting panel with the usual New, Open, Save, Save As, Close etc.
menus (like in Excel, or Word, etc.) What is the best way to
accomplish Save, or Save As? Should be the variables behind the entry
fields be written to a binary file, or can the forms be saved directly
with all the controls and it contents to a file, or is there any other
solution? How professionals do it?

Any advice is highly appreciated. Tx in advance

Andras

G'day Andras,
search the Help file for "Using Menus in Your Application" this topic is
well documened there.
and/or
Go to >Tools >Menu Editor
cheers,
build


Ok, tx build, I have no problems with menus, I've got a lot of them,
but the question was which code to put behind the Save or Save As
menus, i.e. how professionally the entry field variables on several
forms can be saved up and reloaded if needed later. How Excel does it
for e.g.? Steve's solution above is sympathetic, tx Steve!

regards

Andras
Jul 17 '05 #4
Andras,

One technique that I've used in the past is to use an Access database (coded
with ADO in VB), and then put the name of each field in it's corresponding
input control's Tag property. You can then use a For Each Control type of
loop to easily get the control's value and store it to the field named in
it's tag property. The same process works in reverse to load a previously
saved group of input values.

To take this a step further, if you have combo boxes with a list of values
to select from, you can write a generic routine to load the lists and then
use a text file to store all the values for each listbox. This makes adding
or removing an item from a listbox a simple matter of editing the text file.
Again, use the tag property to correlate the control with it's list of
values in the file.

Here are some routines I wrote a few years ago to do this. These are copied
straight from my projects, so you'll need to tweak them, but you'll get the
idea. (This project stored engineering design data, so records are loaded
and stored based on a "Design ID" field. It's just an Access AutoNumber
field.

(InputDatabase is a global variable that points to the Access database)

*****************

Public Sub LoadDesignFromDB(Activeform As Form, DesignID As Long)

' This routine loads the contents of all controls on the main form that
contain a tag value
' from the selected record in the design database

Dim CurrentControl As Control
Dim f As ADODB.Field
Dim Msg As String
Dim dbInputDatabase As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SQLStatement As String

On Error GoTo ErrHandler

SQLStatement = "SELECT * FROM InputData WHERE DesignID = " & DesignID

Screen.MousePointer = vbHourglass

dbInputDatabase.Open (ProviderString & ";Data Source=" & InputDatabase)
rs.Open SQLStatement, dbInputDatabase, adOpenKeyset, adLockOptimistic

For Each f In rs.Fields
For Each CurrentControl In Activeform.Controls
If CurrentControl.Tag = f.Name Then
If f.Type = adBoolean Then
CurrentControl = Abs(f.Value)
Else
CurrentControl = f.Value
End If
End If
Next
Next

rs.Close
dbInputDatabase.Close
Set rs = Nothing
Set dbInputDatabase = Nothing

Screen.MousePointer = vbDefault

MsgBox "Design data loaded sucessfully", vbOKOnly + vbInformation, "Load
Design Data"

Exit Sub

ErrHandler:

Screen.MousePointer = vbDefault
Select Case Err
Case Else
Msg = "Unable to load design data. Error Number: " & Err.Number &
vbCrLf & Err.Description
End Select
MsgBox Msg, vbCritical + vbOKOnly, "Load Design Data"

On Error Resume Next

rs.Close
dbInputDatabase.Close
Set rs = Nothing
Set dbInputDatabase = Nothing

End Sub

*****************

Public Sub SaveDesignToDB(Activeform As Form, SaveMode As String)

' This routine saves the contents of all controls on the form that
contain a tag value
' to a the Design database

Dim Msg As String
Dim Style As Integer
Dim Title As String
Dim Response As Integer

Dim CurrentControl As Control
Dim ControlTag As String

Dim dbInputDatabase As New ADODB.Connection
Dim rs As New ADODB.Recordset

Dim SQLStatement As String

On Error GoTo ErrHandler

' If DesignID has been reset, save as new; otherwise, update current
record
If SaveMode = "NEW" Then
Msg = "Save current data as new design in database?"
SQLStatement = "InputData"
Else
Msg = "Overwrite current design in database?"
SQLStatement = "SELECT * FROM InputData WHERE DesignID = " &
CurrentDesignID & ""
End If

Style = vbQuestion + vbOKCancel '+ vbDefaultButton2
Title = "Save Design Data"
Response = MsgBox(Msg, Style, Title)

If Response <> vbOK Then
Exit Sub
End If

Screen.MousePointer = vbHourglass

dbInputDatabase.Open (ProviderString & ";Data Source=" & InputDatabase)
rs.Open SQLStatement, dbInputDatabase, adOpenKeyset, adLockOptimistic

If SaveMode = "NEW" Then
rs.AddNew
End If

For Each CurrentControl In Activeform.Controls
ControlTag = CurrentControl.Tag
If ControlTag <> "" Then
rs.Fields(ControlTag) = CurrentControl
End If
Next
rs.Update
rs.MoveFirst

MsgBox "Design data saved successfully.", vbOKOnly, "Save Design Data"

rs.Close
dbInputDatabase.Close
Set rs = Nothing
Set dbInputDatabase = Nothing

Screen.MousePointer = vbDefault

Exit Sub

ErrHandler:

Screen.MousePointer = vbDefault
Select Case Err
Case Else
Msg = "Unable to save design data. Error Number: " & Err.Number &
vbCrLf & Err.Description
End Select
MsgBox Msg, vbCritical + vbOKOnly, "Save Design Data"

On Error Resume Next

rs.Close
dbInputDatabase.Close
Set rs = Nothing
Set dbInputDatabase = Nothing

End Sub

*****************

Public Sub LoadLists(Activeform As Form, ListFileName As String)

' This routine loads each combo box from the "ListData.dat" file
' in the App.Path\config directory. This is a very fast, easy way
' of maintaining combo lists.

' This function works by searching the main form for a control with an
' assigned tag property that matches a tag entered in the listdata file.
' If one is found, it's list is populated with the values following the
tag
' entry.

Dim FileHandle As Integer
Dim FileName As String
Dim TextInput As String
Dim ItemToAdd As String
Dim Counter As Integer
Dim Msg As String

Dim ControlTag As String
Dim DefaultListIndex As Integer
Dim CurrentControl As Control

On Error GoTo ErrHandler

FileHandle = FreeFile
FileName = App.Path & "\config\ListData.dat"

' Load lists for combo boxes
Open FileName For Input As #1
Do Until EOF(FileHandle)
Line Input #FileHandle, TextInput
If UCase(TextInput) = "CONTROL" Then
ItemToAdd = ""
Input #FileHandle, ControlTag, DefaultListIndex
For Each CurrentControl In Activeform.Controls
If CurrentControl.Tag = ControlTag Then
Do Until UCase(ItemToAdd) = "EOL"
Line Input #FileHandle, ItemToAdd
If UCase(ItemToAdd) = "EOL" Then Exit Do
CurrentControl.AddItem ItemToAdd
Loop
CurrentControl.ListIndex = DefaultListIndex
Exit For
End If
Next
End If
Loop
Close #FileHandle

Exit Sub

ErrHandler:

Close #FileHandle
Screen.MousePointer = vbDefault
Select Case Err
Case Else
Msg = "Error in ListData.dat file. " & Err.Description & "."
End Select
MsgBox Msg, vbCritical + vbOKOnly, "Load List Controls"

End Sub

*****************

Sample ListData.dat file (greatly shortened):

*****************

Combo/List control data file for Visual Basic projects.
Only the lines following the word "CONTROL" and up to "EOL"
are read. The format is as follows:

CONTROL
control tag, default list index
list data 1
list data 2
....
....
EOL

-----------------------------------------------

----State----
CONTROL
"State",0
AL
AK
AZ
AR
CA
WV
WI
WY
EOL

----Nominal OD----
CONTROL
"NominalOD",18
3.00
4.00
4.13
4.25
48.00
EOL

----Bore Dia----
CONTROL
"BoreDia",5
1.13
1.50
2.00
EOL

*****************

Enjoy!

Calan


Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin Lucas-Smith | last post by:
I am trying to use PHP's COM support to open a URL from within MS Word then save the document. I am using PHP5.0.3/Apache2/WindowsXP. phpinfo() confirms that COM support is enabled. ...
3
by: Newbie | last post by:
I am trying to get the save/open dialog figured out. I am able open the save dialog but when I put in a file name (whatever.txt) and save the file does save with the name but it is blank. Below...
1
by: Andrew | last post by:
I'm adding this as it to me a while to figure out all the pieces to be able to do this without using Microsoft.Office.Interop which caused me problems on the web-server. Streaming is the easy...
2
by: BusyBoy | last post by:
Hi All I am using two aspx pages The first aspx page loads the second page in a popup window. The second aspx page has no html and I change its content type to download a particular file. ...
4
by: Bob Bedford | last post by:
Hi all, I'm stuck with some php code that runs out of time limit. This is due to a long XML file process that has to save pictures on the disk. What I've now: - read XML file - parse XML...
3
by: kev | last post by:
Hi folks, I have a form for registration (frmRegistration) whereby i have two buttons. One is Save which saves record using the OnClick property. I used wizard to create the save button. The...
1
by: msanger | last post by:
Hi, I have several excel sheets in Office 2007, which has all kinds of standard calculations, and a consolidated Excel Sheet with totals and rollup of all the other excel files. The issue I am...
0
by: walkabout | last post by:
A shared document is left open frequently so need a script that detects 5 minutes inactivity and saves changes and closes document. thanks. could mod the following but needs to save changes and...
0
by: Ang | last post by:
Hi, I want to open a word file on background instead of showing the process on client's screen. And then do mailmerge, after that allow user to saveas. (user simply click the button and IE will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.