Current location: Hot Scripts Forums » Programming Languages » ASP » Firs two characters of a var


Firs two characters of a var

Reply
  #1 (permalink)  
Old 08-17-03, 01:41 PM
Tesco Tesco is offline
ASP Guru
 
Join Date: Jun 2003
Location: UK
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Firs two characters of a var

Hello.
How do I get the first to characters of a var? I was told I needed to use Left() or something? Could some please explain how to use this sub properly?
TIA
Reply With Quote
  #2 (permalink)  
Old 08-17-03, 02:41 PM
Shane Shane is offline
Coding Addict
 
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
Try:


Code:
Dim strThing, strTwo
strThing = "hello"

strTwo = Left(strThing, 2)
Usage for the Left function:

Left(STRING_HERE, LENGTH_HERE)
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
Reply With Quote
  #3 (permalink)  
Old 08-17-03, 03:03 PM
Tesco Tesco is offline
ASP Guru
 
Join Date: Jun 2003
Location: UK
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, that worked.

But, I need a little more help.

I'm doing this to get the first two characters of two dates (i.e. they're day), which I can do successfully now.

But, later in my code, I try to subtract one from the other, but I get 'type mismatch' error on the line that performs this arithimatic.

Could you help?
Ta.
Reply With Quote
  #4 (permalink)  
Old 08-17-03, 03:06 PM
Shane Shane is offline
Coding Addict
 
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
Are you trying to find the difference between two dates? If so, then there is an easier way to do so. (http://msdn.microsoft.com/library/de...ctdatediff.asp)

But anyway, try converting your variables to integers using:

Code:
intTwo = cint(strTwo)
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL

Last edited by Shane; 08-17-03 at 03:11 PM.
Reply With Quote
  #5 (permalink)  
Old 08-17-03, 03:13 PM
Tesco Tesco is offline
ASP Guru
 
Join Date: Jun 2003
Location: UK
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Tried that, still get type mismatch error.

Yeah, I am comparing to dates, but I thought that DateDiff() only worked on SQL Server? I don't have access to that
Reply With Quote
  #6 (permalink)  
Old 08-17-03, 03:21 PM
Shane Shane is offline
Coding Addict
 
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally posted by Tesco
Tried that, still get type mismatch error.

Yeah, I am comparing to dates, but I thought that DateDiff() only worked on SQL Server? I don't have access to that
Nah, you don't need SQL Server. You just have to make sure your two dates are in the form of the Date data type.

This should work....

Code:
firstDate = CDate(strDate)
secondDate = CDate(strDateTwo)

theDifference = DateDiff("d",firstDate, secondDate)
Also, if you want me to help fix your existing code, please post it so I can see what you are doing.

BTW: this is a great reference.. http://msdn.microsoft.com/library/de...ctdatediff.asp
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
Reply With Quote
  #7 (permalink)  
Old 08-17-03, 03:55 PM
Tesco Tesco is offline
ASP Guru
 
Join Date: Jun 2003
Location: UK
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Shane, got it working with DateDiff()
Reply With Quote
  #8 (permalink)  
Old 08-17-03, 05:37 PM
Shane Shane is offline
Coding Addict
 
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
Not a problem.
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with disallowing characters in user signup Ted PHP 7 01-14-04 11:44 AM
accented characters in MySQL gwdguy PHP 0 09-20-03 04:59 PM


All times are GMT -5. The time now is 03:16 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.