Solved

Saving a file....

Posted on 1998-12-20
5
144 Views
Last Modified: 2010-05-03
Can someone give me an answer on how to save my programs inputs. I'm using about 10 Textbox as input to some of my calculation....for example in Textbox1(in runtime mode) I keyin '1' then I have this Menu on top of my screen, where I put &Save....

So is there away to save that input ? "1" And how can I load it back the "1" when next time I run it.
0
Comment
Question by:plastic_74
  • 3
5 Comments
 
LVL 4

Expert Comment

by:idcanada
ID: 1451691

Use the registry,
GetSetting and SaveSetting are the elements.
Look in the VB Help for how to use these witha full explanation.



0
 
LVL 3

Expert Comment

by:Sendoh
ID: 1451692
Hi !
Beside registry, you can save it to fiel as well.
Hope it'll help you.
0
 
LVL 2

Author Comment

by:plastic_74
ID: 1451693
Hei...guys what I need is code. How do I write the code... Open files, Save files, Is what I need. Not REGISTRY !
0
 
LVL 3

Accepted Solution

by:
Sendoh earned 200 total points
ID: 1451694
Hi !

The code as follow :

 Dim strSave as string
 Dim FileNum As Integer

 For i=0 to 10
      if i <> 0 then
           strSave = strSave & "," & textArray(i).text
      else
           strSave = textArray(i).text
      end if
 next i
   
 FileNum = FreeFile
 Open "save.txt" For Output As FileNum
 Print #FileNum, strSave
 Close FileNum

Every text field are seperated by ",".
When you need to get back the data just :

On Error GoTo errorhandler:
    Dim FileNum As Integer
    Dim retval As String
   
    FileNum = FreeFile
    Open save.txt For Input As FileNum
    Input #FileNum, retval
    Close FileNum
    'code to extract the retval fiel based on ','
   
errorhandler:
    'file not found error so assign default print schedule
    If Err.Number = 53 Then
          msgbox "File Not found"
    End If
0
 
LVL 3

Expert Comment

by:Sendoh
ID: 1451695
Hi !
Extra code for extract !!

Function ExtractString(ByVal strSource As String, ByVal intPosition As Integer, ByVal strDelimiter As String) As Variant
    Dim intPos As Integer
    Dim intLastPos As Integer
    Dim intLoop As Integer
    Dim intPos1 As Integer

    intPos = 0
    intLastPos = 0
    intLoop = intPosition
    Do While intLoop > 0
        intLastPos = intPos
        intPos1 = InStr(intPos + 1, strSource, strDelimiter)
        If intPos1 > 0 Then
            intPos = intPos1
            intLoop = intLoop - 1
        Else
            intPos = Len(strSource) + 1
            Exit Do
        End If
    Loop
    ' If we didn't find a comma and we're still on the first piece of the
    ' string, we have an error.  We must have at least one delimiter in our strings!
    If intPos1 = 0 And (intLoop = intPiece Or intLoop > 1) Then
        ExtractString = Null
    Else
        ExtractString = Mid(strSource, intLastPos + 1, intPos - intLastPos - 1)
    End If
End Function

Private Sub Command1_Click()
    Dim s As String
   
    s = ExtractString("a,b,c,d", 2, ",")
    'should be "b"
    MsgBox s
End Sub

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

20 Experts available now in Live!

Get 1:1 Help Now