473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Help with trimming carriage returns from strings obtained via dlg_open

I'm a rookie with vb.net and I'm trying to modify source code that was given to me...

in short the program I have is a file copy application... it reads a file name and path from a given txt file and it does a dlg_open on that file to get the string necessary... however if that file contains a carriage return at the end, I get an error saying there are illegal characters in the path... I would like it to ignore any CRs obviously.

The code I currently have looks like this:
Expand|Select|Wrap|Line Numbers
  1. #Region " Local variables"
  2.  
  3.     Private dbl_PctDone As Double = 0
  4.     Private str_SourceFile As String = ""
  5.     Private str_DestFile As String = ""
  6.     Private str_ShortFileName As String = ""
  7.     Private int_CurrentBytes As Long = 0
  8.     Private int_TotalBytes As Long = 0
  9.  
  10. #End Region
  11.  
  12. #Region " Public Properties"
  13.  
  14.  
  15.     Public Property PercentDone() As Double
  16.         Get
  17.             Return dbl_PctDone
  18.         End Get
  19.         Set(ByVal value As Double)
  20.             dbl_PctDone = value
  21.         End Set
  22.     End Property
  23.  
  24.     Public Property SourceFile() As String
  25.         Get
  26.             Return str_SourceFile
  27.         End Get
  28.         Set(ByVal value As String)
  29.             str_SourceFile = value
  30.         End Set
  31.     End Property
  32.  
  33.     Public Property DestinationFile() As String
  34.         Get
  35.             Return str_DestFile
  36.         End Get
  37.         Set(ByVal value As String)
  38.             str_DestFile = value
  39.         End Set
  40.     End Property
  41.  
  42.     Public Property CurrentBytes() As Long
  43.         Get
  44.             Return int_CurrentBytes
  45.         End Get
  46.         Set(ByVal value As Long)
  47.             int_CurrentBytes = value
  48.         End Set
  49.     End Property
  50.  
  51.     Public Property TotalBytes() As Long
  52.         Get
  53.             Return int_TotalBytes
  54.         End Get
  55.         Set(ByVal value As Long)
  56.             int_TotalBytes = value
  57.         End Set
  58.     End Property
  59.  
  60.     Public ReadOnly Property ShortFileName() As String
  61.         Get
  62.             Return str_ShortFileName
  63.         End Get
  64.     End Property
  65.  
  66. #End Region
  67.  
  68. #Region " Private Methods"
  69.  
  70.     Private Function CopyProgress(ByVal totalFileSize As Int64, ByVal totalBytesTransferred As Int64, ByVal streamSize As Int64, ByVal streamBytesTransferred As Int64, ByVal dwStreamNumber As Int32, ByVal dwCallbackReason As Int32, ByVal hSourceFile As Int32, ByVal hDestinationFile As Int32, ByVal lpData As Int32) As Int32
  71.         Try
  72.             '*** Update the properties and the percentage
  73.             int_CurrentBytes = totalBytesTransferred
  74.             int_TotalBytes = totalFileSize
  75.             dbl_PctDone = Convert.ToInt32((totalBytesTransferred / totalFileSize) * 100)
  76.         Catch
  77.             ThrowError(Err, System.Reflection.MethodBase.GetCurrentMethod.Name)
  78.         End Try
  79.     End Function
  80.  
  81. #End Region
  82.  
  83. #Region " Public Methods"
  84.  
  85.  
  86.     Public Sub New(ByVal SourceFile As String, ByVal DestinationFile As String)
  87.         str_SourceFile = SourceFile
  88.         str_DestFile = DestinationFile
  89.     End Sub
  90.  
  91.     Public Sub StartCopying()
  92.  
  93.         Dim cpr As CopyProgressRoutine
  94.  
  95.         Try
  96.  
  97.             '*** Set the event handler for the copy progress
  98.             cpr = New CopyProgressRoutine(AddressOf CopyProgress)
  99.  
  100.             '*** Make sure the file exists
  101.             If File.Exists(str_SourceFile) Then
  102.  
  103.                 '*** Get the file info
  104.                 Dim file_Info As New FileInfo(str_SourceFile)
  105.                 str_ShortFileName = file_Info.Name
  106.  
  107.                 '*** Start copying the file
  108.                 CopyFileEx(str_SourceFile, str_DestFile, cpr, 0, 0, 0)
  109.  
  110.             End If
  111.  
  112.         Catch
  113.             ThrowError(Err, System.Reflection.MethodBase.GetCurrentMethod.Name)
  114.         End Try
  115.  
  116.     End Sub
  117.  
  118. #End Region
  119.  

I know that the SourceFile string and DestFile string need to ignore any and all CRs but I am not sure how to do it... I have tried adding a "str_SourceFile = trim.str_SourceFile to the local variables with no luck.

Thanks in advance for any help.
Oct 9 '08 #1
1 1029
Plater
7,872 Expert 4TB
Whatever string you have, do a .Trim() on it.
That code looks very vb6 and not very .NET though
Oct 9 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Lauren Quantrell | last post by:
I have created the following trigger: CREATE TRIGGER ON OutputTable FOR INSERT AS Declare @filename nvarchar(35) Declare @filecontents nvarchar(2000) Declare @strcmdshell varchar(150)
4
by: Les Juby | last post by:
Can someone please help with a suggestion as to how I can keep the formatting (carriage returns) that the user enters into a memo field and then display that later. I figured I might be able to...
2
by: eagleofjade | last post by:
I am trying to import data from a Word document into an Access table with VBA. The Word document is a form which has various fields. One of the fields is a field for notes. In some cases, this...
5
by: Chad Paquette | last post by:
Hi, We have a legacy cgi app that's written in C. We are encountering an error when we try to retrieve a cgi environment variable. The variable we are getting contains a Base64 encoded...
6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
2
by: Matt Mercer | last post by:
Hi all, I am having a frustration problem, and I have read about 25 newsgroup postings that do not have a satisfying answer :) The problem appears to be common where carriage returns are lost...
8
by: TheDude5B | last post by:
Hi, I have some data which is stored in my MySQL database as TEXT. when the data is entered in, it has some carriage returns in it, and this can be seen when querying the data using MySQL Query...
2
by: sean | last post by:
Can anyone tell me how to add a carriage return to a string using vb.net? I need to add two strings with a carrage return together and post to an email message body ie: This gives me an...
19
by: ash | last post by:
hi friends, i have some questions whch is in my last year question papers.i need some help to get logic of these questions. 1) write a C function, that takes two strings as arguments and...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.