UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Remove Vbcrlf From Front Of String..?, Access 2010    
 
   
Larry Larsen
post Mar 2 2018, 12:11 PM
Post#1


UA Editor + Utterly Certified
Posts: 24,172
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


Hi

I'm building up a string that initially includes [VbCrLf] to build a vertical style string..

This creates a space at the beginning of the final string..

eg:
CODE
LstString = LstString & vbCrLf & dtDay & " " & WeekdayName(Weekday(dtDay, vbMonday))


Q: How would I go about removing that first instance of VbCrLf...??

Some how "trim" the string..!!
thumbup.gif
Go to the top of the page
 
theDBguy
post Mar 2 2018, 12:15 PM
Post#2


Access Wiki and Forums Moderator
Posts: 73,276
Joined: 19-June 07
From: SunnySandyEggo


Hi Larry,

You could try something like:

Mid(LstString,3)

Hope it helps...
Go to the top of the page
 
Larry Larsen
post Mar 2 2018, 12:27 PM
Post#3


UA Editor + Utterly Certified
Posts: 24,172
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


Hi..
Many that's worked a treat...

Was playing with the Left/Right functions and forgot about the Mid()

Interesting in knowing that number (3)
thumbup.gif
Go to the top of the page
 
theDBguy
post Mar 2 2018, 12:40 PM
Post#4


Access Wiki and Forums Moderator
Posts: 73,276
Joined: 19-June 07
From: SunnySandyEggo


Cheers! cheers.gif
Go to the top of the page
 
BananaRepublic
post Mar 2 2018, 12:47 PM
Post#5


Dungeon Cleaner
Posts: 1,512
Joined: 16-June 07
From: Banana Republic


FWIW, this is more portable and a bit more self-documenting:

CODE
Mid$(LstString, Len(vbCRLf) + 1)


Which essentially is the same as theDBGuy's suggestion but at least you know why it's "3".
Go to the top of the page
 
Larry Larsen
post Mar 2 2018, 12:54 PM
Post#6


UA Editor + Utterly Certified
Posts: 24,172
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


thumbup.gif notworthy.gif
Go to the top of the page
 
theDBguy
post Mar 2 2018, 12:58 PM
Post#7


Access Wiki and Forums Moderator
Posts: 73,276
Joined: 19-June 07
From: SunnySandyEggo


Hi BR,

Thanks for the assist. My question is, do you prefer Mid$() over Mid()? If so, why please? Thanks.
Go to the top of the page
 
BananaRepublic
post Mar 2 2018, 01:13 PM
Post#8


Dungeon Cleaner
Posts: 1,512
Joined: 16-June 07
From: Banana Republic


Generally speaking, I prefer the string version of the function over the variant version of same. It really don't make sense to run stuff like this:

CODE
Dim InputString As String
Dim OutputString As String

InputString = "Hello, world!"
OutputString = Mid(InputString, 7)


Here, everything is a string but the Mid() returns a variant so there's now an implicit conversion... why?

I don't do this because Mid$() is faster than Mid() (it is but on oh too small a scale to even notice), but rather because I try my hard to avoid any implicit conversions which will always hide bugs in my code. To illustrate further...

CODE
Debug.Print Mid(Me.MyTextbox.Value, 7)


If the textbox is empty, the result is Null. So.... what is going to happen here:

CODE
Dim OutputString As String

OutputString = Mid(Me.MyTextbox.Value, 7)


It'll blow up with that "Invalid use of Null" because we can't assign a Null to the string variable. Had we done this instead:

CODE
Debug.Print Mid$(Me.MyTextbox.Value, 7)


It'd have immediately blow up and we know that our logic is flawed because we are not guarding for the unexpected nulls.

This is somewhat of an oversimplification but I hope that it illustrates that it's best to choose a function that matches the expected data type you want, to make it easier for your code to be tested and verified that it will work as expected in all circumstances, and not just by happy accident.
Go to the top of the page
 
theDBguy
post Mar 2 2018, 01:29 PM
Post#9


Access Wiki and Forums Moderator
Posts: 73,276
Joined: 19-June 07
From: SunnySandyEggo


Thanks for the detailed explanation. notworthy.gif
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    26th September 2018 - 09:38 AM