Multiple Fields for Hyperlink Expression - sql

I am building an expression for a hyperlink in SSRS. I can currently get it to point to the correct directory, but also need it to point to the correct file within the directory and I'm not sure how to include multiple fields. I'm sure its something simple that I'm missing. Would appreciate any help you all can provide. Code is below that gets to me to the directory, need to add code to get to the FileName which is the actual file. Thanks in advance.
="file://phpfile01/analyst/AMHPData/Exports/"&Fields!XML_EXPORT_DIRECTORY.Value

You add more fields to the expression with the &:
="file://phpfile01/analyst/AMHPData/Exports/" & Fields!XML_EXPORT_DIRECTORY.Value & "/" & Fields!FileName.Value
The extra slash may not be needed if it's included in your XML_EXPORT_DIRECTORY field.
If not if would be:
="file://phpfile01/analyst/AMHPData/Exports/" & Fields!XML_EXPORT_DIRECTORY.Value & Fields!FileName.Value

Related

Surround Number to interpret as Text

I have a CSV files and one of the fields named period stores number. Now within SSRS, I need to make use of a multi-value parameter, due to the workings of SSRS to use this with a CSV I need to do Join(Parameters!Period.Value, ",").
This issue with this is then my data set has the following query:
="SELECT WarehouseZone, RevenueStream,ClientID,CONVERT(varchar(10),Period) FROM BudgetCSV.csv
WHERE WarehouseZone IN ('" & Join(Parameters!Warehouse.Value,"', '") & "')
AND (RevenueStream IN ('" & Join(Parameters!AnalysisCode.Value,"', '") & "'))
AND (ClientID IN ('" & Join(Parameters!Customer.Value,"', '") & "'))
AND (CONVERT(varchar(10),Period) IN ('"& Join(Parameters!Period.Value, "','") & "'))"
This code works fine for the zone, stream and client, I get a data type mismatch of period.
Is there any way using Powerquery to have the csv think that period is text. I have seen somewhere that by making the column say ="1" it would interpret that as text instead of an integer.
You can either use Text.From or Number.ToText to convert a number value to text.
Text.From(Period)
or
Number.ToText(Period)
EDIT: THE FOLLOWING DOES NOT WORK - Using this method only works on an individual level, luckily there is a better solution
So I mentioned in an earlier post that I could get around using the Join by creating a single parameter for each period, but this was causing an issue where if I selected 10, 1 would also be return because, strings.
This was due to me using the following code on each of these parameters
=iif(Join(Parameters!Period.Value,",").ToLowerInvariant().Contains("10"), "10",-999)
Simple changing that code to the following
=iif(Join(Parameters!Period.Value,",") = 1, 1,-999)
So the issue is solved, but any input on how I could get a more dynamic solution working would be great as there may be times in the future when I need to use a longer list of numbers.
Adding as another answer for posterity to see my mistakes.
There is in fact a much easier way to achieve this.
By adding the above filter onto the dataset you can achieve this without the need for any SQL or any extra parameters. This is probably obvious to anyone who has been working with SSRS for any length of time, but I'm rather new to it myself.

System.ArgumentException: 'Illegal characters in path.' Error

