|
Thank you. I going to see if I can adapt it for my use.
Quecumber256
|
|
|
|
|
I need to download from an FTP site. There are an unknown # of files. I have code to download a single file at a time but have problems getting the file names. The error message is invalid username/password when I use Path.GetFiles(strPathName).
|
|
|
|
|
Let's see the code you're using to try and get the files. The Path class doesn't have a GetFiles method. The Path class doesn't work with FTP sites, so I don't know why you're using it.
|
|
|
|
|
As you can see, I tried a couple of different methods. I also tried some of these inside the FTP class after the logon. I also tried to FTP.Logon. The upload works, but I know the filename that I have createed for the upload.
'FTP.DownloadAllFiles(strSource, strDest)
'For Each fname In My.Computer.FileSystem.GetFiles(strSource)
' strDest = strDest & fname
' strSource = strSource & fname
'FTP.DownloadFile(strSource, strDest)
'If FTP.flag_bool Then
' ctr = ctr + 1
'End If
' Next
'Dim f1 As New FileIOPermission(FileIOPermissionAccess.Read, strSource)
'Dim f2 As New FileIOPermission(FileIOPermissionAccess.PathDiscovery, strSource)
'fname = Dir(strSource)
'My.Computer.FileSystem.CopyFile(strSource, strDest)
'Dim filenames() As String = Directory.GetFiles(strSource)
'Do While fname.Trim > " "
'For i = 0 To filenames.Length - 1
' fname = Path.GetFileName(filenames(i))
' strDest = strDest & fname
' strSource = strSource & fname
' FTP.DownloadFile(strSource, strDest)
' If FTP.flag_bool Then
' ctr = ctr + 1
' End If
' 'fname = My.Computer.FileSystem.GetName(strSource)
' 'Loop
'Next
|
|
|
|
|
Are you actually using this code? Because every line is commented out...
This code won't work at all. Your combining filesystem objects and methods with FTP ideas. There two just don't work together at all.
What is "FTP" as defined in your code? There is no definition nor a Dim statement showing what kind of object it is.
You're using .NET Framework 2.0, so there is an FtpClient class built in, which your code isn't using at all as far as I can tell. FtpClient docs[^]
|
|
|
|
|
FTP is the FTP class that I built for .NET 2003 (from an MSDN sample). The upload works. But the download needs a file name. The ftp site is in our network so it can be accessed as an ftp site or as a file (windows explorer or internet explorer). The code is commented out when I copied it because there are about 3 different (though similar) methods that I copied from samples I found in help or on-line.
|
|
|
|
|
I need help with a bug in a program for a PPC device.
The following line of code results in a “FormatExceptionWasUnhandled” error:
If Mid(DecimalPart, 1, 1) <> "1" Then
DecimalPart is a String variable containing the text “.5”.
When I set up a Watch for Mid(DecimalPart, 1, 1) the result is “.” and for Mid(DecimalPart, 1, 1) <> "1" the result is “True”.
I am sure I am missing something incredably simple, I just can not figure out what.
Thanks,
David Wilkes
|
|
|
|
|
The FormatException gets thrown when the formatting for an argument does match the parameter specifications of the method. There's nothing in this code that would throw that exception because the Mid function doesn't expect the string parameter to be in any format.
Besides, why are you using the old VB6 Mid function? You should be using the methods in the String class, like
If DecimalPart.StartsWith("1") Then
|
|
|
|
|
Thanks for the reply!
This is what I get for being lazy. Using MID? I was using a function someone else wrote (no sense reinventing the wheel right?). I figured out last night that it was part of the line just prior to this that was actually throwing the error (not used to this environment yet). When I stripped it down I figured out it was trying to do Val(".")
So I just did what I should have done from the start and write my own function.
David Wilkes
|
|
|
|
|
My co-worked and I have a debate going, he's trying to tell me that you cannot check to see if an event has been raised in VB.Net, is this true? If not does anyone have some examples I can look at?
"Okay, I give up: which is NOT a real programming language????"
Michael Bergman
"Well yes, it is an Integer, but it's a metrosexual Integer. For all we know, under all that hair gel it could be a Boolean."
Tom Welch
"Let's face it, the average computer user has the brain of a Spider Monkey."
Bill Gates
|
|
|
|
|
Unless you put code in your event handler to mark when it has been fired, I'm not aware of a way to tell if it was previously fired.
topcoderjax - Remember, Google is your friend.
|
|
|
|
|
Yes and no, and this is not just a limitation of VB.NET. It's any lanugage that uses Windows Forms and handles events.
There is no log that says which events have fired when. There are only two ways to tell an event fired. The first is in the event handler (obviously!).
The second is to override WndProc and watch for the window message that will cause the event to fire inside your code.
|
|
|
|
|
Hello, I have a tiny tiny problem with this code.
It's a regex that grabs this kinda text
Text: Posted May 17,2005 08:30 AM
Code: ([Pp][Oo][Ss][Tt][Ee][Dd]\s[A-Za-z]*\s\d,\s[0-3000]\s[\d]:[\d]\s[A][M])
I can't see why it's not working, but I'm missing something in the code. Please help.
Thanks a lot!!!
Anthony.
Belief is a beautiful armour.
Knowledge is the sword.
|
|
|
|
|
regexlib.com[^] has a regex tester and cheat sheets, and is where I go with problems like this.
topcoderjax - Remember, Google is your friend.
|
|
|
|
|
You only match one digit for the date, but you need to match one or two.
The set [0-3000] will not be recognised as a range of numbers, it will be a set of the digits 0-3, 0, 0 and 0.
You only match one digit for hours, but you need two.
You only match one digit for minutes, but you need two.
You only match AM times, but PM times will fail.
Sets containing one one character is superflous. [A] is the same as plain A.
---
single minded; short sighted; long gone;
|
|
|
|
|
ya he is correct in addition you r calculating single space onlyso \s* has to be gven
with regards
Balagurunathan.B
|
|
|
|
|
Hello Guffa
Thanks for your help back then.
I am trying to index with his regex but it does not pick text that's stored in a HTML tag.
Example: Johnson <b>Peter</b> Smith for the keywords "John" and "Peter" returns only "John"
\\b("+keyword+"'?s?)\\b|(^"+keyword+"'?s?)\\b|\\b("+keyword+"'?s?$)
So how do I go about making the regex pick-up Peter, which is in a HTML tag. Thanks
Anthony, Canada.
|
|
|
|
|
On the contrary. It finds "Peter", but not "John".
Do you have an example that actually does demonstrate what you are trying to do?
---
single minded; short sighted; long gone;
|
|
|
|
|
Thanks!
For example, i want to search for James, but because the James in my text is embedded in a BOLD tag, it does not return a result.
So if I have <b>James</b> is there a way I can "remove" the HTML tag, and have only "James" for my regex to pick-up?
|
|
|
|
|
ant1xxx wrote: For example, i want to search for James, but because the James in my text is embedded in a BOLD tag, it does not return a result.
Yes, it does.
ant1xxx wrote: So if I have James is there a way I can "remove" the HTML tag, and have only "James" for my regex to pick-up?
You don't have to. It's matching only "James", not the html tags.
---
single minded; short sighted; long gone;
|
|
|
|
|
We have a main method which calls a sub method 50 times and in turn the sub method calls one more method 5 times. From the first the datatable is passed by byval and one or two value types are passed by byval. The method doesn't make any changes to the variables
1. Byval or Byref - which will be faster-multiple times and multilevels calling?
2. Will that be a good idea to have multiple levels of methods to be called multiple times. We have lot of local variables. Will the garbage collectors's headache be more in creating and destroying the objects?
Thanks
|
|
|
|
|
ByVal means that the method will create its own copy of the variable, and any changes will not be passed back to the method that called it.
ByRef means the method will use the variable you passed in and update it.
Some objects (I believe DataTables are one example of this) are always passed ByRef even if you specify ByVal because they are so complex.
It sounds like what you want to do is use ByRef. Running a method that updates a couple variables 50 * 5 = 250 times shouldn't be too much for an average computer today. If you were updating several hundreds of thousands than you may worry about it more.
Hope this helps.
|
|
|
|
|
thank you i never fully got that. i even goggled it before and never saw good answer.
|
|
|
|
|
First: abandon any notion of ByRef vs. ByVal from VB6.
Second: there is a difference with ByVal and ByRef wrt object instances.
What ByRef and ByVal indicate are which memory address to copy to the method's stack.
Lets look at the following code:
<br />
Private Sub DataTableCreator()<br />
Dim dt As New DataTable()<br />
ByValReceiver(dt)<br />
ByRefReceiver(dt)<br />
End Sub<br />
<br />
Private Sub ByValReceiver(ByVal valdt As DataTable)<br />
valdt = Nothing<br />
End Sub<br />
<br />
Private Sub ByRefReceiver(ByRef refdt As DataTable)<br />
refdt = Nothing<br />
End Sub<br />
ByValReceiver will take in the memory address of the object on the heap and assign it to a local variable "valdt" on it's stack.
ByRefReceiver will take in the memory address of the variable "dt" from DataTableCreator's stack and assign that to refdt.
So what does this do for you? Two things.
1) If you run the code you'll see ByValReceiver won't effect dt in DataTableCreator, but ByRefReceiver does.
When you assign Nothing you're in effect clearing the memory reference from the variable.
refdt is really a reference to a reference (or pointer to a pointer in in the old days **p), setting it to nothing clears the real reference to the DataTable, which is dt in DataTableCreator.
2) I can't prove this since .Net can be a black box, but I fully expect that nesting calls with ByRef will cause multiple dereferencing steps (going to the memory address in the variable) to get back to the heap.
If you used refdt, first it must dereference to dt, then dereference dt to get to the actual DataTable instance on the heap.
This would actually marginally slow things down.
ByRef is required for when you want value types, which are held on the local stack (i.e. integer, long, structures etc) to be modified by the called method.
Think out parameters.
Objects should be handed down ByVal, unless you really want to use the trick above!
Hope this clears things up at least a little?
Coding since '85 - ATARI BASIC, Forth, C, Java, C#, VB.Net ..
|
|
|
|
|
K.P.Kannan wrote: The method doesn't make any changes to the variables
Then you should not pass anything by reference.
K.P.Kannan wrote: Byval or Byref - which will be faster-multiple times and multilevels calling?
ByVal will be faster, and that is the default way of passing parameters.
When you pass an object by value, you are passing a copy of the reference to the object, and it will be handled just as afficiently as a local variable in the method.
When you pass an object by reference, you are passing a reference to the reference to the object. Whenever you use it in the method, it has to be dereferenced, which adds a small overhead each time.
The ByVal and ByRef keywords are mostly kept for compatibility reasons. In object oriented programming they are very rarely used at all.
K.P.Kannan wrote: Will that be a good idea to have multiple levels of methods to be called multiple times.
Unless you are making a huge number of calls to the methods, it doesn't matter much.
K.P.Kannan wrote: We have lot of local variables. Will the garbage collectors's headache be more in creating and destroying the objects?
Local variables are allocated on the stack, and don't have to be garbage collected at all. If you have local variables that are references, and create objects for those references, the objects will of course be garbage collected.
Creating and freeing objects are considerably cheaper in .NET than it was in VB6. As long as you make use of the objects, you should not normally be concerned with the cost of creating and freeing them. If you create and free the same kind of objects a lot, you might consider a way of reusing them, but on the other hand many objects are not even built to be reused in that way.
---
single minded; short sighted; long gone;
|
|
|
|