Dec 8th, 2006, 01:12 PM
#1
Thread Starter
Addicted Member
what is the problem in my code
i wrote this code to insert word from (newoutfile.txt ) which have a list of words
between brackets in (outfile.txt)
the problem is when i run it an error displyed in the first run
(subscript out of range ) pointing to this line
and if ii run it again for the same text and without ghanging in the code
no errors appears
why?
why in the first run there is error, but second there is no error ?
Dec 8th, 2006, 01:15 PM
#2
Re: what is the problem in my code
what is the value of X, when it runs and when it does not
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
Dec 8th, 2006, 01:32 PM
#3
Re: what is the problem in my code
Also how are tmp and X defined, and are you using Option Explicit?
Dec 8th, 2006, 04:09 PM
#4
Thread Starter
Addicted Member
Re: what is the problem in my code
yes i'm using Option Explicit
see my code please
VB Code:
Sub insword()
Dim pos1 As Long, pos2 As Long, i As Integer, X As Integer
Dim file As String, line As String, word As String
Dim tmp() As String
file = vbNullString
i = 0
X = 0
Open "C:\newoutfile.txt" For Input As #1
tmp = Split(Input(LOF(1), 1), vbCrLf)
Close #1
Open "C:\outfile.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, line
i = i + 1
pos1 = InStr(1, line, "(")
pos2 = InStr(1, line, ")")
If pos1 > 0 And pos2 > 0 Then
word = Mid(line, pos1 + 1, pos2 - pos1 - 1)
If word <> "GLOSS" Then
word = tmp(X)
X = X + 1
End If
line = Left(line, pos1 - 1) & "(" & word &
")" & Right(line, Len(line) - pos2)
End If
If i = 1 Then
file = line
Else
file = file & vbCrLf & line
End If
Loop
Close #1
Open "C:\outfile.txt" For Output As #1
Print #1, file
Close #1
End Sub
Dec 8th, 2006, 04:12 PM
#5
Re: what is the problem in my code
Could you also put newoutfile.txt in a zip file and attach it?
Dec 8th, 2006, 04:37 PM
#6
Thread Starter
Addicted Member
Re: what is the problem in my code
Hi MartinLiss...
I attach file newoutfile.txt
Attached Files
Dec 8th, 2006, 01:31 PM
#7
Re: what is the problem in my code
subscript out of range is when your index value is greater then the bounds of the array or collection. So I would assume that you have a value in x that is either too large or your array is not dimensioned correctly.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Dec 8th, 2006, 04:33 PM
#8
Hyperactive Member
Re: what is the problem in my code
Nothing wrong, but it makes a strange text file in the output.
What is the intention?
Dec 8th, 2006, 05:07 PM
#9
Re: what is the problem in my code
If your newoutfile.txt is blank then it will give the subscript error.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Dec 10th, 2006, 01:33 PM
#10
Thread Starter
Addicted Member
Re: what is the problem in my code
i'm using a shell command befor this function
actually newoutfile.txt is the output of this shell command
this is the code
VB Code:
'open command prompt to run Python script
Open Apath & "dos.bat" For Output As #1
Print #1, "cd C:\python24"
Print #1, "buckwalter2unicode.py -i C:\buckwalter_morphan_1\data\newfile.txt -o C:newoutfile.txt -E mbcs"
' Print #1, "buckwalter2unicode.py -i C:\buckwalter_morphan_1\data\newfile.txt -o C:newoutfile.txt "
Close #1
' ShellAndWait Apath & "dos.bat"
Shell Apath & "dos.bat"
i allways checking the newoutfile.txt it's always there "not empty"
i don't understand what's the problem
Dec 10th, 2006, 02:10 PM
#11
Hyperactive Member
Re: what is the problem in my code
What is the value of X when you get the error?
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width