I have created a small program which returns simple outputs to the user. The user enters numbers into this program and from here I can return the highest/smallest values, or the sum of all the numbers, etc.
However I wish to design a method of saving the returned value into a text file. I have been able to accomplish this by using the SaveFileDialog feature on VB.NET ( 2008 ) which does indeed save the values to a text file.
But the issue is that I unable to figure out how I go about placing this SaveFileDialog into a separate class fromo the form which I can call upon in my main form.
I am new to VB and I have the basic grasp of classes. For instance my algorithms to work out the highest values is in a class which I understand I need to call upon then return the value to the main form (This is my code to call upon the algorithm in my class) but when it comes to a saveFileDialog you're not returning a value you are calling upon that function, which confuses me.
ArrayClass.SumInteger(Array)
TheAnswer = ArrayClass.ArrayAnswer4
TextBox10.Text = TheAnswer
This is the SaveFileDialog code I have been using which works on the main form, but not from a class:
Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim myStream As Stream
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
saveFileDialog1.FilterIndex = 2
saveFileDialog1.RestoreDirectory = True
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
myStream = saveFileDialog1.OpenFile()
Using sw As StreamWriter = New StreamWriter(myStream)
' Add some text to the file.
sw.WriteLine(TextBox1.Text)
sw.WriteLine(TextBox2.Text)
sw.WriteLine(TextBox3.Text)
sw.WriteLine(TextBox4.Text)
sw.WriteLine(TextBox5.Text)
sw.WriteLine(TextBox6.Text)
sw.WriteLine("--------")
sw.WriteLine("This is the large value " & (TextBox7.Text))
sw.WriteLine("This is the smallest value" & (TextBox8.Text)
sw.Close()
End Using
If (myStream IsNot Nothing) Then
' Code to write the stream goes here.
myStream.Close()
End If
End If
End Sub
I would like to say I have tried many ways to get this working but that would be incorrect, I am generally struggling to understand how I would get this feature to work. I just don't know where to start.
Can you explain to me how I go about accomplishing my task. I feel like a bit of a dummy.
-Edward

New Topic/Question
Reply



MultiQuote





|