Hiya,
I've been stuck on an application for a long time. The application has changed many times. It works different each time. It always gets worse and better at the same time!!! I need serious help.
It has 1 form, 1 command button, 1 text box and 2 labels. (1 label displays the date which is saved along with every number)
1. The command button is used to save a 3 digit number entered into the text box and the current date.
2. The other label, larger label, label will display a list of all previously entered numbers and their dates on the current file.
3. When the command button is pressed the data will save instantly meaning the user needs to select a text file before hand.
4. The ability to open a different file later will be done through the normal File, Open.
5. New will give the user the ability to create a new text file to save to and all data on the form will be erased.
6. Open will also take any data on the selected file and put it in the label. The label shows whatever is on the file at all times.
7. Save is to save any data on the label to a different file, a new one with the user choosing file name. It will not save what is in the text box.
I'm a beginner and I'm doing my best to learn everything but this gets confusing. I always run into problems appending to file and keeping the file open for the command button or making the command button open it automatically each time and appending to it. The other issue is the label. Reading and displaying the data or writing the list of data on it is different from writing 1 line which I can allready do. I'm sure this is out of my league and I need more practice at basic write, read and append but my tutor needs this soon! I've been on it since last year :-)
Heres my code, if you could improve this in anyway using a similiar format so that I can understand it as I go along that would be brilliant. I'll be using the code again later so I'll need to understand it. The applications was saving in this format...
0
#2004-06-12#,"876"
But its not now. I've been trying to change the 0 to a 1 and make it go up 1 with every record saved but I've messed it up and I dont know how. I just get '0' on my saves now. I'm happy to do this in parts and step by step. You know best but if you can come up with the application that does most of what I said thats great. I wanted this application finished before 2005! Doesnt look like I was born for programming then!!!
Dim Dates(9000) As Date
Dim Reps(9000) As String
Dim Session As Integer
Private Sub cmdSubmit_Click()
Dim I As Integer
'The submit button acts like 'Save' but also effects the form
'Find value of lblReps and prepare a variable
Reps(I) = txtReps
'Use to save the current data inputed by the user however a command button will also do this
cdlFiles.Filter = "Files (*.txt)|*.txt"
cdlFiles.DefaultExt = "txt"
cdlFiles.DialogTitle = "Save File"
cdlFiles.Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
On Error GoTo No_Save
cdlFiles.ShowSave
Open cdlFiles.FileName For Append As #1
Write #1, Session
For I = 1 To Session
Write #1, Dates(I), Reps(I)
Next I
Close 1
Exit Sub
No_Save:
Resume ExitLine
ExitLine:
Exit Sub
'Load workout history file into lblHistory and show as a list
lblHistory = Dates(D) & " " & Reps(R)
'Clear all text boxes
txtReps.Text = ""
'Show details in debug window
Debug.Print Dates(D); Reps(R)
End Sub
Private Sub Form_Load()
'Display the time and date with enabled timer control
lblDate = Format(Now, "mm/dd/yyyy")
lblTime = Time
Timer1 = True
'Initiate variable for date
Dates(D) = Format(Now, "mm/dd/yyyy")
End Sub
Private Sub mnuFileExit_Click()
End
End Sub
Private Sub mnuFileNew_Click()
'New will create a new text file for the user to write data to later
cdlFiles.Filter = "Files (*.txt)|*.txt"
cdlFiles.DefaultExt = "txt"
cdlFiles.DialogTitle = "Save File"
cdlFiles.Flags = cdlOFNOverwritePromt
cdlFiles.ShowSave
Close
End Sub
Private Sub mnuFileOpen_Click()
'Used to open text file and read the data for show in history label
cdlFiles.Filter = "Files (*.txt)|*.txt"
cdlFiles.DefaultExt = "txt"
cdlFiles.DialogTitle = "Open File"
cdlFiles.Flags = cdlOFNFileMustExist + cdlOFNPathMustExist
cdlFiles.ShowOpen
Open cdlFiles.FileName For Input As #1
Close 1
Exit Sub
No_Open:
Resume ExitLine
ExitLine:
Exit Sub
End Sub
Private Sub mnuFileSave_Click()
'Use to save the current data inputed by the user however a command button will also do this
cdlFiles.Filter = "Files (*.txt)|*.txt"
cdlFiles.DefaultExt = "txt"
cdlFiles.DialogTitle = "Save File"
cdlFiles.Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
On Error GoTo No_Save
cdlFiles.ShowSave
Open cdlFiles.FileName For Append As #1
Close 1
Exit Sub
No_Save:
Resume ExitLine
ExitLine:
Exit Sub
End Sub
Private Sub Timer1_Timer()
'Make timer update system time as it changes
If lblTime.Caption <> CStr(Time) Then
lblTime.Caption = Time
End If
End Sub
Private Sub txtReps_KeyPress(KeyAscii As Integer)
'Only allow number keys or the backspace key to be used
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyBack Then
Exit Sub
Else
KeyAscii = 0
Beep
End If
End Sub
Private Sub mnuRecentFile_Click(index As Integer)
' Call the file open procedure, passing a
' reference to the selected file name
OpenFile (mnuRecentFile(index).Capt
ion)
' Update the list of the most recently opened files.
GetRecentFiles
End Sub
Private Sub Init()
Session = 1: vsbControl.Value = 1: vsbControl.Max = 1
Reps(1) = ""
lblDate.Caption = Dates(1)
txtReps.Text = Reps(1)
End Sub