Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to get first 5 digits from long data type in vb6.
I am storing my data in variant

What I have tried:

I am trying with left$ function but unable to get it
Posted
Updated 15-May-17 23:43pm
v2
Comments
Suvendu Shekhar Giri 16-May-17 5:40am    
Make sure you have converted it to string prior to use the left$ function.

1 solution

You will have to check the syntax of this because I'm not installing VB6 just for this (or much else to be honest).
VB
Dim along As Variant
along = 123549512
Dim longAsString As String
longAsString = CStr$(long)
Dim res as String
res = Left$(longAsString, 5)


[Edited to change Str$ to CStr$ .. the former includes a space for the sign of the number, the latter does not. Alternatively could have taken the string from the 2nd character, but that is not as clear)

[Edited to fix the syntax error with Left$ spotted and corrected by @RichardDeeming - thank you]
 
Share this answer
 
v3
Comments
Richard Deeming 16-May-17 10:11am    
IIRC, the Left function only takes two arguments: the string, and the number of characters to return. It should be:
res = Left$(longAsString, 5)
CHill60 17-May-17 4:43am    
Cheers ... I've used the syntax for Mid$ instead. I'll correct the error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900