Active Directory vbscript case conversion - vbscript

I need some help with my script.
The full script can be found here
The portion of the script I need help with is this:
If (Len(strTitle) > 3) Then
arrStr = Split(strTitle," ")
For i=0 To UBound(arrStr)
word = LCase(Trim(arrStr(i)))
word = Replace(word, Mid(word, 1, 1), UCase(Mid(word, 1, 1)), 1, 1)
strTitleCon = strTitleCon & word & " "
Next
End If
In our AD, everything is written in uppercase which is why I need to make it title case. However, this doesn't work if it's for title's like "QC Technician" or "HR Manager".
How can I go about doing that with the current script that I have?

Add another condition inside the loop and change the casing only if the string is longer than 2 characters.
For i=0 To UBound(arrStr)
word = Trim(arrStr(i))
If Len(word) > 2 Then
word = UCase(Left(word, 1)) & LCase(Mid(word, 2))
End If
arrStr(i) = word
Next
strTitleCon = Join(arrStr, " ")

Related

vbscript won't read file after 8Mb

I have a file written in vbs that wont read a file after about 8MB. I am currently using "Scripting.FileSystemObject". When I test the code, I notice that it runs fine until line ~79500, thats when the "AtEndOfStream" just results in True. I was looking for documentation, but it seems not to exist.
The code is supposed to show duplicate file information and put it in a separate file, which works well enough till around that line.
This is the section of code giving me the problem (it is the second reading function I have in the code):
Set first = fso.OpenTextFile(filePath + firstFileName)
Set secondFile = fso.OpenTextFile(filePath + secondFileName)
count = 0
countInLine = 0
Do Until secondFile.AtEndOfStream
lineMatches = false
lineOfSecond=secondFile.ReadLine
If count > 79440 Then
MsgBox("first line" & first.AtEndOfStream)
End If
Do Until first.AtEndOfStream
lineOfFirst =first.ReadLine
if lineOfSecond = lineOfFirst Then
lineMatches = True
Exit Do
End If
Loop
If Not lineMatches Then
writeFl.Write(count & "second" & lineOfSecond & vbCrLf)
End If
count = count + 1
Loop

Get number first and second and third from text line

