Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 18th, 2004, 11:52 PM
Authorized User
 
Join Date: Aug 2004
Location: rogers, ar, USA.
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
Reply With Quote
  #2 (permalink)  
Old August 19th, 2004, 06:49 AM
Friend of Wrox
Points: 3,947, Level: 26
Points: 3,947, Level: 26 Points: 3,947, Level: 26 Points: 3,947, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,150
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
Reply With Quote
  #3 (permalink)  
Old August 19th, 2004, 08:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #4 (permalink)  
Old August 19th, 2004, 12:37 PM
Registered User
 
Join Date: Aug 2004
Location: , , .
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))



Reply With Quote
  #5 (permalink)  
Old August 19th, 2004, 12:46 PM
Authorized User
 
Join Date: Aug 2004
Location: rogers, ar, USA.
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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



All times are GMT -4. The time now is 06:14 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.