Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 August 18th, 2004, 11:52 PM
Authorized User
 
Join Date: Aug 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Split Function type mismatch error

Hey Guys,

I am getting a type mismatch error when I attempt to split a string.
Here is what I have tryed so far:

Dim st As String
Dim t As String

st = "now then"
t = Split(st, vbTab)
MsgBox t

this give a type mismatch error. I also tried this:

dim v as variant
v = split(st, vbTab)
MsgBox v

This also gives a type mismatch error. I also tried this:

dim arr(2) as string
arr = split(st, vbTab)
msgbox arr(0)

This give a "can't assign array" error.


Any suggestions will be 100% appreciated. Thanks

Ryan

nikotromus
__________________
nikotromus
 
Old August 19th, 2004, 06:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Although you think that vbTab is a string character consisting of a tab, it is not. The intrinstic constant vbTab is a number (I forget if it's a byte or integer) and is used in leiu of CHR(9) for easy concatenation of strings for programers. Try using CHR(9) instead of vbTab and see if you still get a type mismatch error. If so, then tabs are not treated as string characters by the SPLIT function.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old August 19th, 2004, 08:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

The type mismatches come at different places in each of the 3 code snippets you posted, that's why you're getting confused.

For starters, Split returns an array so your 1st one "Dim t As String" is no good.

Your 2nd one, dim v as variant, is fine. A Variant can contain an array so that's OK. Your Type Mismatch in this case comes from the line "MsgBox v". MsgBox can't work on an array - had you put "MsgBox v(0)" it would have been fine.

Your 3rd one "dim arr(2) as string" is no good because you have sized the array in advance. Had you used "dim arr() as string" instead then this one would be fine too.

hth
Phil
 
Old August 19th, 2004, 12:37 PM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default


The problem is that there is no 'TAB' in the input string. When you type in code in the IDE and hit the tab key it converts the to the appropriate amount of spaces.

For example type in the following and hit the tab key after typing s = "A
Then type B"

s = "A B"
L = Len(s)

It looks like a tab but L will be 5 not 3!!!!

To put the tab in use this syntax:
    st = "A" & vbTab & "B" & vbTab & "C"
    v = Split(st, vbTab)
    MsgBox (v(0) & " " & v(1) & " " & v(2))



 
Old August 19th, 2004, 12:46 PM
Authorized User
 
Join Date: Aug 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You guys are completely awesome. PgTips solved my first problem of the type mismatch, and LarryT solved my second problem of not reading a tab because there really was no tab there in the first place.

Thank you all very much. You solved a big headache for me.

Ryan

nikotromus





Similar Threads
Thread Thread Starter Forum Replies Last Post
Type Mismatch error Sheraz Khan Classic ASP Basics 0 May 16th, 2007 08:12 AM
Using a user defined type and the Split Function nikotromus Access VBA 2 August 20th, 2004 12:02 PM
Dlookup function giving Type Mismatch error Ron V Access 2 May 19th, 2004 01:31 PM
Data Type mismatch error clueless_may Access VBA 1 May 5th, 2004 09:16 AM
Data Type Mismatch error transcona Classic ASP Databases 4 June 25th, 2003 07:23 PM





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