Solved

Save the data.

Posted on 1998-12-18
8
184 Views
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)

      But:
      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.

Arthur

      
      
0
Comment
Question by:arrthur
8 Comments
 

Expert Comment

by:janeausten
ID: 1451423
hi,

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.

ex.

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!

0
 
LVL 1

Expert Comment

by:Sekans
ID: 1451424
arrthur:
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.

Regards,
Sekans
0
 
LVL 3

Accepted Solution

by:
jbil earned 50 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
         Loop
Close #1

'My need some tweaking, but you get the idea.
0
 

Author Comment

by:arrthur
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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:arrthur
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.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1451428
Bought This Question.
0
 

Author Comment

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

Arthur
0
 

Author Comment

by:arrthur
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
    'initialize
  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
'Wend
'****************|end1 Get A line |**************************************
End Sub  'ReadData

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

Art

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now