Need help with school project..
I am currently doing a computing project at school, and am having trouble with some parts of it.
My task is to create a program that will store a recipe name, number of people it will serve and the list of ingredients with their quantities and units.
It also asks that the program should output the recipe name and a new number of people with revised quantities with units for any number of people that the user chooses.
So far for my code I have:
Imports System.IO
Public Class Form1
Private Sub ButtonOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOpen.Click
Dim FileReader As StreamReader
Dim results As DialogResult
results = OpenFileDialog1.ShowDialog
If results = DialogResult.OK Then
FileReader = New StreamReader(OpenFileDialog1.FileName)
IandQ.Text = FileReader.ReadToEnd()
FileReader.Close()
End If
End Sub
Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
Dim FileWriter As StreamWriter
Dim results As DialogResult
results = SaveFileDialog1.ShowDialog
If results = DialogResult.OK Then
FileWriter = New StreamWriter(SaveFileDialog1.FileName, False)
FileWriter.Write(IandQ.Text)
FileWriter.Write(RecipeNameSave.Text)
FileWriter.Write(Serves.Text)
FileWriter.Close()
End If
End Sub
Private Sub AmendRecipeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AmendRecipeButton.Click
End Sub
End Class
This code allows me to save and retrieve files but I cannot separate the recipe name or the number of people into separate text boxes from the ingredients.
I also have no clue as to how I can amend the ingredient quantities after a new number of people is chosen.
Any helpful suggestions are appreciated.
Re: Need help with school project..
Quote:
I also have no clue as to how I can amend the ingredient quantities after a new number of people is chosen.
I believe it's called arithmetic.
Quote:
I cannot separate the recipe name or the number of people into separate text boxes from the ingredients.
You don't appear to be trying to do so! Let's just say that reading a file as a single block of text isn't the way to go.
Re: Need help with school project..
Quote:
Originally Posted by
dunfiddlin
I believe it's called arithmetic.
You don't appear to be trying to do so! Let's just say that reading a file as a single block of text isn't the way to go.
I understand that, but it's how to put it in to the code that I can't do.
As for the separate text boxes, I tried using the 'Split()' function and using an array, I couldn't get either to work.
Re: Need help with school project..
Look into the Streamwriter's WriteLine and the Streamreader's ReadLine methods.
Right now, you have:
FileWriter.Write("AAA")
FileWriter.Write("BBB")
Which outputs:
AAABBB
But with Writeline instead:
FileWriter.WriteLine("AAA")
FileWriter.WriteLine("BBB")
You get:
AAA
BBB
Which then you can easily read one line at a time using the Streamreader's Readline method.
Re: Need help with school project..
Quote:
I tried using the 'Split()' function and using an array, I couldn't get either to work.
So what happened? Your computer exploded, Superman died? What?
We work with cold, hard detail around these parts. If you can't or won't supply it, we don't help. If you're looking for someone to relieve you of the burden of writing the program you won't find them here, especially for a school project.