how to trap this error....

User avatar
sal21
PlatinumLounger
Posts: 4343
Joined: 26 Apr 2010, 17:36

how to trap this error....

Post by sal21 »

In splitting var i acan have max 2 value, but the second can be =""
HoW to trap this error?
In effect i want to insert in field5 the first member of splitting, and in field6 the second if is >""...

part ofg code

Code: Select all

Dim VAR_SPLIT() As String, INTX As Long, VAR_SPLIT_1 As String
VAR_3 = Trim(Mid(strLine, 171, 12))
            VAR_SPLIT = Split(VAR_3, " ")

            For INTX = 0 To UBound(VAR_SPLIT)
                If VAR_SPLIT(INTX) > "" Then
                RST.Fields(5) = VAR_SPLIT_1
                End If
                If VAR_SPLIT(INTX + 1) > "" Then
                RST.Fields(6) = VAR_SPLIT_1
                End If
            Next

User avatar
HansV
Administrator
Posts: 78393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how to trap this error....

Post by HansV »

Code: Select all

Dim VAR_SPLIT() As String
VAR_3 = Trim(Mid(strLine, 171, 12))
VAR_SPLIT = Split(VAR_3, " ")
RST.Fields(5) = VAR_SPLIT(0)
If UBound(VAR_SPLIT) >= 1 Then
  RST.Fields(6) = VAR_SPLIT(1)
End If
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how to trap this error....

Post by HansV »

Or even simpler:

Code: Select all

Dim VAR_SPLIT() As String, INTX As Long
VAR_3 = Trim(Mid(strLine, 171, 12))
VAR_SPLIT = Split(VAR_3, " ")
For INTX = 0 To UBound(VAR_SPLIT)
  RST.Fields(INTX + 5) = VAR_SPLIT(INTX)
Next INTX
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4343
Joined: 26 Apr 2010, 17:36

Re: how to trap this error....

Post by sal21 »

HansV wrote:Or even simpler:

Code: Select all

Dim VAR_SPLIT() As String, INTX As Long
VAR_3 = Trim(Mid(strLine, 171, 12))
VAR_SPLIT = Split(VAR_3, " ")
For INTX = 0 To UBound(VAR_SPLIT)
  RST.Fields(INTX + 5) = VAR_SPLIT(INTX)
Next INTX
TKS. work now.