correct Syntax of Input
Forums
Hi,
I came across an inconsistency in the scripting Doku of IDEA 8.5 (in german)
a) Objectcatalog : Input[$](Chars As Long, #FileNum As Integer )
b) Tooltip : Input(By Val Number as Integer, By Val FileNumber as Integer) As String
I get the error message:
'Error in Line 41 - Overflow
Line 41 >> Contents2 = Input(Lange2, Filenum)
and Lange2 is 65534. Which is indeed an Overflow if it should be an Integer. (somehow already also indicated by the Definition of the Seek function (Position as Integer)
The question ist then for me : how can I access portions of a text file which are beyond that point. I try to read-in text portion, then process then with iReplace and write them again into another txt-file.
Example of using text files and iReverse
'***************************************************************************************************
'* Script: Import to database.iss
'* Author: Brian Element - brian.element@ideascripting.com
'* Date: Jan 25, 2014
'* Purpose: Example script to show how to input from a text file and placing in a database
'***************************************************************************************************
Option Explicit
Dim sDatabase As String
Sub Main
Call createDatabase() 'Create a new database to import files to
Call addRecords()
client.RefreshFileExplorer
MsgBox "Script complete"
End Sub
Function createDatabase()
Dim db As database
Dim oNewTable As Table
Dim oMyField As Field
sDatabase = Client.UniqueFileName("test")
Set oNewTable = Client.NewTableDef
Set oMyField = oNewTable.NewField
oMyField.Name = "test"
oMyField.Description = "Test field to store text data"
oMyField.Type = WI_CHAR_FIELD
oMyField.Length = 15
oMyField.Equation = " """" "
oNewTable.AppendField oMyField
Set db = Client.NewDatabase(sDatabase, "", oNewTable)
End Function
Function addRecords()
Dim iFilenum As Integer
Dim sContents As String
Dim newDB As database
Dim newRS As RecordSet
Dim newRec As Record
Dim newTable As TableDef
Set newDB = Client.OpenDatabase(sDatabase)
Set newRS = newDB.RecordSet
Set newRec = newRS.NewRecord
Set newTable = newDB.TableDef
newTable.Protect = False
'Optain a new file number
iFilenum = FreeFile
Open "test.txt" For Input As iFilenum
Do While Not EOF(iFilenum)
Line Input #iFilenum, sContents
'MsgBox iReverse(sContents)
newRec.SetCharValue "TEST", sContents
newRs.AppendRecord newRec
newRec.ClearRecord
Loop
newTable.Protect = True
close iFilenum
End Function
'***************************************************************************************************
'* Script: Save to text file.iss
'* Author: Brian Element - brian.element@ideascripting.com
'* Date: Jan 25, 2014
'* Purpose: Example script to show how to input and output a file
'***************************************************************************************************
Option Explicit
Dim sDatabase As String
Sub Main
Call addRecords()
MsgBox "Script complete"
End Sub
Function addRecords()
Dim iFilenum1 As Integer
Dim iFilenum2 As Integer
Dim sContents As String
'Optain a new file number
iFilenum1 = FreeFile
Open "test.txt" For Input As #iFilenum1
iFilenum2 = FreeFile
Open "test2.txt" For Output As #iFilenum2
Do While Not EOF(iFilenum1)
Line Input #iFilenum1, sContents
sContents = iReverse(sContents)
Write #iFilenum2, sContents
Loop
Close iFilenum1
Close iFilenum2
End Function
Well I think the input should
Well I think the input should be long and not an integer. Integer is only good to about 32,000. So I think for b) it should be:
Input(By Val Number as Long, By Val FileNumber as Integer) As String
So in this instance Lange2 would be long and you won't get the overflow error. I will test it out his weekend and get back to you.