Qualifier Error


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Qualifier Error

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Qualifier Error

    [Originally posted by rachael]

    Hi,

    This is my first time program in VBasic.˙ I believe I am having syntax error in my code.

    I have a customer text file which consists of Name, Office Number and address with fixed length as following:

    Alan˙ 123456˙ ABCDEFG
    Maggie87654321ABCDEFG

    I need to read the string and insert into a database.

    My code is as following:

    Function GetFileStrArray(inFileName As String) As Variant
    ˙ ˙ On Error GoTo errHandler
    ˙ ˙ Dim mTextLine As String
    ˙ ˙ Dim arrResult() As String
    ˙ ˙ Dim mHandle
    ˙ ˙ Dim i As Integer
    ˙ ˙ Dim Name As String
    ˙ ˙ Dim Office As String
    ˙ ˙ Dim Address As String
    ˙ ˙ ˙ ˙
    ˙ ˙ gCancel = False
    ˙ ˙
    ˙ ˙ mHandle = FreeFile
    ˙ ˙ Open inFileName For Input As #mHandle
    ˙ ˙ i = 0
    ˙ ˙ Do While Not EOF(mHandle)
    ˙ ˙ ˙ ˙ ˙
    ˙ ˙ ˙ ˙ Line Input #mHandle, mTextLine
    ˙ ˙ ˙ ˙
    ˙ ˙ ˙ ˙ If Len(Trim(mTextLine)) > 0 Then
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ ReDim Preserve arrResult(i)
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ i = i + 1
    ˙ ˙ ˙ ˙ ˙ ˙ ˙
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ Name.arrResult(i) = InStr(1, mTextLine, 6)
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ Office.arrResult(i) = InStr(7, mTextLine, 8)
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ Address.arrResult(i) = InStr(15, mTextLine, 12)
    ˙ ˙ ˙ ˙ End If
    ˙ ˙ Loop
    ˙ ˙ Close #mHandle
    ˙ ˙ GetFileStrArray = arrResult
    ˙ ˙ Exit Function

    How to extract each column from the list and put in a array, so that during the insertion, each field can be called out to be inserted into a database.

    Thanks.


  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Qualifier Error

    [Originally posted by Tarniceru Robert Antonio]

    your code is way too complicated...
    For a beginner, this way is much simplier:
    Just put a command button named cmdDb, a DataControl named dtaDb connected to the table in the database, and four TextField named txtName, txtDay, txtMonth, txtYear, connected to the proper DataField, after you filled the DataSource (which is dtaDb), and the code is that:
    ----------------------------------
    Dim arrResult(100, 4) As String
    Dim strName, DayOfBirth, MonthOfBirth, YearOfBirth As String
    Dim i As Integer

    Private Sub CmdDB_Click()
    For j = 0 To i - 1
    ˙ ˙ dtaDb.Recordset.AddNew
    ˙ ˙ ˙ ˙ txtName.Text = arrResult(j, 1)
    ˙ ˙ ˙ ˙ txtDay.Text = arrResult(j, 2)
    ˙ ˙ ˙ ˙ txtMonth.Text = arrResult(j, 3)
    ˙ ˙ ˙ ˙ txtYear.Text = arrResult(j, 4)
    ˙ ˙ dtaDb.Recordset.Update
    Next j
    End Sub

    Private Sub Form_Load()


    Open "FileName" For Input As #1

    ˙ ˙ i = 0
    ˙ ˙ Do While Not EOF(1)
    ˙ ˙ ˙ ˙ Input #1, strName, DayOfBirth, MonthOfBirth, YearOfBirth
    ˙ ˙ ˙ ˙ arrResult(i, 1) = strName
    ˙ ˙ ˙ ˙ arrResult(i, 2) = DayOfBirth
    ˙ ˙ ˙ ˙ arrResult(i, 3) = MonthOfBirth
    ˙ ˙ ˙ ˙ arrResult(i, 4) = YearOfBirth
    ˙ ˙ ˙ ˙ i = i + 1
    ˙ ˙ Loop
    Close #1

    End Sub

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Qualifier Error

    [Originally posted by Tarniceru Robert Antonio]

    I forget to tell you that your file should look like this:

    "Robert","10","10","1979"
    "Maria","18","12","1978"
    "Anca","29","10","1978"

  4. #4
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Qualifier Error

    [Originally posted by neophile]

    Here's another alternative...

    Option Explicit

    Private Type TextRecord
    ˙ ˙ Name As String * 6
    ˙ ˙ Number As String * 8
    ˙ ˙ Address As String * 12
    End Type

    Private Sub GetRecords(ByVal Filename As String, ByRef RecArray() As TextRecord)
    ˙ ˙ Dim fn As Integer
    ˙ ˙ Dim sData As String
    ˙ ˙ Dim sTmp() As String
    ˙ ˙ Dim i As Integer
    ˙ ˙
    ˙ ˙ fn = FreeFile
    ˙ ˙ Open Filename For Binary Access Read As fn
    ˙ ˙ ˙ ˙ sData = Space(LOF(fn))
    ˙ ˙ ˙ ˙ Get fn, , sData
    ˙ ˙ Close fn
    ˙ ˙ sTmp = Split(sData, vbCrLf)
    ˙ ˙ sData = ""
    ˙ ˙ For i = 0 To UBound(sTmp)
    ˙ ˙ ˙ ˙ If Len(sTmp) = 26 Then
    ˙ ˙ ˙ ˙ ˙ ˙ ReDim Preserve RecArray(i) As TextRecord
    ˙ ˙ ˙ ˙ ˙ ˙ With RecArray(i)
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ .Name = Mid(sTmp(i), 1, 6)
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ .Number = Mid(sTmp(i), 7, 8)
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ .Address = Mid(sTmp(i), 15, 12)
    ˙ ˙ ˙ ˙ ˙ ˙ End With
    ˙ ˙ ˙ ˙ End If
    ˙ ˙ Next
    ˙ ˙ Erase sTmp
    End Sub

    Private Sub Command1_Click()
    ˙ ˙ Dim vData() As TextRecord
    ˙ ˙ Dim i As Integer
    ˙ ˙ GetRecords "mydata.txt", vData
    ˙ ˙ For i = 0 To UBound(vData)
    ˙ ˙ ˙ ˙ RecSet!Name = Trim(vData(i))
    ˙ ˙ ˙ ˙ RecSet!Number = Trim(vData(i))
    ˙ ˙ ˙ ˙ RecSet!Address = Trim(vData(i))
    ˙ ˙ Next
    ˙ ˙ Erase vData
    End Sub


    ... and there's a fine line between 'complicated' and 'extendable' :)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center