I have the following format in my txt file:
1 1,30705856804525E-7 2,64163961816166E-8
1,12201845645905 1,24157281788939E-7 2,45690063849224E-8
1,25892543792725 1,18248813407718E-7 2,29960868125545E-8
1,41253757476807 1,13006606738963E-7 2,16654658657944E-8
1,58489322662354 1,0842624220686E-7 2,05472137082552E-8
1,77827942371368 1,04479198625995E-7 1,96135836461053E-8
1,99526226520538 1,01119816520168E-7 1,8839035220708E-8
2,23872113227844 9,82917924829962E-8 1,82003176973922E-8
2,51188635826111 9,59338279926669E-8 1,76765304615856E-8
2,81838297843933 9,39840489877497E-8 1,72491425587395E-8
3,16227769851685 9,23831819932275E-8 1,69019571671924E-8
3,54813385009766 9,10766573269939E-8 1,66210121221866E-8
3,98107171058655 9,00157104410937E-8 1,63944182673958E-8
4,46683597564697 8,91577514039454E-8 1,62121711611007E-8
5,01187229156494 8,8466336478632E-8 1,60659361370108E-8
5,6234130859375 8,7910699164695E-8 1,59488209305891E-8
6,30957365036011 8,74651959748007E-8 1,58551749507296E-8
7,07945775985718 8,71086527354237E-8 1,57803938805046E-8
7,94328212738037 8,68237393092386E-8 1,57207402651238E-8
8,91250896453857 8,65963372120859E-8 1,56731942979604E-8
10 8,64150138113473E-8 1,56353241465013E-8
11,2201843261719 8,62705391568852E-8 1,5605175818223E-8
I need to get only value for integers on left and right value so in this example I need to get:
1
2,64163961816166E-8
10
1,56353241465013E-8
This is what I've tried:
' Check Noise Spectral Density.txt exists
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(fso.GetParentFolderName(WScript.ScriptFullName) + "\Projects\Noise Spectral Density.txt")) Then
' Open the file for input.
Set NoiseSpectralDensity = fso.OpenTextFile(fso.GetParentFolderName(WScript.ScriptFullName) + "\Projects\Noise Spectral Density.txt", 1)
' Noise Variables
Dim Noise
' Read from the file and display the results.
Do While NoiseSpectralDensity.AtEndOfStream <> True
' Read Line By Line
TextLine = NoiseSpectralDensity.ReadLine
' Check If Number
'If (IsNumeric(Left(TextLine, 5))) Then
' Get Noise
' Noise # 1kHz
Noise = Right(TextLine, InStr(Mid(TextLine, 2), InStr(TextLine, " ")-1))
x = MsgBox("SNR: " & Split(Left(TextLine, 5), " ")(0) & " NOISE: " & Noise & "",0, "Noise Spectral Density")
'End If
Loop
' Close the file for input.
NoiseSpectralDensity.Close
Else
x = MsgBox("Noise Spectral Density.txt NOT Found!" & vbCrLf & "Wave->Save As Text...", 0, "Noise Spectral Density")
End If
But I could not get left and right numbers in VBScript using Split(TextLine, " ")(0).
Your data seems to be tab-separated, so you could do something like this:
arr = Split(TextLine, vbTab)
If Not (InStr(arr(0), ",") > 0) Then
'first number doesn't have decimals
snr = arr(0)
noise = arr(2)
End If
Though the solution provided by #AnsgarWiechers should work but in case, if it doesn't, you can make use of regular expressions(Replace the whole Do-while loop with the following):
Set objReg = New RegExp
objReg.Pattern = "^(\d+)(?=\s).*\s+([\d,Ee-]+)$" 'See the explanation below
Do While NoiseSpectralDensity.AtEndOfStream <> True
'Read Line By Line
TextLine = NoiseSpectralDensity.ReadLine
' Check If Number
Set objMatches = objReg.Execute(TextLine)
For Each objMatch In objMatches
SNR = objMatch.submatches.item(0)
Noise = objMatch.submatches.item(1)
MsgBox "SNR: "&SNR&"; Noise: "&Noise
Next
Loop
Click for Regex Demo
Regex Explanation:
^ - asserts the start of the string
(\d+) - matches 1+ occurrences of a digit and captures it in Group 1
(?=\s) - positive lookahead to find the position immediately preceded by a white-space. So the digits in the step 2 will be matched until a whitespace(spaces,tabs etc.) is encountered
.* - matches 0+ occurrences of any character except a newline
\s+ - matches 1+ occurrences of a whitespace
([\d,Ee-]+) - matches 1+ occurrences of a digit or , or - or the letter E or e and capture it in group 2
$ - asserts the end of the string

How to read variable length application identifiers in .zpl datamatrix in VB6?

