looking for the first time specific characters appear - vba

In vba I am openening a table from access with a column that look like the following:
1300nm11-53-0202 0302.SOR
I would like to look for the very first time "nm" is found in the string and write everything that is before that into a variable "strGolfLengte" (so In this case strGolflengte would be "1300")
NB:
I can't be sure that there won't be several nm's in the string, I just want to look for the first time they are found.
NB2:
The string before nm could be "n" characters, in all cases, I want the full lenght (n) of the string written in strGolflengte

I would use the `instr()' function like this:
strGolfLengte = left(myLine,instr(1,myLine,"nm",1))

I think it is the easiest way to do this:
strGolfLengte = Split(myLine,"nm")(0)

Related

SQL request to find item in table by value in column

Its pretty simple question, I know, but I really stacked with a problem with it...
I have a table customer_customer and a column code in it. So I need to find all items with a specific code value. So I wrote that:
SELECT * FROM customer_customer WHERE code LIKE "КL-12345"
and got an error:
column "КL-12345" does not exist
Why КL-12345 became a column if I specify it as value of code column? What am I doing wrong?
String literals must be enclosed in single quotes.
By enclosing it in double quotes, you specified a variable name.
Also, note that your where condition is the same as writing
where code = 'КL-12345'
LIKE is used for pattern matching. For instance you would match all codes that contain 'KL-12345' like this
where code like '%KL-12345%'
Change it to single quotes
SELECT * FROM customer_customer WHERE code LIKE 'КL-12345'
or
SELECT * FROM customer_customer WHERE code = 'КL-12345'

How does the Like predicate work in SQL?

I have a field called OrderNumber and there's already a record with that field value of "JY8023".
I tried querying using this SQL code, but it returned nothing.
SELECT .... WHERE OrderNumber LIKE "JY8023"
I also tried using wildcards and it worked
SELECT .... WHERE OrderNumber Like "%JY8023%"
So does that mean OrderNumber Like "JY9023" is not the same as OrderNumber = "JY8023"?
the string has characters before or after it, that you can't see. try something like select length(OrderNumber) WHERE OrderNumber Like "%JY8023%" to confirm this. Some characters are not only invisible, but unselectable with a cursor. But, they're there and they affect string comparisons.
additional debugging steps to follow will be to use substring to extract the offending part, and other string functions to further inspect the value. like, maybe selecting the string as a hex encoded string will help you identify the bytes.

Negating a string to be passed to mssql server

I have a text field which acts a filter field. It checks for equals, contains and starts with. My problem is, with out changing any of my code, can I check for the 'does not contain', 'does not start with' and so on by just using the string i'm passing with something like '!' operator or "<>"?
for example:
I want to get all the records that do not have 'a' in them, so can I pass the string as "!a" or "<>a" or something so that I can get the required records? (I know these two don't work cause I tried.)
You have to use the keyword NOT, e.g.
SELECT * FROM Table WHERE Foo NOT LIKE '%bar%'
Please refer http://www.sqlservercentral.com/Forums/Topic1213442-338-1.aspx
Can solve with case in where clause

Removing Spaces in Calculated Lists

I have created a calculated column which creates a URL which calls a Column called "Pitch Name" and from that will create the URL but I have to remove the space/spaces between words from pitch which needs to be displayed as a URL. Example of this is "Coca Cola" needs to be "CocaCola" so the site name can be"http://sitename.com/CocaCola". I've tried using the TRIM function but that doesn't work. I have tried the REPLACE function aswell but that seems not to work either. Any Solutions?
(Taken from an attempt to edit an answer:)
Update: The REPLACE and FIND Functions work but only if the string contains the amount of the desired character. And if the character doesn't appear the same amount of times the formula has asked for you will always get the string #VALUE which means it hasn't worked
SharePoint Calculated Fields use Excel functions, not .NET functions, so you probably want to use SUBSTITUTE rather than REPLACE.
Try something like this:
=SUBSTITUTE([Pitch Name], " ", "")
Update:
According to Xue-Mei Chang in Calculated Field Error:
The "SUBSTITUTE" function is not available in SharePoint.
As a workaround, he proposes:
For the "SUBSTITUTE" function, you have to use a combination of the "REPLACE" function with a "FIND" function. The "FIND" would return the position of the desired character in the string, which would then pass on to the "REPLACE" function so it can replace it with the new character.

lua variable in pattern match

Im just wondering if it is possible to put a variable in a pattern match in Lua. Like something similar to the following:
var = "hello"
pattern = string.match(datasource, "(var)%s(a%+)")
The reason I need to do this is because the variable "var" will change periodically. (it will be in a loop)
Cheers in advance
Lua doesn't handle string interpolation inside of the quotes. Instead, you'll need to concatenate the parts with the var as a var reference and the rest as quote strings.
"("..var..")%s(a%+)" starts with a "(" as a string literal, concatenates the variable, then finishes off the rest of the string with a string literal.
Use "("..var..")%s(a%+)" instead.
I needed the same thing I think, a variable in a pattern match, but the above solution didn't work for me. I'm posting my solution in case it helps someone, didn't find anything else on the net like it.
I read a ': ' delimited file (name: tel) and want to search by name in the file and have the name and telephone number as answer.
local FileToSearch = h:read'*a' -- Read all the file
var = io.read() -- ask the name
string.gmatch(FileToSearch, ''..var..': '..'%d+') -- search for name, concatenate with number