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


Save the data.

Posted on 1998-12-18
Medium Priority
Last Modified: 2011-09-20
I am learning VB from the manual. Sometimes I do not know the “word” I need to look up to get to the next step. In time I have found what I need, but this one is eluding me. Since I don’t know the word, I will try to explain the problem.
I have created a flexgrid form with preset columns but  rows set at runtime. I have labeled the columns at run time. The grid will be a scoresheet and I can perform the following, although probably not in the best way.
       Get the Players names with an input box to an array and sort that array.
      Get the scores for each round with an input box and place them in the grid.
      Sum the rows for total scores.
      I have created an exe file from this. (my first ever)

      I cannot retain any data between calls to the program. And have been unable, so fa,r to spot the area in the manual that refers to this.  Could you just give me the name of the process or some clue where to look? I am not lazy or I would not have gotten this far, I think.
      As you can see, I’m certainly not any “expert” and it may be that so basic a question as this is out of line with your function.
      If it isn’t, I surely thank you for any clue you can give me.


Question by:arrthur
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

Expert Comment

ID: 1451423

i think the topic you're looking for is global variables.  these are variables declared using "public" or "global" instead of dim when you are using variables for several forms.  or when you're in one form only, you declare your variables right under "option explicit" before you start your events and procedures.


Option Explicit

Dim i as Integer
Dim myStr as String

Private Sub ....
dim m as Integer.....
End Sub

the i declared under option explicit retains its value as you stay in the form, and is usable by all your subroutines in the form, keeping the last value you assign to it.  whereas the value of the m declared inside the private sub is usable only by that subroutine, making other subroutines or events use that variable will cause an error.

that't it;  at least that what i understood from your problem.  hope that helped, do tell me if you need more explanation or if i'm totally off the track.

happy holidays, and good luck!


Expert Comment

ID: 1451424
If you wish to save data to disk between sessions of your application, you have a few options.  You could write the data to a text file or an INI file.  You could also place the data in a database.  The database can be created using VB's data manager and accessed at runtime to retrieve previous data and add new data.


Accepted Solution

jbil earned 200 total points
ID: 1451425
Hi arrthur

Are you by chance trying to save the values in flexgrid to reuse
when you start the app again?

If so there are several options, data base, text file, etc.

Here's Q&D way to get you started.
To save grid. With all selected call a sub that will.............  

Open "c:\grid\" & ".txt" For Append As #1
         Print #1, MSFlexGrid1.Text
         Close #1

