If RadioButton.Checked - directory

I need help loading text file in TextBox3.Text with 3 possible options.
1. If there is nothing in TextBox.Text
2. If there is some help text explication to say user what he have to load
3. if correct path then..
I have all good if I choose only from pathn but I need the 3 option.
My code:
If (TextBox3.Text = "Enter the path from your computer to your text file") And (TextBox3.Text = "") And RadioButton1.Checked = True Then
Dim FILE_NAME = Path.Combine(Directory.GetCurrentDirectory(), "\default.txt")
End If
If TextBox3.Text <> "" Then
FILE_NAME = TextBox3.Text
End if
PS: Dim file_name is already declared, but i didnt want to enter here all that codes. Also I tried to not add () and laso looked in MSDN declaration and did exactly same but it wont load nothing, if I dont enter path, OR if I let the explication to user so it wont load default.txt
Thank you

I would like to explain to you what I have been (trying) to explain in the comments (obvoiusly) without much success:
You have written, as your first line:
If (TextBox3.Text = "Enter the path from your computer to your text file") And (TextBox3.Text = "") And RadioButton1.Checked = True
So, YOU are testing (in a shorter way):
IS(TextBox got the value of "Enter the path from your computer to your text file")?
Yes?
Then IS (textBox ALSO the value of "")
Yes?
Then IS (the radio button also checked?)
However, you're code will NEVER REACH the 'is the radiobutton...' part, Since textbox cannot be both
"Enter the path from your computer to your text file" AND "" (nothing/Blank)
I hope you now understand the reason for your code never executing that part of your first if statement.
It's impossible for the code to be true with that condition, and I hope now you will be able to see why.

Related

How to modify code in Blue Prism to Move folders with all they have inside

