VB: form data to save to notepad

jsalzm1

Member
Join Date
Jun 2015
Location
Houston
Posts
23
Hi guys,

Im new to VB and im trying to create a form that will save the data from the form to Notepad. But when I click the "save" button I made, it saves the data, but the error "448##error" appears on the notepad. What is wrong with the code? I tried creating the first line and entering the data, but i cant seem to get it right
 
Hi guys,

Im new to VB and im trying to create a form that will save the data from the form to Notepad. But when I click the "save" button I made, it saves the data, but the error "448##error" appears on the notepad. What is wrong with the code? I tried creating the first line and entering the data, but i cant seem to get it right

Post your save button code.
 
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim k As Long

If TextBox10.Text <> "" Then
If MsgBox("Please ensure all of the following criteria is correct:" & vbNewLine & "Job #" & TextBox1.Text & vbNewLine & "Sales Order Number:" & TextBox2.Text & vbNewLine & "Date:" & DateTimePicker1.Text & vbNewLine & "Requested by:" & ComboBox1.Text & vbNewLine & "Serial #:" & TextBox3.Text & vbNewLine & "Hose Type:" & ListBox2.Text & vbNewLine & "Hose Size:" & ListBox3.Text & vbNewLine & "Fitting 1:" & TextBox11.Text & vbNewLine & "Fitting 2:" & TextBox12.Text & vbNewLine & "Quantity:" & NumericUpDown1.TextAlign & vbNewLine & "OAL:" & TextBox4.Text & vbNewLine & "Cut Off:" & TextBox5.Text & vbNewLine & "Offset:" & TextBox6.Text & vbNewLine & "Crimp 1:" & TextBox7.Text & vbNewLine & "Crimp 2" & TextBox8.Text & vbNewLine & CheckBox1.Text & vbNewLine & CheckBox2.Text, vbYesNo) = vbYes Then
MsgBox("Hose Sucessfully Added")
ReDim Preserve jobnumber(0 To totalhoses)
ReDim Preserve salesorder(0 To totalhoses)
ReDim Preserve hosedate(0 To totalhoses)
ReDim Preserve request(0 To totalhoses)
ReDim Preserve serial(0 To totalhoses)
ReDim Preserve type(0 To totalhoses)
ReDim Preserve hosesize(0 To totalhoses)
ReDim Preserve fitting1(0 To totalhoses)
ReDim Preserve fitting2(0 To totalhoses)
ReDim Preserve qty(0 To totalhoses)
ReDim Preserve oal(0 To totalhoses)
ReDim Preserve cutoff(0 To totalhoses)
ReDim Preserve offset(0 To totalhoses)
ReDim Preserve cs1(0 To totalhoses)
ReDim Preserve cs2(0 To totalhoses)
ReDim Preserve cleaned(0 To totalhoses)
ReDim Preserve pig(0 To totalhoses)

jobnumber(totalhoses) = TextBox1.Text
salesorder(totalhoses) = TextBox2.Text
hosedate(totalhoses) = DateTimePicker1.Text
request(totalhoses) = ComboBox1.Text
serial(totalhoses) = TextBox3.Text
type(totalhoses) = ListBox2.Text
hosesize(totalhoses) = ListBox3.Text
fitting1(totalhoses) = TextBox11.Text
fitting2(totalhoses) = TextBox12.Text
qty(totalhoses) = NumericUpDown1.TextAlign
oal(totalhoses) = TextBox4.Text
cutoff(totalhoses) = TextBox5.Text
offset(totalhoses) = TextBox6.Text
cs1(totalhoses) = TextBox9.Text
cs2(totalhoses) = TextBox10.Text
cleaned(totalhoses) = CheckBox1.Text
pig(totalhoses) = CheckBox2.Text

FileOpen(2, "HoseData.txt", OpenMode.Output)
WriteLine(2, tempjobnumber, tempsalesorder, temphosedate, temprequest, tempserial, temptype, temphosesize, tempfitting1, tempfitting2, tempqty, tempoal, tempcutoff, tempoffset, tempcs1, tempcs2, tempacs1, tempacs2, tempcleaned, temppig)

For k = 1 To totalhoses

WriteLine(2, jobnumber(k), salesorder(k), hosedate(k), request(k), serial(k), type(k), hosesize(k), fitting1(k), fitting2(k), qty(k), oal(k), cutoff(k), offset(k), cs1(k), cs2(k), cleaned(k), pig(k))

Next
FileClose(2)
Hoses_Load(sender, e)

Else
MsgBox("Please Review")
End If
Else
MsgBox("Save")
End If

