Customer Info Form sent to .txt file on desktop via button click - vb.net

Good evening,
I am attempting to finish this last little bit of my VB.net project for school. It's the good ol' pizza ordering system. After the welcome screen the user is prompted to enter first name/last name/email and then click submit (if they leave any box empty it will pop up w/ msgbox). I need to send the information that is input into textbox1, textbox2, and textbox3 into a .txt file on the desktop if possible.
Here is the code
Public Class CustomerInfo
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
MsgBox("Please Enter Your Information")
' Forces user to input something in to all three boxes before being allowed to proceed
'Prompts user to complete form with a message box.
'Once information is complete, clicking the submit button will close this form and open the Selection Form.
Dim desktopPath As String =
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim fileName As String = "customer.txt"
Dim fullPath As String = IO.Path.Combine(desktopPath, fileName)
IO.File.AppendAllLines(fullPath, {"textbox1.text & textbox2.text & textbox3.text"})
else
Selection.Show()
Me.Hide()
End If
End Sub
I attempted to upload a screenshot of the windows form, but am new to the forum. It's very basic, text boxes 1, 2, and 3 with a "Submit" button below them.
Thanks in advance for any assistance provided.
Kyle

Related

Visual Basic find and display

I have made a program in Visual Basic. It's a contact book where the user can enter a friend's name as the key and contact which is stored as a value. Both are entered via TextBoxes and the information is then displayed in a ListBox.
The following code is for my search address button where I enter the contact name in TextBox4 and it displays the address in TextBox3. The problem I'm having with my code is that after I enter more contacts into my ListBox and I click the find button it does display the address, but also the error message which is intended to be used if the contact does not exist.
I'm a beginner to programming and looking to see what is wrong with my code.
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
TextBox3.Clear()
For Each x In MyAddressBook
If TextBox4.Text.Contains(x.Key) Then
TextBox3.Text = x.Value
Else
If TextBox4.Text <> x.Key Then
MessageBox.Show("error")
End If
End If
Next
End Sub
You probably only need to stop the For Each loop when you were successful in your search. Add a Exit For after TextBox3.Text = x.Value. Since you found the address there's no need to look further.

how do i pass information to second form object

