I have been making alot of random scripts lately, none of which are really useful for anything but they help me to understand various things and I use them for reference quite often... anyways, one of the outline button options for one of my scripts is a popup msgbox generator that generates a code that I can just copy and paste (there are alot of message boxes in the script)
but I am having trouble with the variable being displayed in the input '$codebox':
$code = "MsgBox(0, $title, $message)"
GUICtrlSetData($codebox, $code)
this displays:
"MsgBox(0, $title, $message)"
rather than the data stored inside the variable. Yet, when I remove the quotation marks from the $code line, that actually brings the msgbox up(which I don't want) and returns a 1 to the codebox, rather than the MsgBox command..
Can I contain a variable inside a variable like this? I am not really sure how else to so this.. Does anybody have a possible workaround I could take a look at? I have searched around but I came up empty.
ps: the updated script can be found here
Figured it out, replace this line:
$code = "MsgBox(0, $title, $message)"
with this one:
$code = 'MsgBox(0, ' & '"' & $title & '"' & ', ' & '"' & $message & '"' & ')'
Answered here by Darius. (Thanks again)
Related
I am trying to read from the clipboard and place in an array. I want to validate the first line as the text: "Client Code "
I fill the array with:
tbClipBoardContents.Text = My.Computer.Clipboard.GetText()
For Each strLine As String In tbClipBoardContents.Lines
arrClipBoard.Add(strLine.ToString)
Next
When I give a variable the value of the first array entry it appears correct = "Client Code " in Visual Studio debugging.
Dim test As String = Trim(arrClipBoard(0).ToString)
However when I check using the "IF" statement it tells me it is not correct??
If test = "Client Code " Then
MsgBox("Correct Clipboard Structure")
Else
MsgBox("Not a Valid Clipboard Structure: " & Trim(arrClipBoard(0).ToString)) ' ** Fires this response.
End If
What is doing my head in is that if I copy the value of test from VS debugger and paste it in the if statement it looks like "Client Code " but this time the if statement fires the correct response.
I have tried it by filling the textbox (tbClipBoardContents) using:
tbClipBoardContents.text.split(New [Char]() {CChar(vbCrLf)})
and
tbClipBoardContents.text.split(newvbline)
with the same results.
So does this mean the true value from the clipboard for the line "Client Code " also carries some hidden characters? Any help is appreciated.
Brad
P.S. I have found that if I test the value of Mid(test,1,11) then I will get the desired result, so this is a workaround but would be interested to know what the 12th character is? Perhaps it is the "CChar(vbCrLf)"
As per my observation Trim will have removed the spaces. and you should change the condition to "ClientCode".
The final solution that worked for me was to find the trailing space using Andrew Morton's method above then
arrClipBoard.Add(Trim(Regex.Replace(strLine.ToString, Convert.ToChar(160), "")))
which effectively converted the char(160) to "".
I am relatively new to VBA and want to accomplish something pretty simple but am confused as to why this is not working. I am reading in lines from a file and if opened in notepad++, each line has a CRLF at the end. I would like to just remove the CR. In notepad++ I can do a replaceall, replacing CRLF with LF and things work great. However, the test I have in VBA right now is not doing this correctly. Below is an example of a string I'm dealing with in Notepad++:
Summary - I went for a walk in the parkCRLF
I want the string to become, Summary - I went for a walk in the parkLF
I am writing out to a file as a test in order to see if its working. Below is my code:
Do While Not txtStream.AtEndOfStream
str = txtStream.ReadLine
edited = Replace(str, Chr(13) & Chr(10), Chr(10))
stream.WriteLine (edited)
Loop
txtStream.Close
The code is being executed without error but the CRLF is still at the end of each line in the newly written file...Maybe I'm missing something obviously but the replace does not seem to be picking up on what I'm searching for. Any help or advice on this would be greatly appreciated!
Even figuring out if the end of the line ends with a CRLF would be a step in the right direction at this point.
Thank you.
WriteLine automatically places an end of line after your string
You should replace it with #Mark's suggestion: stream.Write(edited)
This performs better:
stream.Write(Replace(txtStream.ReadAll, vbCrLf, vbLf))
or
stream.Write(Replace(txtStream.ReadAll, vbCr, vbLf))
.
Details about ReadAll
You are reading a line so it will remove the new line characters. Your replace statement has nothing to do. You are then writing a line which will add new line characters.
Also, you aren't closing the output stream in the code sample you provided.
You will want something like this:
Do While Not txtStream.AtEndOfStream
str = txtStream.ReadLine
stream.Write str & Chr(10)
Loop
txtStream.Close
stream.Close
I'm getting a persistent error:
The element cannot be found in a collection.
This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there.
I've checked, double and triple-checked my variable listings in the Read-Only and Read-Write variables in my Script task.
I've debugged it to death and gotten input from another programmer here who couldn't spot the issue either.
I've also researched to no end.
Does anyone see anything wrong with my code?
Script Task code:
Public Sub Main()
Dts.Variables("User::strMailBody").Value = "Thank you for submission. For your convenience, we are including the last four of the HICN# and the Name on the application(s) we have received* from you." _
& vbNewLine & vbNewLine & "Here are the following: " & vbNewLine & vbNewLine
Dts.Variables("User::strMailBody").Value = Dts.Variables("User::strMailbody").Value.ToString() & vbNewLine & Dts.Variables("User::strListing").Value.ToString()
Dts.Variables("User::strMailBody").Value = Dts.Variables("User::strMailBody").Value.ToString() & vbNewLine & vbNewLine & Dts.Variables("User::strFooter").Value.ToString()
If Left(Dts.Variables("User::strAgentID").Value, 2) = "TX" Then
Dts.Variables("User::strSubject").Value = "ACME Health Plans Confirmation: Total "
Else
Dts.Variables("User::strSubject").Value = "ACME2 Baptist Health Plans Confirmation: Total "
End If
Dts.Variables("User::strSubject").Value = Dts.Variables("User::strSubject").Value.ToString() & Dts.Variables("User::lngCountAgent").Value.ToString() & " " & "[RESTRICTED: CONFIDENTIAL]"
Dts.Variables("User::DateSent").Value = Now()
Dts.Variables("User::UserSent").Value = "SSIS"
Dts.TaskResult = ScriptResults.Success
End Sub
For anybody else struggling with this issue the resolution for me was as follows: (note I am NOT using User:: when getting variable values within my script task)
On the package Properties I hadn't included the variables as ReadOnlyVariables
You'll need to set your newly added variables as follows:
Right click on the package and select Edit
In the Script section click on ReadOnlyVariables or ReadWriteVariables (depending on your how you want your variables behave)
Check the check-box beside the variables you wish to use in your script task
Click Ok to save your changes
Hope this helps
I just had the same issue and unable to find the problem for ages. I found that the reason for the error was that I had missed one of the colons between "User" and the variable name.
I had this (which caused the error):
string FileName = UserVariables["User:CurrentFileName"].Value.ToString();
when I should have had this:
string FileName = UserVariables["User::CurrentFileName"].Value.ToString();
just in case anyone else has the same problem :)
Ohhh.........man. It's amazing how you can stare at this stuff and miss something stupid, for hours.
strFooter was missing in the listing.
ALL SET NOW. Sincere thanks to those who looked and commented. Eric, thanks, I'll remember that as sometimes I will probably need to use C insatead of VB (haven't yet but will).
Had a similar issue, after a lot of debugging, realized that the variable naming convention should be User::varname and NOT USER::varname
I guess c# is very case sensitive.
Hope this helps and saves you lot of your valuable time :-)
a) Right click on the script task and choose edit
b) Locate the Read or Read/Write variables properties in the list.
c) Click on the property and the variable you wish to access in the script task.
Another variation on "have been staring at the screen for too long to see the typo". In my case, I got the same error by mixing up the syntax between Project Params and User variables, and adding a $ sign in front of User.
error :
string varA = (string)Dts.Variables["$Project::ParamA"].Value
string varB = (string)Dts.Variables["$User::ParamB"].Value
corrected :
string varA = (string)Dts.Variables["$Project::ParamA"].Value
string varB = (string)Dts.Variables["User::ParamB"].Value
At some point of execusion of my project, the input to the database is in the format:
Buy Requirement of "xxxxxx & xxxxxx" through mycompany.com
It results in an incorrect SQL syntax error. I need to replace " with white space. I searched in google but no helpful suggestions were there.
How to replace " with whitespace?
Dim str As String
str="Buy Requirement of "Telemarketing & ERP Software" through IndiaMART.com"
' TODO: perform replace
' result
str = "Buy Requirement of Telemarketing & ERP Software through IndiaMART.com"
I finally understand what you are asking now...
Here, this is what you want to be using: teststring.Replace(""""c, "")
If you really want to use Linq and extension methods, then use this: New String(teststring.Where(Function(c) Char.IsLetterOrDigit(c) OrElse Char.IsWhiteSpace(c)).ToArray()).
But that's just making things complicated for no reason.
I'm writing a VBA macro that will send a string to the command line like below:
str = "SELECT (edr.VersionName + ' ' + edr.BuildName)"
RSP = Shell(Environ$("COMSPEC"), vbNormalFocus)
SendKeys str
But the issue comes that the special keys like ( and + are lost in translation; the command line ends up like below:
SELECT edr.VersionName ' ' edr.BuildName
How do I prevent those special characters from being lost in the process?
You can get the '+' symbols to show up by using this string:
str = "SELECT (edr.VersionName += ' ' += edr.BuildName)"
In the SendKeys function in VBA, the '+' symbol is used to indicate the {SHIFT} key. So, {SHIFT}=, is actually the '+' symbol; at least on my keyboard.
Using that logic, '+9' and '+0' should give you '(' and ')' but I haven't gotten those to work yet.
EDIT
Ok, you can get the parentheses to show up, but you kind of have to include them twice:
str = "SELECT +9" & "(edr.VersionName += ' ' += edr.BuildName)" & "+0"
Again, keep in mind, the above string works for my keyboard (standard English). If you are using a different keyboard layout, the characters after the '+' signs will most likely be different.
Actually I found out another way to display those special characters, by enclosing it with {} it will show up in my command line. Thanks for the help!