Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 25th, 2004, 01:47 PM
Authorized User
 
Join Date: Jan 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Frustrations of Split(long)

I am driving myself mad trying to get something simple to work. SOmeone here is going to laugh at what I am missing....

I have a string returned from reading a file (its going to form part of an automated import process). Being a bit of a pig it's seperated with semicolons (;)

I need to break it down into fields from this and recall the split method from my asp days. Dug out my trusty old wrox 'begining asp' to refer to the reference section in the back (missing from begining access 2000 vba) but I cannot get it to work.Ive gone through the msdn examples but they are a little lack-lusture.

I seem to be running into dificulty in assigning the return from split into an array of any kind. I think this may be simply down to not knowing the exact syntax for assigning the return from split (which will be unknown at runtime and dynamic) to an array.

I have tried:>
newarray = Split(impGetString, ";")
newarray() = Split(impGetString, ";")

Anyone have a solution????




 
Old January 25th, 2004, 04:45 PM
Authorized User
 
Join Date: Nov 2003
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I perform this method in several functions in an application I'm working on to split an employee name into the first and last name elements. The syntax in your post is correct. The only thing I don't know is whether or not you declare your array.
Code:
 dim newarray() as string
Do you have any other information such as an error that is raised or anything else that could help determine the cause?



 
Old January 26th, 2004, 02:41 AM
Authorized User
 
Join Date: Jan 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When you say the syntax is correct - which one!

(1) newarray = Split(impGetString, ";")
OR
(2) newarray() = Split(impGetString, ";")

I do declare the array as I'm using option explicit but you hay have highlighted an error. The reference I had on it was dim newarray() as integar - which I thought was odd myself....

I will run it around again later and come back with the errors it generates.

Thanks for your input.


 
Old January 26th, 2004, 11:27 AM
Authorized User
 
Join Date: Nov 2003
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I apologize for omitting that bit of information before. The proper syntax is as your exhibit (1).

I don't think it should be a problem if you declare your array as an array of integer values. The one thing to remember is that if the string you are breaking down is a string of numeric values, the integer data type is only valid for numbers from -32,768 to 32,767. If any of the values in the string exceed either of these limits, you will receive a run time error. Also, the integer data type is only for whole numbers, that means no values to the right of the decimal. The same goes for the long data type. If the values in your string contain rational numbers (values to the right of the decimal point), you should declare a data type of single or double.

One other thing to consider might be to declare your array as variant and let the application decide the sub-data type for each element for the array.

I hope this helps. Good luck.

 
Old January 26th, 2004, 12:20 PM
Authorized User
 
Join Date: Jan 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Scrub the post below - got the problem. It was in the variable definition. I opted for: Dim tmpArray() As Variant which gave mismatch error where as Dim tmpArray As Variant worked. Ummm.
When is an array not an array.........

IGNORE<><><> LEFT IN SITU FOR REFERENCE <><><><>

Still no go. Throws Error 13 (Type mismatch and highlights the last line): Have tried converting the contents of the variable impGetString to a string prior to executing the command as well. No joy. On the first run variable impGetString contains "E:\_MASTER_SHARES\MUSIC\2003\Alex Parks - Over Conscious(cd).mp3;041.50;Alex Parks;Over Conscious(cd);version;album name;pop;2003;comment;0;0;0;;0;0;;0;0;;0;0;;0;0;;0 ;0;;0;0;;0;0;;0;0;;0;0;;0;0;;0;0;;0;0;;0;0;;0;0;;0 ;0;;0;0;;0;0;;0;0;;0;0;"

Dim tmpArray() As Variant

Open "d:\data_projects\import.txt" For Input As #1
Input #1, impGetString ' gets one line from text file
' split up string into sub data
tmpArray = Split(impGetString, ";")
 
Old January 26th, 2004, 12:28 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You should drop the parentheses when you declare a Variant array. The Variant type is able to hold an array:

Dim tmpArray As Variant

Alternatively, declare the array as a String:

Dim tmpArray() As String

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 27th, 2004, 04:19 PM
Authorized User
 
Join Date: Jan 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorted this one out - many thanks for all of your help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to split a long string with tab delimited Andraw SQL Server 2005 27 July 17th, 2008 05:38 PM
output frustrations, please help! mellan XSLT 1 August 22nd, 2005 11:10 AM
Split a long vedio to several parts Andraw Classic ASP Basics 0 May 3rd, 2005 10:58 AM
Modifying long text in a long field sajsal Classic ASP Databases 1 February 20th, 2004 12:36 PM
Datagrid Frustrations rob225 Pro VB 6 0 December 30th, 2003 11:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.