Please help. I have a piece of code that's already working in other parks of my program, however fails to work when accessed by a certain form so i can't see there can be an error with it. Its an information storage project using text files. A screenshot of the exact code and the error:
I expected it to change the label text to the contents of the text file its trying to read.
Thanks everyone :)
Well, there must be one or more illegal characters coming from your "zoots1.txt" file!
Build the filename and see what it looks like:
Dim zoot1s As String
zoot1s = My.Computer.FileSystem.ReadAllText("zoot1s.txt")
Dim fileName As String
fileName = zoot1s + "c.txt"
MessageBox.Show(fileName)
Dim ClassStrain As String
ClassStrain = My.Computer.FileSystem.ReadAllText(fileName)
TempLabel3.Text = ClassStrain
Timer1.Start()
--- EDIT --
My bad. I Found the issue to be that there is a skip in text where it goes to a new line. As if i had added vbNewline to it. Is there any way to edit the text file and take away the last character so there isnt a new line.
Use the Trim() function to get rid of white space. Also use Path.Combine() to make sure the path is correctly separated from the filename with the correct number of backslashes:
zoot1s = My.Computer.FileSystem.ReadAllText("zoot1s.txt").Trim()
Dim fileName As String = System.IO.Path.Combine(zoot1s, "c.txt")
I think you just missed the most important thing, which is the whole specific path of your file that will be reading data from, specifically after the ReadAllText() method, so instead of this line:
zoom1s=My.computer.FileSystem.ReadAllText('zoot1s.txt")
You should edit it like this:
zoom1s=My.computer.FileSystem.ReadAllTex(My.Computer.FileSystem.CurrentDirectory & \zoot1s.txt")
I hope this can solve your problem.
^_^

VBA store path including Environ("username") in a text file

I am trying to create a text file that stores a folder path. This text file is then referenced via a vba sub. The path I want to use is something like:
"C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Templates"
This works fine in the sub but I've tried all kinds of variations in the text file but none of them get recognised and trigger error 52 - bad file.
Is there a way to make this work? I'm trying to allow people to set a different file path without needing to modify the code.
If you are trying to provide a path to the folder where user templates are stored then you could try
ActiveDocument.AttachedTemplate.Path
as an alternative (returns the path to the folder where the current template is stored for the user).
Otherwise store the path template as something like
"C:\Users\###UserName###\AppData\Roaming\Microsoft\Templates"
Which gives you a single string to retrieve. Then you can use the VBA Replace function to change the ###UserName### to the value of Environ("UserName)"
my_user_path = replace(my_path_template, Environ$("UserName"))
You might also want to explore using either a CustomDocumentProperty, or a Variables, to store your path template as this keeps the path template string as part of the Document or Template and not in a separate file.

Connecting to OpenVPN in VB.NET

I am wondering on how to connect to OpenVPN with VB.NET, I have attempted using the following code but then in the command line I get an error saying "Options error: In [CMD-LINE]:1: Error opening configuration file: C:\Users\Minetro300\Documents\connection.ovpn
Use --help for more information.".
IO.File.WriteAllText((System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\vShield" & "\connection.ovpn"), My.Resources.OpenVPNCertificate)
IO.File.WriteAllText((System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\vShield" & "\connection.bat"), "openvpn " & System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\connection.ovpn")
Dim connect As System.Diagnostics.Process
connect = New System.Diagnostics.Process()
connect.StartInfo.FileName = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\vShield" & "\connection.bat"
connect.StartInfo.WindowStyle = ProcessWindowStyle.Normal
connect.Start()
connect.WaitForExit()
I was going to say that I don't know the reason for your error but here are some suggestions to write better code and then I realised that one of those suggestions would have solved your issue. Look at the path of the file you specify in this line:
IO.File.WriteAllText((System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\vShield" & "\connection.ovpn", My.Resources.OpenVPNCertificate)
and now look at the path you specify for what I assume is supposed to be the same file in this line:
IO.File.WriteAllText((System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\vShield" & "\connection.bat"), "openvpn " & System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\connection.ovpn")
The path you specify to read the file from is not the same as the path you specify to write the file to, so is it any wonder that it can't read the file?
The advice I was going to give you about improving your code is to not use long expressions multiple times but, instead, use them once and assign the result to a variable, then reuse that variable. If you had done that then you could not have messed up the path the second time. So:
Dim ovpnFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "vShield\connection.ovpn"
You can now use that ovpnFilePath variable wherever you need that path and then you won't try to read from a different path to that which you wrote to.
That suggested code incorporates several other improvements too. Firstly, importing namespaces that you use often and then not using them in your code. As an example, System is already imported so you don't need to use System.Environment in code like you are. What's worse, though, is that you use System.Environment in some places and just Environment in others, sometimes immediately adjacent. That's bad coding. If I see two different things in your code then I should be able to assume that they are different, not the same thing written two different ways for no good reason. You should also be importing the System.IO namespace and not qualifying File with IO repeatedly.
Importing the System.IO namespace means that you can also use the Path class unqualified and you should be using that class to combine partial paths rather than using string concatenation. Further to that, NEVER concatenate two literals together. It's just silly and complicates your code for no good reason.
Looking more closely at your code, I see that you use two file paths multiple times and both files are in the same folder. I would tend to do this for those paths:
Dim folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "vShield")
Dim ovpnFilePath = Path.Combine(folderPath, "connection.ovpn")
Dim batFilePath = Path.Combine(folderPath, "connection.bat")
That will make your code much less complex and thus easier to read. It will eliminate your current issue and make it less likely that you'll make more.
EDIT: Here is your original code written "properly":
Dim folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "vShield")
Dim ovpnFilePath = Path.Combine(folderPath, "connection.ovpn")
Dim batFilePath = Path.Combine(folderPath, "connection.bat")
File.WriteAllText(ovpnFilePath, My.Resources.OpenVPNCertificate)
File.WriteAllText(batFilePath, String.Format("openvpn ""{0}""", ovpnFilePath))
Using connect As New Process(batFilePath)
connect.StartInfo.WindowStyle = ProcessWindowStyle.Normal
connect.Start()
connect.WaitForExit()
End Using
As you can see, it's much easier to read for one thing. It doesn't perform the same operations over and over so it nullifies the chance of making the mistake that caused you to post this question in the first place, i.e. use different paths when writing and reading a file.
It also gets rid of unnecessary qualifying namespaces. System and System.Diagnostics are already imported by default, so no need to do anything with them. This code does assume that you have also imported System.IO, which you can do at the file or the project level.
I've also used String.Format to create the commandline as it makes it cleaner to wrap the file path in double-quotes. That's not strictly necessary in this case but it ensures that the commandline will still work if the file path has spaces in it, which is completely possible.
Finally, it correct disposes the Process object that you create by doing so with a Using block, which causes the object created at the Using statement to be disposed at the End Using statement. You should always dispose any objects you create that support it.

how to do reverse index in VBA

I don't know anything about VBA but I need to get the file name out of a file full path.
So for a string like "c:\something\somethingelse\file.name" I need to get "file.name" out. Also how can you get a quote in a string such as " " "? backslash doesn't seem to work.
To get a quote in a string use two quotes ("")
To find the location of the slash from the end, use InstrRev()
the DIR() function will return the filename.
You need to add a reference to the Microsoft Scripting runtime.