Good Morning all.
I have been working on this forever. but I am down to the very end. I need to get this submitted for may class Sunday.
I have a button that sends my data to the usb drive and I need to send it to a list on a second form. How do I pass this over.
Here is what I have:
Private Sub btnTestResults_Click(sender As Object, e As EventArgs) Handles btnTestResults.Click
' Sends data to the frmresults form three, and creates the "consult.txt file on a
' USB drive for the Nurse can contact the patients.
Dim objWriter As New IO.StreamWriter("e:\consult.txt")
Dim frmThird As New frmElevatedResults
Dim intHighCholesterol As Integer = 200I
' Write the file line by line until the file is completed.
If IO.File.Exists("e:\consult.txt") Then
If _intCholesterolLevel(intCount) < intHighCholesterol Then
objWriter.WriteLine(_strNames(intCount))
objWriter.WriteLine(_intCholesterolLevel(intCount))
Else
MsgBox("The file is not available.
Please restart the program when the file is available", , "Error")
objWriter.Close()
End If
End If
Hide()
frmThird.ShowDialog()
End Sub
Thank you very much
One option would be to make the listbox public on frmElevatedResults:
Add the listbox control via Toolbox to your frmElevatedResults (if not already done).
In the Project-Explorer click on Show all Files.
Open frmElevatedResults.Designer.vb
Find the listbox controle e.g. listBox1 as ListBox
Make it public: public listBox1 as ListBox
(I would have included screens but my VS is not in English).
On your first form you can now use:
Dim frmThird As New frmElevatedResults
...
frmThird.listBox1.Items.Add(string.concat(_strNames(intCount),
" - ",
_intCholesterolLevel(intCount))
...
Hide()
frmThird.Show()
or whatever you want to put in there.

VB.NET Set Default Text Editor

I have created my own text editor in Visual Basic 2013. I want to open text files with it from outside the application: to open them from the Desktop with double click or right click and open with.
I tried to use right click and open with but it doesn't work, it just opens up my application.
How I make my text editor the one that I open text files with?
You would have to use something like the Environment.GetCommandLineArgs method.
Put this in your form load event:
Dim CommandLineArguments() As String = Environment.GetCommandLineArgs()
If CommandLineArguments.Length >= 2 AndAlso String.IsNullOrEmpty(CommandLineArguments(1)) = False AndAlso IO.File.Exists(CommandLineArguments(1)) Then
Me.TextBox1.Text = IO.File.ReadAllText(CommandLineArguments(1))
End If
This will get the command line arguments sent to your application (which is the path to the file you are trying to open with your app) and check if the argument is an existing file. If so, it will read all the file's text into your TextBox.
Write this code in the form load event.
Private Sub form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim fname As String = Command$()
If Not fname = "" Then
fname = Replace(fname, Chr(34), "")
Dim obj As New System.IO.StreamReader(fname.ToString)
RichTextBox1.Rtf = obj.ReadToEnd
obj.Close()
Me.Text = "Your Application Name " & fname
End If
End Sub

how to reset variable on form clear in vb?

I have a small program that on "Load" button click creates object info and populates a text field. I also have a clear button that resets everything on the form. On form load if you click the "load" button without first choosing a company from the drop down list you get an error saying "choose company first".
If you choose a company and hit "load" everything works perfectly. If you hit clear everything clears out but if you then hit "load" it fills the text field with the info from the previously chosen company instead of showing the "choose company first error".
does anyone out there have any suggestions that might help to truly clear everything when the clear button is clicked?
here is my code
Public Sub btn_LoadScript_Click(sender As Object, e As EventArgs) Handles btn_LoadScript.Click
'get vb script
If cb_COID.SelectedItem = String.Empty Then
lbl_FormMainUserMessage.Text = "Select a Company Code"
Else
Try
Dim co As Object = M3System.GetEntity("MillCompany.Company", cb_COID.SelectedItem)
Dim script As Object = co.Scripting.ItemByKey("PaycheckCalc")
'Dim script = co.Scripting.ItemByKey("CCalcCode")
Scintillatb_Script.Text = script.vbscript
Catch ex As Exception
lbl_FormMainUserMessage.Text = ex.Message
End Try
End If
End Sub
Private Sub btn_Reset_Click(sender As Object, e As EventArgs) Handles btn_Reset.Click
'clear form
For Each cb In Me.Controls.OfType(Of ComboBox)()
cb.Text = String.Empty
cb.SelectedItem = String.Empty
Next cb
For Each tb In Me.Controls.OfType(Of TextBox)()
tb.Text = String.Empty
Next tb
For Each lb In Me.Controls.OfType(Of Label)()
lb.Text = String.Empty
Next lb
Scintillatb_Script.Text = ""
End Sub
Try to set your dropdown selected index -1.
Add to your clear code :
YourDropdown.selectedindex = -1
How are you clearing the drop down list? it seems that the text of the drop down list is cleared, but not the selected index or selected item of that drop down list.
That's why when clicking load for the second time after clearing the UI, it still loads the information, instead of mentioning the error message "Choose company first error"

How to automatically append to RichTextBox in Visual Basic

I tried Google for an answer but didn't find what I was looking for.
I created a very simple app that lets users use a barcode scanner to scan barcodes into a text file. Everything works fine, I just want to simplify it a bit more.
Originally, I have a textbox1.text field where the scanned barcode would appear, then the user had to click the 'Add' button (Button1.Click) I placed next to the textbox field to append the barcode serial into a RichTextBox right below. Well the user found it tedious to have to click the 'Add' button every time they scanned an individual barcode.
My Question
Is there a way I can have the text in textbox1.text automatically append to RichTextBox as soon as a barcode is scanned? I want to eliminate having to click the 'Add' button.
Here is my current code (code for the Button1.Click button):
Dim scanData As String = TextBox1.Text
RichTextBox1.AppendText(scanData + " " + Format(TimeOfDay, "HH:mm:ss") + vbNewLine)
TextBox1.Clear()
TextBox1.Focus()
First off, I would make sure the user cannot input text themselves by disabling the TextBox control (TextBox1.Enabled=False), then add your code to the TextChanged event:
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
Dim scanData As String = TextBox1.Text
RichTextBox1.AppendText(scanData + " " + Format(TimeOfDay, "HH:mm:ss") + vbNewLine)
TextBox1.Clear()
TextBox1.Focus()
End Sub
Before appending to the RTB, I would check to make sure the BarCode is valid.