According to GS1 standards (http://www.databar-barcode.info/application-identifiers/) a variable length field in a barcode should have a break sign to signal when it ends.
Code for the .zpl printer in my test is as follows:
^BY200,200^FT250,860^BXN,12,200,0,0,6,~
^FH\^FD\7E10012345678912345678910123\7E1151606013712\7E1^FS
This was written according to (http://www.servopack.de/support/zebra/ZPLbasics.pdf) and when I scan it into Notepad++ I see that the breaks are applied in the code as shown in the picture below.
But when I try to scan it in my VB6 application it doesn't appear to catch the break sign and writes everything from 10 (batch number) and forward into the batchnumber instead of breaking before 15 (expiration date).
My code looks like this:
ElseIf Left(Data, 2) = AI_BATCH Or Left(Data, 6) = "<GS>10" Or Left(Data, 3) = "~10" Then
If Left(Data, 2) = AI_BATCH Then
Data = Mid(Data, 3)
ElseIf Left(Data, 6) = "<GS>10" Then
Data = Mid(Data, 7)
ElseIf Left(Data, 3) = "~10" Then
Data = Mid(Data, 4)
End If
' Calculate length
While Mid(Data, AI_BATCH_LEN + 1, 1) <> "" And Mid(Data, AI_BATCH_LEN + 1, 1) <> "~" And Mid(Data, AI_BATCH_LEN + 1, 1) <> "<"
AI_BATCH_LEN = AI_BATCH_LEN + 1
Wend
gs1.batch = Trim(Left(Data, AI_BATCH_LEN))
Data = Mid(Data, 1 + AI_BATCH_LEN)
Thanks in advance.
You seem to be looking for the 2 ASCII characters 'G' and 'S' but you should be looking for the single 'GS' character - GS is ASCII control character 29 (Group Separator).
This character is not printable as a letter so Notepad++ (and the font its using) substitute the graphical glyph you see.
Use chrw$(29) to locate this character:
x = "Hello" & chrw$(29) & "World"
?x
HelloWorld
?left$(x, instr(x, chrw$(29)) - 1)
Hello

Issue running Classic ASP written in VBScript on Windows 2012 with IIS 8

This is a very peculiar issue. I have a 2012 Server running IIS 8 with support for classic ASP installed. I am building a comma separated string from a form. I then am retrieving this string from a table and want to split on the commas.
First, when I build the string and submit it to the DB (SQL Express 2014), something is adding a space after each comma even though there is no space in the code.
Second, when I return the string and attempt to split on the comma, it doesn't do anything; the ubound method returns -1... For testing purposes, I hand built an array and this has the same behavior.
Code that builds the csv string:
If fieldName = "txt_EnvironmentType" then
strTempEnvCSV = strTempEnvCSV & fieldValue & ","
End If
Test code for split:
txtEnvironmentType = "This,Is,A,Test,String"
If txtEnvironmentType <> "" then
response.write(txtEnvironmentType)
array = split(txtEnvironmentType,",")
l = ubound(array)
response.write("<br>array is " & l & " long")
For i = LBound(array) to UBound(array)
response.write("<br>" & array(i))
Next
End If
The Above test code returns the following to the browser:
This,Is,A,Test,String
array is -1 long
Am I missing something?
Thanks!
For the mysterious spaces, add a TRIM() to make sure you aren't starting with spaces:
If fieldName = "txt_EnvironmentType" then
strTempEnvCSV = strTempEnvCSV & TRIM(fieldValue) & ","
End If
This ran (for your second issue) for me - the only change I made was to dim the array variable and name it something other than "array"
<%
dim arrMine
txtEnvironmentType = "This,Is,A,Test,String"
If txtEnvironmentType <> "" then
response.write(txtEnvironmentType)
arrMine = split(txtEnvironmentType,",")
l = ubound(arrMine)
response.write("<br>arrMine is " & l & " long")
For i = LBound(arrMine) to UBound(arrMine)
response.write("<br>" & arrMine(i))
Next
End If
%>

Displaying only certain text from file - Visual Basic

I want to only display numbers in a text box that i have. At the moment my code reads the text file and adds all the code to the textbox and not only the needed text(which are numbers).
tbRecipient.Text = My.Computer.FileSystem.ReadAllText("filepath")
if anyone can point me in the right direction and let me know how i would go around this problem, that would be great.
I have a file containing:
Steve, 017876
Alan, 098578
...
I want to list only the numbers into a text box once i have got them from the file.
To do this i am using:
Dim i As Integer
For i = 0 To cbRecipients.CheckedItems.Count - 1
My.Computer.FileSystem.WriteAllText("filepath", cbRecipients.CheckedItems.Item(i) & vbCrLf, True)
Next
frmHome.myFunction()
Then under myFunction() is:
tbRecipient.Text = My.Computer.FileSystem.ReadAllText("filepath")
You can use this function:
Function GetFileColumnContents(s_Path As String, ColumnNumber As Long, ColumnDelimiter As String, Optional s_OutputDelimiter As String) As String
On Error GoTo ErrHandler
Open s_Path For Input As #1 'Open the txt file for readin as Temporary File Number 1
Do While Not EOF(1) 'Read line bu line until end of file
Line Input #1, Mystring 'Store the line value in Mystring
GetFileColumnContents = GetFileColumnContents & s_OutputDelimiter & Split(Mystring, ColumnDelimiter)(ColumnNumber - 1) 'process the string
Loop
ErrHandler:
Close #1
End Function
Call in subrutine:
tbRecipient.Text = GetFileColumnContents("filepath", 2, ",", vbCrLf)
Edit: The linenum = linenum + 1 was not neccesary in the function (edited above)
s_Path : is path to the txt file (like "C:\Test.txt")
ColumnNumber: is the column in the text file. If the data looks like:
A, 123, red
B, 456, blue
then ColumnNumber 1 are letters, ColumnNumber 2 are numbers and 3 are colors.
(ColumnNumber - 1) is there because first part of split has index 0, but the ColumnNumber is 1
split("A, 123, red",",")(0) 'results to "A"
split("A, 123, red",",")(1) 'results to " 123"
If you want to list the items from text file column 2 and in the result separated by comma then call the function with comma as last argument:
tbRecipient.Text = GetFileColumnContents("filepath", 2, ",", ",")

Resources