'Then to load..........
Open "c:\grid\"  & ".txt" For Input As #1
         Do While Not EOF(1)
            mystr = Input(1, #1)
            MSFlexGrid1.Text = mystr
Close #1

'My need some tweaking, but you get the idea.
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.


Author Comment

ID: 1451426
My thanks to all who answered. It sure feels better not to be all alone. Happy Holiday to all. I am not quite sure I understand your general format yet, in that I seems to have three email transmissions of the same content.      I am most certainly not complaining. Thanks again     Now the next work is up to me and see what can be done.

Author Comment

ID: 1451427
My thanks to all who answered. It sure feels better not to be all alone. Happy Holiday to all. I am not quite sure I understand your general format yet, in that I seems to have three email transmissions of the same content.      I am most certainly not complaining. Thanks again     Now the next work is up to me and see what can be done.
LVL 13

Expert Comment

ID: 1451428
Bought This Question.

Author Comment

ID: 1451429
I have been ill and unable to use the PC and try out some options. Doing better. Hope to be able to try again soon and will then send update on how I did. Thank you for you continued interest.


Author Comment

ID: 1451430
I have not been able to spend much time on my VB quest for awhile,. As I type this I am unsure of what information your site has retained about my questions. So, in brief:

My hope is to create an executable, stand alone file with a score sheet for a game "Mah Jongg" using Flexgrid for the display. The players in our retirement community enjoy having that capability at their yearly tournament. I have been advised that I would do better to work with Excel or some standard spreadsheet.  I do know this and have actually used Excel and Quattro and even Paradox in the past ten or so years. I can't lind anyone who will and can do this for me when I am unavailable.

From my books I also feel I would perhaps do better not using sequential files and creating player and  creating types for the records and fields since the whole thing seems a database type situation. If I have time I will enjoy fiddling with that some day.

As of now I can create the grid and label the columns. I can enter the player names and assign Id numbers. I can post the scores after applying validity checks which I have previously  worked out for use with Excel . I can calculate the total scores for each player.

Writing code for file saving and opening are completely new to me and I am finding it difficult . Here is the code to save, which is  at least 99% an exact copy of the help your "mdougan" kindly provided me with on January 4th. It did not take me long to know that I saved a File 'cause I could see it.

Public Sub Save()
Dim fHandle As Long
Dim I As Long     'row counter
Dim j As Long     'col counter
Dim sHold As String

fHandle = FreeFile

Open "c:\My Documents\MyJongg" & "\Save.dat" For Output As fHandle
  For I = 0 To Scoresheet.Rows - 1
  sHold = ""
    For j = 0 To Scoresheet.Cols - 1
    sHold = sHold & Scoresheet.TextMatrix(I, j)
      If j < Scoresheet.Cols - 1 Then
      sHold = sHold & ","
      End If
    Next j
  Write #fHandle, sHold
  Next I

Close fHandle

End Sub

Getting it back  seemed easy but displaying it gave me real trouble. I finally decided my problem might be that I really had no idea of what it look like in its any disk form, except that it should be some kind of a text file. So I tried opening the file  in Notepad . Good, then I saw it and could figure out what the delimiters were.

I had gotten some knowledge of text manipulation in past adventures, so I felt I could de something here. I eventually worked out the code below. I feel sure it must be the longest way around there is, but it does seem to do the job in displaying the first "record" in the proper cells. My present problem is that I cannot figure out how to get the subsequent lines. I have not spotted anything in either of my two books that deals with this. It may well be there somewhere and I keep reading.

I guess there are a lot of "comments" below that are simple stuff to someone experienced, but I do get lost if I don't try to write down what I thought I was doing. There are also some code lines now commented out (mainly re Wend). These are bits of attempts to get that next line of code. Mostly I think I might have been getting the same first line over and over.

Public Sub ReadData()           'open a data file
  Dim inti As Integer             'general ForNExt counter
  Dim intlength As Integer        'hold # chars in each strGetLine
  Dim strGetLine As String        'hold one line of file
  Dim strCellText As String       'temporary: hold txt for 1 cell
    Dim strA As String    'to fetch 1 character
  Dim intRowCounter As Long   'counter / rows
  Dim intColCounter As Integer
  Dim intStringPosition As Integer   'counter / columns
  Dim fHandle As Long   'will hold a file number
  inti = 0                        'init character counter
  intStringPosition = 1
  strA = ""                       'init for single chars
  intRowCounter = 0
  intColCounter = 0
    'get file
    fHandle = FreeFile    'assigns open file number nextline opens
    Open "c:\My Documents\MyJongg" & "\Save.dat" For Input As fHandle

'**************** loop1 Get A line (top) *************************************
'  While Not EOF(fHandle)          'loop thru  entire file string
  Line Input #fHandle, strGetLine 'get line of file
  intlength = Len(strGetLine)     'get n.chars THIS line

'******************| loop2 accumulate field - paste to cell |*******
For inti = intStringPosition To intlength       'counter for each Char in line
  strA = Mid(strGetLine, inti, 1) 'get next Char
    If strA = """" Then     'skip over quote delimiter
      GoTo skipper          'by jumping to line label
    End If
    If strA = "," Then              'if is end of this cell txt
      strA = ""
      Scoresheet.TextMatrix(intRowCounter, intColCounter) = strCellText
      strCellText = ""              'blank accumulate variable
     intColCounter = intColCounter + 1
    GoTo skipper
    End If
    strCellText = strCellText & strA    'concatenate cell txt
skipper:                                'line label
intStringPosition = intStringPosition + 1
  Next inti
'******************| end2 accumulate field and paste to cell |**********

'intRowCounter = intRowCounter + 1       'increment the row counter
'****************|end1 Get A line |**************************************
End Sub  'ReadData

I thank you again for any help you can give me in getting thase next lines.



Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
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…
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…
Suggested Courses

636 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