peebman2000
Programmer
Hey guys it’s me I’m back, I’m a beginner programmer, so this is why I have some many questions. Anyway on my code below where It begins the IF statement “If Right(dept, 6) >= 1011100 and Right(dept, 6) <= 101380 and left (dept, 3) = “DAS” then
Payroll = “000”
Address1= payroll
End if”…I’m getting a Conversion from string " " to type 'Double' is not valid. Error. What its supposed to do here in the if statement is read the text file and anything that right of dept(which is DAS) and left at DAS that has characters that are less than 101100 and greater than 101380 its supposed to make payroll be “000”. I get the conversion error, does anyone know why. I would appreciate any help. Thanks.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Visible = True
Dim slnin As String = ""
Dim slnout As String = ""
Dim outputfile As String = ""
Dim semi As String = ""
Dim national_id As String = ""
Dim last_name As String = ""
Dim first_name As String = ""
Dim mid_initial As String = ""
Dim suffix As String = ""
Dim dept_ID As String = ""
'Dim payroll As String = ""
Dim address1 As String = ""
Dim address2 As String = ""
Dim city As String = ""
Dim state As String = ""
Dim postal As String = ""
Dim phone As String
Dim hire_dt As New Date()
Dim mystring As String = hire_dt.ToString("MM/dd/yyyy")
Dim reg_temp As String = ""
Dim full_part_time As String = ""
Dim appt_type As String = ""
Dim derived_value As String = " "
Dim derived_value2 As String = " "
Dim barg_unit As String = ""
Dim oh_bu_flag As String = ""
Dim union_cd As String = ""
Dim jobcode As String = ""
Dim business_title As String = "" ' coded this variable thinking this was the job_title
Dim derived_value3 As String = " "
Dim derived_value4 As String = " "
Dim termination_dt As String = "" ' coded this variable thinking this was the separation_dt
Dim action As String = ""
Dim action_reason As String = ""
Dim pay_period_end As New Date()
Dim paystring As String = pay_period_end.ToString("MM/dd/yyyy")
Dim emp_id As String = ""
Dim empl_rcd As String = ""
Dim class_indc As String = "" 'code this variable thinking this was the job_indicator
Dim dept As String = ""
Dim payroll As String = ""
semi = ";"
'Dim mystringbuilder As New StringBuilder
'Dim fileok As Boolean = False ' may delete
Dim doctxt As String = Right(FileUpload1.FileName, 3).ToString
'Try
'If doctxt.ToLower = "txt" Or doctxt.ToLower = "txt" Or doctxt.ToLower = Nothing Or doctxt = "" Then
If FileUpload1.HasFile And doctxt.ToLower = "txt" Or doctxt.ToLower = "txt" Then
Dim filename As String = ""
If filename = String.Empty Then
filename = FileUpload1.PostedFile.FileName
End If
Dim sr As StreamReader
sr = File.OpenText(filename)
While sr.Peek() <> -1
slnin = sr.ReadLine
If Not slnin Is Nothing Then 'store text in slnin
national_id = slnin.Substring(1384, 20)
last_name = slnin.Substring(1650, 30)
first_name = slnin.Substring(1685, 30)
mid_initial = slnin.Substring(1720, 30)
suffix = slnin.Substring(1645, 15)
dept_ID = slnin.Substring(0, 9)
dept = dept_ID
If Left(dept, 3) = "DAS" Then
dept_ID = 100
End If
If Right(dept, 6) >= 101100 And Right(dept, 6) <= 101380 And Left(dept, 3) = "DAS" Then
'If Right(dept, 6) > 1 Then
payroll = "000"
'address1 = payroll
End If
'address1 = slnin.Substring(391, 54)
address2 = slnin.Substring(446, 55)
city = slnin.Substring(501, 30)
state = slnin.Substring(531, 6)
postal = slnin.Substring(537, 12)
phone = slnin.Substring(549, 24)
phone = Replace(phone, "/", "")
phone = Replace(phone, "-", "")
If IsDate(slnin.Substring(341, 10)) = False Then
hire_dt = "01/01/1900"
Else
hire_dt = slnin.Substring(341, 10)
End If
reg_temp = slnin.Substring(52, 1)
full_part_time = slnin.Substring(152, 1)
appt_type = slnin.Substring(5161, 1)
barg_unit = slnin.Substring(320, 4)
oh_bu_flag = slnin.Substring(316, 1)
union_cd = slnin.Substring(317, 3)
jobcode = slnin.Substring(27, 6)
business_title = slnin.Substring(33, 10) ' this did not match up with the layout(job title)
termination_dt = slnin.Substring(361, 10) ' this did not match i thought this was separation date
action = slnin.Substring(68, 3)
action_reason = slnin.Substring(71, 3)
If IsDate(slnin.Substring(1800, 10)) = False Then
pay_period_end = "01/01/1900"
Else
pay_period_end = slnin.Substring(1800, 10)
End If
emp_id = slnin.Substring(10, 11)
empl_rcd = slnin.Substring(21, 3)
class_indc = slnin.Substring(5163, 1) ' this did not match up with the layout(job indicator)
'last_name = last_name.PadRight(25)
'build line to be wrote out
'Dim myStringBuilder As New StringBuilder
'myStringBuilder.Append(national_id + semi)
slnout = national_id + semi
slnout += last_name.Trim.PadRight(30, " ") + semi
slnout += mid_initial + semi
slnout += first_name.Trim.PadRight(30, " ") + semi
slnout += suffix.PadRight(15, " ") + semi
slnout += dept_ID.PadRight(10, " ") + semi
slnout += address1.PadRight(55, " ") + semi
slnout += address2.PadRight(55, " ") + semi
slnout += city.PadRight(30, " ") + semi
slnout += state.PadRight(6, " ") + semi
slnout += postal + semi
slnout += phone.Trim + semi
slnout += hire_dt.ToString("MM/dd/yyyy") + semi
slnout += reg_temp + semi
slnout += full_part_time + semi
slnout += appt_type + semi
slnout += derived_value + semi
slnout += derived_value2 + semi
slnout += barg_unit + semi
slnout += oh_bu_flag + semi
slnout += union_cd + semi
slnout += jobcode + semi
slnout += business_title.PadRight(30, " ") + semi
slnout += derived_value3 + semi
slnout += derived_value4 + semi
slnout += termination_dt + semi
slnout += action + semi
slnout += action_reason + semi
slnout += pay_period_end.ToString("MM/dd/yyyy") + semi
slnout += emp_id + semi
slnout += empl_rcd + semi
slnout += payroll
slnout += class_indc + semi & vbCrLf
outputfile += slnout
'Response.Write(slnout)
'Response.End()
End If
End While
'Response.Write(slnout)
'Response.End()
sr.Close()
'Dim fileout As String = "\newfile" & ".txt"
Try '& FileUpload1.Filename)
File.WriteAllText(Server.MapPath("uploads/newfile.txt"), outputfile)
Catch ex As Exception
''FileUpload1.SaveAs(Server.MapPath("uploads\" & FileUpload1.FileName))
Label1.Text = "Failed because <br/>" & ex.Message
End Try
Label1.Text = "File uploaded to server" '& FileUpload1.PostedFile.FileName
'sr.Close()
'objstreamreader.Close()
'Console.ReadLine()
Else
Label1.Text = "Please select a file to upload"
End If
'Else
'Label1.Text = "Please Choose a Text file only with extension of .txt"
'End If
'Catch ex As Exception
'Response.Write("You did not choose the correct file")
'Response.End()
' End Try
End Sub
Payroll = “000”
Address1= payroll
End if”…I’m getting a Conversion from string " " to type 'Double' is not valid. Error. What its supposed to do here in the if statement is read the text file and anything that right of dept(which is DAS) and left at DAS that has characters that are less than 101100 and greater than 101380 its supposed to make payroll be “000”. I get the conversion error, does anyone know why. I would appreciate any help. Thanks.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Visible = True
Dim slnin As String = ""
Dim slnout As String = ""
Dim outputfile As String = ""
Dim semi As String = ""
Dim national_id As String = ""
Dim last_name As String = ""
Dim first_name As String = ""
Dim mid_initial As String = ""
Dim suffix As String = ""
Dim dept_ID As String = ""
'Dim payroll As String = ""
Dim address1 As String = ""
Dim address2 As String = ""
Dim city As String = ""
Dim state As String = ""
Dim postal As String = ""
Dim phone As String
Dim hire_dt As New Date()
Dim mystring As String = hire_dt.ToString("MM/dd/yyyy")
Dim reg_temp As String = ""
Dim full_part_time As String = ""
Dim appt_type As String = ""
Dim derived_value As String = " "
Dim derived_value2 As String = " "
Dim barg_unit As String = ""
Dim oh_bu_flag As String = ""
Dim union_cd As String = ""
Dim jobcode As String = ""
Dim business_title As String = "" ' coded this variable thinking this was the job_title
Dim derived_value3 As String = " "
Dim derived_value4 As String = " "
Dim termination_dt As String = "" ' coded this variable thinking this was the separation_dt
Dim action As String = ""
Dim action_reason As String = ""
Dim pay_period_end As New Date()
Dim paystring As String = pay_period_end.ToString("MM/dd/yyyy")
Dim emp_id As String = ""
Dim empl_rcd As String = ""
Dim class_indc As String = "" 'code this variable thinking this was the job_indicator
Dim dept As String = ""
Dim payroll As String = ""
semi = ";"
'Dim mystringbuilder As New StringBuilder
'Dim fileok As Boolean = False ' may delete
Dim doctxt As String = Right(FileUpload1.FileName, 3).ToString
'Try
'If doctxt.ToLower = "txt" Or doctxt.ToLower = "txt" Or doctxt.ToLower = Nothing Or doctxt = "" Then
If FileUpload1.HasFile And doctxt.ToLower = "txt" Or doctxt.ToLower = "txt" Then
Dim filename As String = ""
If filename = String.Empty Then
filename = FileUpload1.PostedFile.FileName
End If
Dim sr As StreamReader
sr = File.OpenText(filename)
While sr.Peek() <> -1
slnin = sr.ReadLine
If Not slnin Is Nothing Then 'store text in slnin
national_id = slnin.Substring(1384, 20)
last_name = slnin.Substring(1650, 30)
first_name = slnin.Substring(1685, 30)
mid_initial = slnin.Substring(1720, 30)
suffix = slnin.Substring(1645, 15)
dept_ID = slnin.Substring(0, 9)
dept = dept_ID
If Left(dept, 3) = "DAS" Then
dept_ID = 100
End If
If Right(dept, 6) >= 101100 And Right(dept, 6) <= 101380 And Left(dept, 3) = "DAS" Then
'If Right(dept, 6) > 1 Then
payroll = "000"
'address1 = payroll
End If
'address1 = slnin.Substring(391, 54)
address2 = slnin.Substring(446, 55)
city = slnin.Substring(501, 30)
state = slnin.Substring(531, 6)
postal = slnin.Substring(537, 12)
phone = slnin.Substring(549, 24)
phone = Replace(phone, "/", "")
phone = Replace(phone, "-", "")
If IsDate(slnin.Substring(341, 10)) = False Then
hire_dt = "01/01/1900"
Else
hire_dt = slnin.Substring(341, 10)
End If
reg_temp = slnin.Substring(52, 1)
full_part_time = slnin.Substring(152, 1)
appt_type = slnin.Substring(5161, 1)
barg_unit = slnin.Substring(320, 4)
oh_bu_flag = slnin.Substring(316, 1)
union_cd = slnin.Substring(317, 3)
jobcode = slnin.Substring(27, 6)
business_title = slnin.Substring(33, 10) ' this did not match up with the layout(job title)
termination_dt = slnin.Substring(361, 10) ' this did not match i thought this was separation date
action = slnin.Substring(68, 3)
action_reason = slnin.Substring(71, 3)
If IsDate(slnin.Substring(1800, 10)) = False Then
pay_period_end = "01/01/1900"
Else
pay_period_end = slnin.Substring(1800, 10)
End If
emp_id = slnin.Substring(10, 11)
empl_rcd = slnin.Substring(21, 3)
class_indc = slnin.Substring(5163, 1) ' this did not match up with the layout(job indicator)
'last_name = last_name.PadRight(25)
'build line to be wrote out
'Dim myStringBuilder As New StringBuilder
'myStringBuilder.Append(national_id + semi)
slnout = national_id + semi
slnout += last_name.Trim.PadRight(30, " ") + semi
slnout += mid_initial + semi
slnout += first_name.Trim.PadRight(30, " ") + semi
slnout += suffix.PadRight(15, " ") + semi
slnout += dept_ID.PadRight(10, " ") + semi
slnout += address1.PadRight(55, " ") + semi
slnout += address2.PadRight(55, " ") + semi
slnout += city.PadRight(30, " ") + semi
slnout += state.PadRight(6, " ") + semi
slnout += postal + semi
slnout += phone.Trim + semi
slnout += hire_dt.ToString("MM/dd/yyyy") + semi
slnout += reg_temp + semi
slnout += full_part_time + semi
slnout += appt_type + semi
slnout += derived_value + semi
slnout += derived_value2 + semi
slnout += barg_unit + semi
slnout += oh_bu_flag + semi
slnout += union_cd + semi
slnout += jobcode + semi
slnout += business_title.PadRight(30, " ") + semi
slnout += derived_value3 + semi
slnout += derived_value4 + semi
slnout += termination_dt + semi
slnout += action + semi
slnout += action_reason + semi
slnout += pay_period_end.ToString("MM/dd/yyyy") + semi
slnout += emp_id + semi
slnout += empl_rcd + semi
slnout += payroll
slnout += class_indc + semi & vbCrLf
outputfile += slnout
'Response.Write(slnout)
'Response.End()
End If
End While
'Response.Write(slnout)
'Response.End()
sr.Close()
'Dim fileout As String = "\newfile" & ".txt"
Try '& FileUpload1.Filename)
File.WriteAllText(Server.MapPath("uploads/newfile.txt"), outputfile)
Catch ex As Exception
''FileUpload1.SaveAs(Server.MapPath("uploads\" & FileUpload1.FileName))
Label1.Text = "Failed because <br/>" & ex.Message
End Try
Label1.Text = "File uploaded to server" '& FileUpload1.PostedFile.FileName
'sr.Close()
'objstreamreader.Close()
'Console.ReadLine()
Else
Label1.Text = "Please select a file to upload"
End If
'Else
'Label1.Text = "Please Choose a Text file only with extension of .txt"
'End If
'Catch ex As Exception
'Response.Write("You did not choose the correct file")
'Response.End()
' End Try
End Sub