473,473 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Left Function

1 New Member
Hi i am having a problem tryin to read a string up to a chr(). The code looks like this:




strMonth = Left(strStartDate, chr(47))

what i want it to do is read the string from the left and stop when it gets to the chr(47) which is "/", but it gives me an error saying "type mismatch". Can someone tell me why this isn't working? Thanks
Feb 13 '07 #1
7 2694
ADezii
8,834 Recognized Expert Expert
Hi i am having a problem tryin to read a string up to a chr(). The code looks like this:




strMonth = Left(strStartDate, chr(47))

what i want it to do is read the string from the left and stop when it gets to the chr(47) which is "/", but it gives me an error saying "type mismatch". Can someone tell me why this isn't working? Thanks
You have the wrong Syntax for Left() and you are missing another required Function. This will work:
Expand|Select|Wrap|Line Numbers
  1. Dim strString As String, strSearchString As String
  2.  
  3. strString = "Yabbadabba/Doo"
  4. strSearchString = "/"
  5.  
  6. Debug.Print Left$(strString, InStr(strString, strSearchString) - 1)
  7.  
  8. 'Output: Yabbadabba
Feb 13 '07 #2
NeoPa
32,556 Recognized Expert Moderator MVP
Another way is to say :
Expand|Select|Wrap|Line Numbers
  1. Dim strString As String, strSearchString As String
  2.  
  3. strString = "Yabbadabba/Doo"
  4. strSearchString = "/"
  5.  
  6. Debug.Print Split(strString, strSearchString)(0)
  7. Output: Yabbadabba
This also handles (automatically and without error) the case of there being no "/" character in the main string.
Feb 14 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
Alternatively, if you prefer to use the chr(47) adapting ADezii's code slightly

Expand|Select|Wrap|Line Numbers
  1.  
  2. strMonth = Left(strStartDate, InStr(strStartDate, chr(47)))
Feb 14 '07 #4
ADezii
8,834 Recognized Expert Expert
Alternatively, if you prefer to use the chr(47) adapting ADezii's code slightly

Expand|Select|Wrap|Line Numbers
  1.  
  2. strMonth = Left(strStartDate, InStr(strStartDate, chr(47)))
Mary:
Wouldn't that leave the Trailing Backslash?
Feb 14 '07 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
Mary:
Wouldn't that leave the Trailing Backslash?
You are right of course.

Should be ..

Expand|Select|Wrap|Line Numbers
  1.  strMonth = Left(strStartDate, InStr(strStartDate, chr(47))-1)
Feb 15 '07 #6
NeoPa
32,556 Recognized Expert Moderator MVP
I still think you're better advised to use Split() rather than Left() and InStr() (See post #3).
Feb 15 '07 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
I still think you're better advised to use Split() rather than Left() and InStr() (See post #3).
I agree, just thought it was worth posting the correct syntax for the Left function. ;)
Feb 15 '07 #8

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

Similar topics

15
by: lawrence | last post by:
Sorry for the dumb question but I'm new to Javascript. I wrote this script hoping to animate some div blocks on a page. You can see the page here: http://www.keymedia.biz/demo.htm Can anyone...
1
by: Martin Lira | last post by:
Hi, I have a webapp that has several jsp pages. The main page has a left nav and it loads the sub pages when requested. Can somebody please give an easy way to track the jsp page you are currently...
5
by: gsb | last post by:
I track the mouse location like this code: function mousePos(e) { var p = new Object(); if(e) { p.x = e.pageX; p.y = e.pageY; } else { p.x = event.x; p.y = event.y; } ... (show) }...
17
by: Nathan Given | last post by:
Hello All, I am trying to debug a broken query. The query uses Left$(,4) instead of Left(,4). What is the difference between the Left() and Left$() functions in Microsoft Access? Thanks!...
4
by: Agnes | last post by:
in .net , any left function ?? or I should use Microsoft.VisualBasic.Left(myString, 5) Thanks
18
by: Jm | last post by:
Hi all I feel stupid for asking this, but i just went to use the left() function from vb6 only to find it doesnt do what it used to under .NET. Im assuming theres something else now im meant to...
8
by: marco | last post by:
Hi ! I have this part of code and i can not find out why the scroller is starting from left to right instead RIGHT to LEFT. This is the main part and the scroller is working fine but from the...
9
by: sql guy123 | last post by:
I normally use MS ACCESS vs MS SQL,, which has a left() and right() function. I need to use MS SQL for this project but I am not familiar with it. I have read a few books, but can not figure out...
6
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have two questions with regards to the LEFT function. I ran into a problem with the LEFT function today. I knew it was a valid Function, but when I tried to use it, it was getting interpreted...
1
by: Lagon666 | last post by:
Hi How can i stick tabs to left. Now it has 40px distance to left. <style> #Content { background-color: #fafafa; border: 1px solid #a2b6cb; padding: 10px;
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.