I have got an issue where it would be super convenient to move whole folders instead of files.
I myself have 0 code writing experience with Blue Prism but went through the code to see if I can modify it to suit my needs.
When I run this code, I get this error message:
Second path fragment must not be a drive or UNC name.
Would anyone be able to have a look and advice on the mistakes I have made? Please bear in mind that it's a novice's work. Thank you in advance.
Inputs: Folder Path, Destination
Try
Dim sSourceFolder As String = Folder_Path
Dim sDestinationFolder As String
If Directory.Exists(Destination) Then
sDestinationFolder = Destination
If Not sDestinationFolder.EndsWith("\") Then
sDestinationFolder &= "\"
End If
sDestinationFolder = ""
Else
sDestinationFolder = ""
sDestinationFolder = Destination
End If
Dim objDirectoryInfo As DirectoryInfo = New DirectoryInfo(sSourceFolder)
Dim aFolders As DirectoryInfo() = objDirectoryInfo.GetDirectories(sSourceFolder)
For Each oFolder As DirectoryInfo In aFolders
If sDestinationFolder = "" Then
oFolder.MoveTo(sDestinationFolder)
Else
oFolder.MoveTo(sDestinationFolder)
End If
Next
Success = True
Message = ""
Catch e As Exception
Success = False
Message = e.Message
End Try
My solution creates a new folder in the destination with the same name as the source folder, copies its contents, and deletes the source folder (essentailly the same thing as moving it). The inputs remain Folder_Path and Destination:
Success = True
Message = ""
Try
If Not Folder_Path.EndsWith("\") Then
Folder_Path &= "\"
End If
Dim newDirectory As String = System.IO.Path.Combine(Destination, Path.GetFileName(Path.GetDirectoryName(Folder_Path)))
If Not (Directory.Exists(newDirectory)) Then
Directory.CreateDirectory(newDirectory)
End If
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(Folder_Path, newDirectory)
System.IO.Directory.Delete(Folder_Path, True)
Catch e As Exception
Success = False
Message = e.Message
End Try
Make sure that you include the System.IO namespace in the Code Options of your object. The Code Options can be found by double-clinking the description box on the Initialize Page/Action and choosing the appropriate tab.

Vb.net Simple TextBox conversion to integer gives error input string was not in a correct format

I have some text boxes on a form I would like to validate. I want to confirm that they contain only numbers, and that the "total" text box is equal to the sum of the other boxes:
Protected Sub TotalBoxValidator_ServerValidate(source As Object, args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles TotalBoxValidator.ServerValidate
If ((Convert.ToInt32(Box1.Text) + Convert.ToInt32(Box2.Text) + Convert.ToInt32(Box3.Text) + Convert.ToInt32(Box4.Text) + Convert.ToInt32(Box5.Text) + Convert.ToInt32(Box6.Text) + Convert.ToInt32(Box7.Text)) = Convert.ToInt32(TotalBox.Text)) Then
args.IsValid = True
Else
args.IsValid = False
End If
End Sub
Now during testing, I fill out the boxes with only integers. The total box is automatically updated to be the sum of the other boxes. However, when I click my "Submit" button on the form, and all the validators run, this one does not work properly.
The code throws an error on the first if statement, saying that the input to the Convert.ToInt32 calls is invalid. "input string was not in a correct format". I am positive that I am putting integers in each box, and that my TotalBox is equal to the sum of the other boxes. So I'm kind of stuck on why this would throw an error. Perhaps I am doing my conversion from string to integer wrong?
Does anyone have any idea what is going on here?
My issue had to do with the fact that my TotalBox (an ASP.net TextBox control) had its "Enabled" property set to false. I did this because it made the textbox greyed out, and the user could not change the value of the text box. Because the TextBox was not Enabled, I could not access the value of the TextBox at runtime. Though I was successfully changing its value in the page's javascript, and visually the value of the textbox was updating on the page, trying to use its value as a string in the code behind caused the error.
It did not have to do with the logic of the code or any syntax error. To fix this problem, I set the Enabled property of the TotalBox to true. Now the box is no longer greyed out, and user has the ability to change their total to be different than the sum of the boxes, which is not exactly what I want, but then again I am validating the total here so it is not a big deal. I will go back and try to grey out the textbox in javascript instead, because I have a feeling this will maintain the ability to get the TextBoxes value, while still having it be greyed out.
Edit: The above solution did work. For others experiencing this problem, consider trying to grey out the textbox using javascript, instead of any .net or asp code.
Here is the updated code:
Protected Sub TotalBoxValidator_ServerValidate(source As Object, args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles TotalBoxValidator.ServerValidate
Dim Box1Value = Convert.ToInt32(Box1.Text)
Dim Box2Value = Convert.ToInt32(Box2.Text)
Dim Box3Value = Convert.ToInt32(Box3.Text)
Dim Box4Value = Convert.ToInt32(Box4.Text)
Dim Box5Value = Convert.ToInt32(Box5.Text)
Dim Box6Value = Convert.ToInt32(Box6.Text)
Dim Box7Value = Convert.ToInt32(Box7.Text)
Dim TotalBoxValue = Convert.ToInt32(TotalBox.Text)
If (Box1Value + Box2Value + Box3Value + Box4Value + Box5Value + Box6Value + Box7Value = TotalBoxValue) Then
args.IsValid = True
Else
args.IsValid = False
End If
End Sub
Now, here is what was really helpful for debugging this situation. Try putting your conversions on different lines, because then when the program halts, it shows you exactly which conversion is going wrong. In my case, I got an error on the TotalBoxValue line. So I knew that something was going wrong with my TotalBox. What was different with the TotalBox than any of the other text boxes? Well, first of all, it was the total. But I knew this was working correctly. So then I thought about its properties. Its enabled property was set to false, different from the other boxes. So i knew this had to be changed.
For some reason in asp.net, when a control has its Enabled property set to false, you cannot access any of its properties at runtime. This is something I have noticed that is maybe not intuitive.
I suggest you use CompareValidators on your textboxes.
This will assure that the page won't even postback if your values aren't appropriate. Example markup:
<asp:CompareValidator ErrorMessage="errormessage" ControlToValidate="Box1"
runat="server" Type="Integer" />
Then you could technically keep the code you've already posted, though if you wanted to forego the validators something like this would treat invalid input as 0:
Dim temp As Integer
Dim boxTotal = {box1.Text, _
box2.Text, _
box3.Text, _
box4.Text, _
box5.Text, _
box6.Text, _
box7.Text} _
.Select(Function(text) If(Integer.TryParse(text, temp), temp, 0)) _
.Sum()
Integer.TryParse(TotalBox.Text, temp)
args.IsValid = boxTotal = temp
You are attempting to convert a text value to an integer before knowing if the text value is an integer, please read up on
integer.TryParse
dim v1, v2, v3, v4, v5, v6, v7 as integer
if not integer.tryparse(box1.text, v1) then
args.IsValid = False
return
endif
if not integer.tryparse(box2.text, v2) then
args.IsValid = False
return
endif
......

VBScript runtime error '800a0034' - Bad file name or number - When trying to write to server side text file

I'm trying to simply write to a text file for later use data collected from input elements on various pages. Admittedly I am likely missing the obvious, but of the variations I have tried and even some of the sample code I have found in many examples I always get the same error.
Code:
<%
Dim currentDirectoryPath, outFile, objFSO, objTextStream
Const fsoForWriting = 2
'Get and assign current directory path
currentDirectoryPath = Server.MapPath(".")
'Assign file name to be used
outFile = "\accdata.txt\"
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Open the text file
Set objTextStream = objFSO.OpenTextFile(currentDirectoryPath & outFile, fsoForWriting, True)
'Write new line to text file
objTextStream.WriteLine "output this as one line of text"
'Close the file and clean up
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing
%>
Result:
Microsoft VBScript runtime error '800a0034'
Bad file name or number
/asp/accounting/datacollect.asp, line 23
(Line 23 of the code is:)
Set objTextStream = objFSO.OpenTextFile(currentDirectoryPath & outFile, fsoForWriting, True)
This is far from being my first language and thus I don't posses a heap load of experience with it so any help or suggestions will be very much appreciated.

What's the correct way to specify file path in VBscript?

New to VBscript and spending way too much time trying to find the right way to open a file for reading. Whatever I've tried I always get "Path not found" error.
This is the real path to my files:
D:\InetPub\vhosts\lamardesigngroup.com\httpdocs\
The file that I am trying to run is:
D:\InetPub\vhosts\lamardesigngroup.com\httpdocs\ifp\files.asp
and I want to read this file:
D:\InetPub\vhosts\lamardesigngroup.com\httpdocs\ifp\css\style.css
Here is the code:
Dim objFSO, strTextFile, strData, strLine, arrLines
CONST ForReading = 1
'name of the text file
strTextFile = "//css/style.css"
'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll
'Split the text file into lines
arrLines = Split(strData,vbCrLf)
'Step through the lines
For Each strLine in arrLines
response.write(strLine & "<br>")
Next
'Cleanup
Set objFSO = Nothing
and I get "12|800a004c|Path_not_found 80"
I've also tried
strTextFile = "D:\InetPub\vhosts\lamardesigngroup.com\httpdocs\ifp\css\style.css"
' and
strTextFile = "\\css\style.css"
strTextFile = "css\style.css"
strTextFile = "css/style.css"
' and many other combinations
I'm obviously lost...
Morning Harley,
Give this a try:
strTextFile = server.MapPath("css/style.css")
It should result in recognizing your specific server location. I ran into this problem trying to get some vbscript file upload code to work. It should start from the folder your page is working in and go from there.

Dynamic ID name in ASP.NET VB.NET

I have about 20 asp:labels in my ASP page, all with ID="lbl#", where # ranges from 0 to 22. I want to dynamically change what they say. While I could write
lbl1.Text = "Text goes here"
for all 23 of them, I'd like to know if there is a way to loop through all of them and change their text.
I thought of creating an array with all my labels, and then just do a For Each loop, but I also have to check if the element exists with IsNothing before I change its text, so I got stuck there.
If anyone can help me, I'd really really appreciate it!
Thank you so so much for your help!!
You can dynamically look up controls on the page by using the System.Web.UI.Page.FindControl() method in your Page_Load method:
Dim startIndex As Integer = 0
Dim stopIndex As Integer = 22
For index = startIndex To stopIndex
Dim myLabel As Label = TryCast(FindControl("lbl" + index), Label)
If myLabel Is Nothing Then
Continue For
End If
myLabel.Text = "Text goes here"
Next
Something like this may work, but you would likely need to tweak it (its from memory, so its not exactly 100% syntactically correct)
For Each _ctl as Control In Me.Controls()
If (TypeOf(_ctl) Is Label) = False Then
Continue For
End If
'add additional filter conditions'
DirectCast(_ctl, Label).Text = "Text Goes Here"
Next
You can also do something similar on the client side using jQuery selectors.

Resources