I'm trying to create a telephone number word generator(that part i have finished) that instead of outputting to a TextBox, writes to a .txt file using StreamWriter. But i'm having issues doing this. Can anyone shed a little light on this?
here is the GUI:
![Name: Capture.PNG
Views: 149
Size: 4.5 KB]()
so one would enter a 7-digit number and press start. The button event runs the combinations and then the "Save As" enables to allow them to save the results to a text file.
i'm not sure i have my coding in the right place for StreamWriter. i've only called from a written text file before to display its contents, never written to one before.
code:
any help one can give will be extremely appreciated. thank you again!
here is the GUI:
so one would enter a 7-digit number and press start. The button event runs the combinations and then the "Save As" enables to allow them to save the results to a text file.
i'm not sure i have my coding in the right place for StreamWriter. i've only called from a written text file before to display its contents, never written to one before.
code:
Code:
Imports System.IO
Public Class TelephoneGenerator
Private filewriter As StreamWriter ' writes data to text file
Private output As FileStream ' maintains connection to file
Private Sub saveButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles saveButton.Click
Dim result As DialogResult ' stores result of Save dialog
Dim fileName As String ' name of file to save data
' display dialog so user can choose name of file to save
Using fileChooser As New SaveFileDialog()
result = fileChooser.ShowDialog()
fileName = fileChooser.FileName ' get specified file name
End Using ' automatic call to fileChooser.Dispose() occurs here
End Sub ' saveButton_Click
Private Sub startButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles startButton.Click
Dim number As String = phoneNumberTextBox.Text ' get the number entered
Dim phoneNumber As Integer = Convert.ToInt32(phoneNumberTextBox.Text)
' String array that stores the letters
Dim letters(,) As String = {{" ", " ", " "}, {" ", " ", " "}, {"A", "B", "C"}, {"D", "E", "F"},
{"G", "H", "I"}, {"J", "K", "L"}, {"M", "N", "O"}, {"P", "R", "S"}, {"T", "U", "V"},
{"W", "X", "Y"}}
Dim digits(6) As Integer ' digits array (indicies 0 through 6)
Dim output As String = String.Empty ' sets the output as String and makes sure its empty
For k = 6 To 0 Step -1 ' get each number individually starting at the end
digits(k) = phoneNumber Mod 10 ' take the input number Mod 10
phoneNumber \= 10 ' divide the phoneNumber by 10 and keep the integer result
Next
' loop through all the letters for each corresponding digit
For Loop1 = 0 To 2
For Loop2 = 0 To 2
For Loop3 = 0 To 2
For Loop4 = 0 To 2
For Loop5 = 0 To 2
For Loop6 = 0 To 2
For loop7 = 0 To 2
' append the seven-letter word to the output
output &= String.Format("{0, -10}", letters(digits(0), Loop1) &
letters(digits(1), Loop2) & letters(digits(2), Loop3) &
letters(digits(3), Loop4) & letters(digits(4), Loop5) &
letters(digits(5), Loop6) & letters(digits(6), loop7))
Next
Next
Next
Next
Next
Next
Next
filewriter.WriteLine(output)
End Sub ' startButton_Click
End Class