473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Re-spliting a split - Type Mismatch

vbscript: Spilt Issue

My text files are delimited as follows:
Record Delimiter: vbCRLF
Field Delimiter: ~

I need to break each record apart based on the first field which defines the type of record (ex: LIN contains the part number as the 4th field ).


When I run my script I continue to get a Type Mismatch error relating to the arrFieldList. How do I correct this issue?


Example Data:

(vbCRLF is at the end of each line)

LIN~1~BP~0950-4381~EC~-~VP~-
UIT~EA
FST~0~D~D~20071118



Code:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("Seagate.txt", ForReading)

Do While objTextFile.AtEndOfStream<>True
strNextLine = objTextFile.Readline
RecDiv = Mid (strNextLine,106,1)
FieldDiv = Mid (strNextLine,104,1)
strRecList = Split(strNextLine , RecDiv)

redim arrFieldList(ubound(strRecList))
For i = 1 to ubound(strRecList)
wscript.echo "Write RecList: " & strRecList(i)
arrFieldList = Split(strRecList(i), "~")

For j = 0 to ubound(arrFieldList)
If arrFieldList(j) = "LIN" Then
wscript.echo "Lin Rec: Part: " & arrFieldList(j+3)
End If
Next
' Wscript.Echo "Service: " & arrFieldList(j)
Next



Loop


Regards,

S
Dec 6 '07 #1
2 2690
kadghar
1,295 Expert 1GB
vbscript: Spilt Issue

My text files are delimited as follows:
Record Delimiter: vbCRLF
Field Delimiter: ~
...

S
vbCRLF is chr(10) & chr(13) that are for next line and car return. you can only search for one of them as the Line Delimiter

lets say your Str1 is
one~two~three~four
five~six~seven~eight
nine~ten~eleven~twelve

I will use an split for Chr(10) and then the Split for "~"
Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. Dim Arr1() As String
  3. Dim Arr2()
  4. Arr1 = Split(str1, Chr(10))
  5. For i = LBound(Arr1) To UBound(Arr1)
  6.     ReDim Preserve Arr2(0 To i)
  7.     Arr2(i) = Split(Arr1(i), "~")
  8. Next
As you can see, this code give you Arr2 as the matrix we needed, but depending on the version of VB it'll have to be a Variant and it'll be a jagged array.

Jagged array is an array of arrays, so instead of have Arr2(i,j) you'll have Arr2(i)(j).

HTH
Dec 6 '07 #2
HTH,

Thank you for the response.
I actually need to add an additional detail: My code is for a WSF so I cannot define variables to the nth degree.

Still working to resplit my split.

S




vbCRLF is chr(10) & chr(13) that are for next line and car return. you can only search for one of them as the Line Delimiter

lets say your Str1 is
one~two~three~four
five~six~seven~eight
nine~ten~eleven~twelve

I will use an split for Chr(10) and then the Split for "~"
Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. Dim Arr1() As String
  3. Dim Arr2()
  4. Arr1 = Split(str1, Chr(10))
  5. For i = LBound(Arr1) To UBound(Arr1)
  6.     ReDim Preserve Arr2(0 To i)
  7.     Arr2(i) = Split(Arr1(i), "~")
  8. Next
As you can see, this code give you Arr2 as the matrix we needed, but depending on the version of VB it'll have to be a Variant and it'll be a jagged array.

Jagged array is an array of arrays, so instead of have Arr2(i,j) you'll have Arr2(i)(j).

HTH
Dec 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would...
4
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
1
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
4
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function...
1
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with...
10
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
8
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
8
by: Lothar Scholz | last post by:
Because PHP5 does not include the mysql extension any more is there a chance that we will see more Providers offering webspace with Firebird or Postgres Databases ? What is your opinion ? I must...
1
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.