5 Replies - 1561 Views - Last Post: 05 August 2009 - 11:31 PM Rate Topic: -----

#1 renmee  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 158
  • Joined: 20-July 09

Help with my code Subscript out of range

Posted 03 August 2009 - 09:21 PM

some of the file i inputted in ms acces are not saving
Private Sub ExtractData(ByVal Lot As String)
Dim fso As New FileSystemObject
Dim ts As TextStream
Dim str_read As String, mfg_info As String, tlNo As String
Dim tl_len As Double, ctr As Double, dataproc As Boolean
Dim x_val As Double, y_val As Double, x_val2 As Double
Dim dateval, temp, temp2, tothrs, tothrs2, sdate As Date, edate As Date
Dim tlsdate As Date, tledate As Date, dateval2

	
	sdate = CDate(Format(txtefcsdate.Text, "mm/dd/yyyy hh:mm:ss"))
	edate = CDate(Format(txtefcedate.Text, "mm/dd/yyyy hh:mm:ss"))
	
	tlsdate = CDate(Format(txttlsdate.Text, "mm/dd/yyyy hh:mm:ss"))
	tledate = CDate(Format(txttledate.Text, "mm/dd/yyyy hh:mm:ss"))
		
	tothrs = DateDiff("n", sdate, edate)
	tothrs = Round(tothrs / 60, 2)
	
	tothrs2 = DateDiff("n", tlsdate, tledate)
	tothrs2 = Round(tothrs2 / 60, 2)

	Set ts = fso.OpenTextFile(File1.Path & "\" & Lot & ".txt", ForReading)
				  
	Dim defIndex, defName

		defIndex = GetIniFileVal("PROGRAM", "DEF_INDEX")
		defName = Split(GetIniFileVal("PROGRAM", "DEFECTS"), ",")
	
	ctr = 0
	Do While Not ts.AtEndOfStream
		ctr = ctr + 1
		str_read = ts.ReadLine
			  
				
		If InStr(str_read, "Shiny") <> 0 Then
			dataproc = True
		End If
				
		'get data
				If ctr = 4 Then
			'Get Info and TL No
			mfg_info = Split(str_read, "|")(0)
			tlNo = Left(Split(str_read, "|")(1), 1)
		ElseIf ctr = 8 Then
			'get Tl Len
			tl_len = Round(Val(Split(str_read, "|")(0)), 1)
						
			Execute_DML ("Insert into AOI_main (mfg_info,date_start,date_end,f_len,tl_no,tl_sdate,tl_edate) values('" & _
				mfg_info & "','" & sdate & "','" & edate & "'," & tl_len & ",'" & tlNo & "','" & tlsdate & "','" & tledate & "')")
				
		ElseIf dataproc Then
			If str_read = "EOV" Then
				Exit Do
			ElseIf CheckIniVal(Split(str_read, "|")(1), defIndex) Then
				Dim code As String, def_code As String
				
				code = Split(str_read, "|")(1)
											
				def_code = defName(code - 1)
			
				''' true dates
				x_val = Round(Val(Split(str_read, "|")(4)), 1)
				x_val2 = Round(tl_len - x_val, 1)
				y_val = Round(Val(Split(str_read, "|")(9)), 1)
								
				temp = (x_val2 / tl_len) * tothrs
				temp2 = temp
				
				dateval = DateAdd("h", Val(Round(temp, 0)), sdate)
				temp = temp2 - Round(temp, 0)
				temp = temp * 60
				dateval = DateAdd("n", Val(temp), dateval)
				''''''''''==================
				
				temp = 0: temp2 = 0
				temp = (x_val / tl_len) * tothrs2
				temp2 = temp
				dateval2 = DateAdd("h", Val(Round(temp, 0)), tlsdate)
				temp = temp2 - Round(temp, 0)
				temp = temp * 60
				dateval2 = DateAdd("n", Val(temp), dateval2)
				'''end true dates
				
				If InStr(LCase(def_code), "dent") Then
					Execute_DML ("Insert into Dents_data (mfg_info,x_val,y_val,date_val,def_cat,tl_dateval,efc_xval) values('" & _
						mfg_info & "'," & x_val & "," & y_val & ",'" & dateval & "','" & def_code & "','" & dateval2 & "'," & x_val2 & ")")
				ElseIf InStr(LCase(def_code), "pit") Then
					Execute_DML ("Insert into Pits_data (mfg_info,x_val,y_val,date_val,def_cat,tl_dateval,efc_xval) values('" & _
						mfg_info & "'," & x_val & "," & y_val & ",'" & dateval & "','" & def_code & "','" & dateval2 & "'," & x_val2 & ")")
				ElseIf InStr(LCase(def_code), "bright object") Then
					Execute_DML ("Insert into BrObject_data (mfg_info,x_val,y_val,date_val,def_cat,tl_dateval,efc_xval) values('" & _
						mfg_info & "'," & x_val & "," & y_val & ",'" & date_val & "','" & def_code & "','" & date_val2 & "'," & x_val2 & ")")
				ElseIf InStr(LCase(def_code), "dark object") Then
					Execute_DML ("Insert into DrObject_data (mfg_info,x_val,y_val,date_val,def_cat,tl_dateval,efc_xval) values('" & _
						mfg_info & "'," & x_val & "," & y_val & ",'" & date_val & "','" & def_code & "','" & date_val2 & "'," & x_val2 & ")")
				End If
			End If
		End If
		
	Loop
	ts.Close
	

	
	'create archiving folder & copy processed file to the archived folder
	If Not fso.FolderExists(File1.Path & "\" & Mid(mfg_info, 8, 1)) Then fso.CreateFolder File1.Path & "\" & Mid(mfg_info, 8, 1)
	fso.CopyFile File1.Path & "\" & cmbLot.Text & ".txt", File1.Path & "\" & Mid(mfg_info, 8, 1) & "\"
	Kill File1.Path & "\" & Lot & ".txt"
	
	FillLotNo
	MsgBox "Record Saved!"
	Me.SetFocus
End Sub

the error line is:
def_code = defName(code - 1)

if i changed it to def_code =defName(code) it saves other data and ignore other data
Please help me with this Thank you so much!!

is there some thing wrong the way i split the records?

Is This A Good Question/Topic? 0
  • +

Replies To: Help with my code Subscript out of range

#2 renmee  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 158
  • Joined: 20-July 09

Re: Help with my code Subscript out of range

Posted 03 August 2009 - 09:33 PM

what is expected array error?
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Help with my code Subscript out of range

Posted 03 August 2009 - 09:37 PM

Sounds like you're trying to use a function or method that is expecting an array as a parameter? We wont know until you show us the code that's causing the error, along with the exact error message :)
Was This Post Helpful? 0
  • +
  • -

#4 renmee  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 158
  • Joined: 20-July 09

Re: Help with my code Subscript out of range

Posted 03 August 2009 - 09:59 PM

i have posted my code look for subscript out of range, thnx for your reply

sir my code is on topic Help With my Code subscript out of range

View PostPsychoCoder, on 3 Aug, 2009 - 08:37 PM, said:

Sounds like you're trying to use a function or method that is expecting an array as a parameter? We wont know until you show us the code that's causing the error, along with the exact error message :)

what should i do then?
Was This Post Helpful? 0
  • +
  • -

#5 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,607
  • Joined: 17-April 07

Re: Help with my code Subscript out of range

Posted 04 August 2009 - 02:42 AM

i think it's the solution
if (code-1)>=0 and (code-1)< ubound (defname) then
def_code = defName(code - 1)
else
continue
endif


i sure this will solve your error
but check out the logic in your code
if this section
Was This Post Helpful? 0
  • +
  • -

#6 renmee  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 158
  • Joined: 20-July 09

Re: Help with my code Subscript out of range

Posted 05 August 2009 - 11:31 PM

View Postthava, on 4 Aug, 2009 - 01:42 AM, said:

i think it's the solution
if (code-1)>=0 and (code-1)< ubound (defname) then
def_code = defName(code - 1)
else
continue
endif


i sure this will solve your error
but check out the logic in your code
if this section

Thank you so much!! ill try it
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1