[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Write, Append, Read and Confusion With This Application

Asked by TycoonMillion in Visual Basic Programming

Tags: append, file, open

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).Caption)
    ' 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
[+][-]01/05/05 03:27 PM, ID: 12967705Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/06/05 11:55 AM, ID: 12976003Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Visual Basic Programming
Tags: append, file, open
Sign Up Now!
Solution Provided By: Enlade
Participating Experts: 2
Solution Grade: A
 
 
Loading Advertisement...
20091021-EE-VQP-81