End Sub



sorry if that is hard to read
 
theres no error....it works, the question im having is when I go back into notepad after hitting save, inside the notepad file says "448##error". Like the file isnt reading what i have in my code
 
theres no error....it works, the question im having is when I go back into notepad after hitting save, inside the notepad file says "448##error". Like the file isnt reading what i have in my code

You are writing to notepad, notepad isn't reading from your code. I assume you know this. You are just creating a Text document.

I haven't looked through the code, but if you put in breakpoints you can do an awful lot of monitoring of values while the code is in break mode and see where the error occurs. I would start with making sure that the Arrays contain the values you expect (every one of them).
 
correct. so for me to create a text document and have the, lets say textbox1 to save, do i need to create a line with "job number", then under that put in some bs value like "2222" then save the notepad file and try rerunning the program again?
 
theres no error....it works, the question im having is when I go back into notepad after hitting save, inside the notepad file says "448##error". Like the file isnt reading what i have in my code

As I read the code, you are only adding one element to the array for each write command. I'm not sure why you are re-writing the whole array each time.

Maybe I am misunderstanding what you are doing, but my principle is to try to keep it as simple as I can - this doesn't *seem* to be the simplest way to do this.

Regardless, as I said above, I recommend finding out what isn't working in your code. You could simply remove the arrays and just get the writeline part working.
 
correct. so for me to create a text document and have the, lets say textbox1 to save, do i need to create a line with "job number", then under that put in some bs value like "2222" then save the notepad file and try rerunning the program again?

My last post for a while - I'm going to lunch.

Have you defined what you actually want to do, clearly in your own mind? I don't have that clear in mine so I don't know if I can help you without that clear definition.

Maybe someone else can.
 
Not really....This isnt my project. Im an IE (interning at the moment) and an ME was trying to write this to use out in the shop. So he gave me all of this. So Im trying to get it to work, which some of it I have. I am just stuck here and highly confused.
 
If you're using VS2013, you should really take advantage of the tools provided by .NET. This code looks like it was copied from an old VB6 program.

For instance you have a lot of arrays that are Redimmed every time you add another item. This is exactly what a List (collection) was designed for:

Instead of the Dim that you have outside of your click handler, you would use this:
Code:
Private  JobNumber as new (List of String)
In place of Redim, and setting the last element value, you would do this:
Code:
JobNumber.Add(TextBox1.Text)

For writing to files, use the StreamWriter object.

Code:
   Dim Index as integer
   Using sw As New System.IO.StreamWriter("HoseData.txt", True)
        While index<JobNumber.Count
                 sw.WriteLine(JobNumber(index)
                 index += 1
         End While
         sw.close
    End Using



These are all standard tools that are part of the .NET framework and have a much better chance of working in future versions.
 
If you're using VS2013, you should really take advantage of the tools provided by .NET. This code looks like it was copied from an old VB6 program.

For instance you have a lot of arrays that are Redimmed every time you add another item. This is exactly what a List (collection) was designed for:

Instead of the Dim that you have outside of your click handler, you would use this:
Code:
Private  JobNumber as new (List of String)
In place of Redim, and setting the last element value, you would do this:
Code:
JobNumber.Add(TextBox1.Text)

For writing to files, use the StreamWriter object.

Code:
   Dim Index as integer
   Using sw As New System.IO.StreamWriter("HoseData.txt", True)
        While index<JobNumber.Count
                 sw.WriteLine(JobNumber(index)
                 index += 1
         End While
         sw.close
    End Using



These are all standard tools that are part of the .NET framework and have a much better chance of working in future versions.

I thought you might be able to make some suggestions. My VB skills, though pretty good at one time, are a bit rusty now.
 

Similar Topics

Hi everyone, I am new here, I am working in a project where SCADA Data need to upload(insert in to) Database table in real-time, I am Using AVEVA...
Replies
1
Views
1,202
Why can't you use a data change with an OR expression. Like Tag1 OR Tag2 Or Tag3? It kind of works but unless a make three data change scripts...
Replies
8
Views
2,938
Hi all, I'm trying to access to archestrA from c#.But i can't find wonderware tookit to take dll file.Do you have wonderware tookit?is possible to...
Replies
0
Views
2,571
We are doing a proof of concept to try the following 1) get data from KepServer 2) The Data will be transformed eg: a Status code of 1 gets...
Replies
0
Views
1,214
Hello everyone, Maybe a simple question for you people, but i break my head on this one. What are integers, signed/unsigned, real, floating...
Replies
3
Views
1,660
Back
Top Bottom